Android Open Source - game-api-android Vissenkom






From Project

Back to project page game-api-android.

License

The source code is released under:

MIT License

If you think the Android project game-api-android 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

package com.android.vissenspel;
//from  w w w. ja va 2s. c  o m
import android.gameengine.icadroids.dashboard.DashboardTextView;
import android.gameengine.icadroids.engine.GameEngine;
import android.gameengine.icadroids.input.MotionSensor;
import android.gameengine.icadroids.input.OnScreenButtons;
import android.gameengine.icadroids.input.TouchInput;
import android.gameengine.icadroids.tiles.GameTiles;
import android.graphics.Color;
import android.util.Log;
import android.util.TypedValue;

/**
 * Main class of the game 'Vissenkom'.
 * 
 * @author Paul Bergervoet
 */
public class Vissenkom extends GameEngine {

  /**
   * MoveableGmeObject vis, player in the game
   */
  private Vis vis;
  
  /**
   * Dashboard for displaying the score
   */
  private DashboardTextView scoreDisplay;
  
  /**
   * Initialize the game, create objects and level
   * 
   * @see android.gameengine.icadroids.engine.GameEngine#initialize()
   */
  @Override
  protected void initialize() {

    // Set up control mechanisms to use
    TouchInput.use = false;
    MotionSensor.use = false;
    OnScreenButtons.use = true;

    createTileEnvironment();

    vis = new Vis(this);
    addGameObject(vis, 120, 240);

    Monster engerd = new Monster(vis);
    addGameObject(engerd, 480, 240);

    @SuppressWarnings("unused")
    StrawberryControler sc = new StrawberryControler(this);
    
    // Example of how to use the Viewport, properties and zooming
    /*
      // Switch it on
      Viewport.useViewport = true;
      // Zoom in, 2x
      setZoomFactor(2f);
      // Make viewport follow the Vis
      setPlayer(vis);
      // Vis will be center screen
      setPlayerPositionOnScreen(Viewport.PLAYER_CENTER, Viewport.PLAYER_CENTER);
      // Determines how quickly viewport moves (see API for details)
      setPlayerPositionTolerance(0.8, 0.5);
     */
    
    // Example of how to add a Dashboard to a game
    scoreDisplay = new DashboardTextView(this);
    scoreDisplay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    scoreDisplay.setTextColor(Color.BLACK);
    addToDashboard(scoreDisplay);
    
    // Example of how to add an image to the dashboard.
    /*
      DashboardImageView imageDisplay = new DashboardImageView(this, "bg");
      addToDashboard(imageDisplay);
    */
    
    createDashboard();
  }
  
  
  private void createDashboard(){
    
    //this.scoreDisplay.setWidgetWidth(20);
    this.scoreDisplay.setWidgetHeight(60);
    this.scoreDisplay.setWidgetBackgroundColor(Color.WHITE);
    this.scoreDisplay.setWidgetX(10);
    this.scoreDisplay.setWidgetY(10);
    // If you want to modify the layout of a dashboard widget,
    // you need to so so using its run method.
    this.scoreDisplay.run(new Runnable(){
      public void run() {
        scoreDisplay.setPadding(10, 10, 10, 10);
      }
    });
  }

  /**
   * Create background with tiles
   */
  private void createTileEnvironment() {
    String[] tileImagesNames = { "vissentile1", "vissentile2" };
    // layout: better not let the Eclipse formatter get at this...
    int[][] tilemap = {
        { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  1,  1,  1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1,  0,  0,  0,  1,  0,  0,  0,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1, -1, -1, -1, -1 },
        { -1, -1, -1, -1, -1, -1, -1, -1,  0,  1,  0,  1,  0,  1,  0,  1,  0,  1,  0,  1,  0,  1, -1, -1, -1, -1, -1, -1, -1, -1 },
        { -1, -1, -1, -1, -1, -1, -1, -1,  1,  0,  1,  0,  1,  0,  1,  0,  1,  0,  1,  0,  1,  0, -1, -1, -1, -1, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1,  1,  1,  1,  0,  1,  1,  1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,  1,  1,  1,  1,  1,  1,  1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1,  0, -1, -1, -1, -1, -1, -1, -1, -1,  0,  0,  0,  0, -1, -1, -1, -1, -1, -1, -1, -1,  0, -1, -1, -1, -1 },
        { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
    };
    GameTiles myTiles = new GameTiles(tileImagesNames, tilemap, 20);
    setTileMap(myTiles);
    Log.d("Vissenkom", "GameTiles created");

  }

  /**
   * Update the game. At this moment, we only need to update the Dashboard.
   * Note: the Dashboard settings will be adjusted!!!
   * 
   * @see android.gameengine.icadroids.engine.GameEngine#update()
   */
  @Override
  public void update() {
    super.update();
    this.scoreDisplay.setTextString(
        "Score: " + String.valueOf(this.vis.getScore()));
  }
}




Java Source Code List

android.gameengine.icadroids.alarms.Alarm.java
android.gameengine.icadroids.alarms.IAlarm.java
android.gameengine.icadroids.dashboard.DashboardImageView.java
android.gameengine.icadroids.dashboard.DashboardTextView.java
android.gameengine.icadroids.engine.GameEngine.java
android.gameengine.icadroids.engine.GameFPSCounter.java
android.gameengine.icadroids.engine.GameThread.java
android.gameengine.icadroids.engine.GameView.java
android.gameengine.icadroids.engine.Viewport.java
android.gameengine.icadroids.forms.GameForm.java
android.gameengine.icadroids.forms.IFormInput.java
android.gameengine.icadroids.forms.ViewCreator.java
android.gameengine.icadroids.forms.ViewRemover.java
android.gameengine.icadroids.input.MotionSensor.java
android.gameengine.icadroids.input.OnScreenButton.java
android.gameengine.icadroids.input.OnScreenButtons.java
android.gameengine.icadroids.input.TouchInput.java
android.gameengine.icadroids.objects.GameObject.java
android.gameengine.icadroids.objects.MoveableGameObject.java
android.gameengine.icadroids.objects.collisions.CollidingObject.java
android.gameengine.icadroids.objects.collisions.ICollision.java
android.gameengine.icadroids.objects.collisions.TileCollision.java
android.gameengine.icadroids.objects.graphics.AnimatedSprite.java
android.gameengine.icadroids.objects.graphics.Sprite.java
android.gameengine.icadroids.persistence.GamePersistence.java
android.gameengine.icadroids.sound.GameSound.java
android.gameengine.icadroids.sound.MusicPlayer.java
android.gameengine.icadroids.tiles.GameTiles.java
android.gameengine.icadroids.tiles.Tile.java
com.android.vissenspel.Monster.java
com.android.vissenspel.StrawberryControler.java
com.android.vissenspel.Strawberry.java
com.android.vissenspel.Vis.java
com.android.vissenspel.Vissenkom.java
game.MyAndroidGame.java
testGames.AndroidCraft_demo.java
testGames.FormTest.java
testGames.Player.java
testGames.TestGameBas.java
testGames.TestGameLex.java
testGames.TestGameRoel.java
testGames.gameEngineTest.DebugEngine.java
testGames.gameEngineTest.GameEngineTestGame.java
testGames.gameEngineTest.TestGameObject.java
testGames.gameEngineTest.debugObject.java
testGames.gameEngineTest.randomObject.java
testGames.testGameObjectBas.java
testGames.testGame.java