Android Open Source - DeathRally Main Game Panel






From Project

Back to project page DeathRally.

License

The source code is released under:

GNU General Public License

If you think the Android project DeathRally listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2012 Johannes Vestlund <Johannes@westlundarna.se>
 * /*from www.  ja  v  a 2  s  .  c  o  m*/
 * This file is part of DeathRally
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even implied warranty of
 * MERCHANTABILITY or FITTNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package project.gamedev.deathrally.game;

import java.util.ArrayList;

import project.gamedev.deathrally.game.controls.Joystick;
import project.gamedev.deathrally.game.model.GameAction;
import project.gamedev.deathrally.game.model.Player;
import project.gamedev.deathrally.game.view.GameRenderer;
import project.gamedev.deathrally.game.view.VisualEntity;
import project.gamedev.deathrally.game.view.VisualVehicle;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;

//Basic design taken from "http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/"
public class MainGamePanel extends GLSurfaceView  {
  private static final String TAG = MainGamePanel.class.getSimpleName();
  private GameRenderer gameRenderer;
  private GameLoop gameLoop;
  private GameModel gameModel;
  private Joystick joystick;
  private Player user;
  
  public MainGamePanel(Context context) {    
    super(context);
    gameRenderer = GameRenderer.getInstance(context);    
    setRenderer(gameRenderer);
    gameModel = new GameModel();
    gameLoop = new GameLoop(getHolder(), this, gameModel);
    
    getHolder().addCallback(this);    
    setFocusable(true);
    setFocusableInTouchMode(true);
    
    //create Entities
    ArrayList<VisualEntity> visualEntities = new ArrayList<VisualEntity>();
    VisualVehicle vCar = new VisualVehicle(0.0f, 0.0f);
    visualEntities.add(vCar);
    gameRenderer.addDrawObj(visualEntities);
    
    joystick = new Joystick(user, this);
    Log.d(TAG,"MainGamePanel created successfully");
  }
  
  public void addVisualObj(VisualEntity ve){
    gameRenderer.addDrawObj(ve);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent e) {
      // MotionEvent reports input details from the touch screen
      // and other input controls. In this case, you are only
      // interested in events where the touch position changed.
    
      float px = e.getX();
      float py = e.getY();
      
      switch (e.getAction()) {        
        case MotionEvent.ACTION_DOWN:
          if(px > 100 && px < 300){
            joystick.createUI(px,py);
          }
          break;
          case MotionEvent.ACTION_MOVE:
            joystick.catchAction(px, py);
            break;
          case MotionEvent.ACTION_UP:
          joystick.reset();
          break;
      }
      return true;
  }

  public void recieveAction(GameAction action) {
    gameModel.performAction(action);
  }
}




Java Source Code List

project.gamedev.deathrally.MainActivity.java
project.gamedev.deathrally.game.DeathRallyGame.java
project.gamedev.deathrally.game.GameLoop.java
project.gamedev.deathrally.game.GameModel.java
project.gamedev.deathrally.game.MainGamePanel.java
project.gamedev.deathrally.game.constants.LevelName.java
project.gamedev.deathrally.game.controls.Joystick.java
project.gamedev.deathrally.game.graphics.Circle.java
project.gamedev.deathrally.game.graphics.Mesh.java
project.gamedev.deathrally.game.graphics.Rectangle.java
project.gamedev.deathrally.game.graphics.Triangle.java
project.gamedev.deathrally.game.model.CollisionEvent.java
project.gamedev.deathrally.game.model.Direction.java
project.gamedev.deathrally.game.model.Entity.java
project.gamedev.deathrally.game.model.GameAction.java
project.gamedev.deathrally.game.model.Hitbox.java
project.gamedev.deathrally.game.model.Level.java
project.gamedev.deathrally.game.model.MovableEntity.java
project.gamedev.deathrally.game.model.Player.java
project.gamedev.deathrally.game.model.Players.java
project.gamedev.deathrally.game.model.Position.java
project.gamedev.deathrally.game.model.Vector2D.java
project.gamedev.deathrally.game.model.VehicleName.java
project.gamedev.deathrally.game.model.VehicleType.java
project.gamedev.deathrally.game.model.Vehicle.java
project.gamedev.deathrally.game.view.GameRenderer.java
project.gamedev.deathrally.game.view.JoystickView.java
project.gamedev.deathrally.game.view.VisualEntity.java
project.gamedev.deathrally.game.view.VisualVehicle.java