Android Open Source - Apocalypse-Defense Game Object






From Project

Back to project page Apocalypse-Defense.

License

The source code is released under:

MIT License

If you think the Android project Apocalypse-Defense 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.apocalypsedefense.app.gameplay_visuals;
//from  ww  w  .j av a2s.c o  m
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;

import com.apocalypsedefense.app.NewGameSettingsActivity;
import com.apocalypsedefense.core.Person;
import com.apocalypsedefense.core.Zombie;

public class GameObject {
  private static final String TAG = "GameObject"; // for logging
  public static Bitmap zombieBitmap;
  public static Bitmap towerBitmap;
  private Bitmap graphic;
  private Person inner;
  private final GameFacade game;
  public static Paint attackedCirclePaint;
  

  /**
   * Wrap a Person for easy access to relevant visual data.
   * NOTE: You will need to set the static Bitmaps for these objects to work.
   * @param person zombie/survivor/etc which this object is wrapping
   * @param game
   */
  public GameObject(Person person, GameFacade game){
    this.inner = person;
    this.game = game;
    setGraphic(inner);
  }

    private void setGraphic(Person inner) {
        // Was going to use the Visitor pattern, but never mind
        if (inner instanceof Zombie){
            graphic = zombieBitmap;
        }
        else {//if (inner instanceof Survivor){
            graphic = towerBitmap;
        }
    }

    public void draw(Canvas canvas) {
    // Translate to screen coords (divide, in this case), centered in the image
    float xStart = inner.position.x / game.xScale;
    float x = xStart - graphic.getWidth()/2;
    float yStart = inner.position.y / game.yScale;
    float y = yStart - graphic.getHeight()/2;
    
    canvas.drawBitmap(graphic, x, y, null);
    Log.v(TAG, String.format("drew gameObject centered at %.0f,%.0f", x, y));
    
    if (inner.isBeingAttacked()) {
      Log.d(TAG, "this game object isBeingAttacked");
      float radius = inner.hp / 5.0f;
      canvas.drawCircle(xStart, yStart, radius, attackedCirclePaint);
    }
  }

  public int getHealth() {
    return inner.hp;
  }
}




Java Source Code List

com.apocalypsedefense.app.AchievementsActivity.java
com.apocalypsedefense.app.ApocalypseDefenseActivity.java
com.apocalypsedefense.app.EndOfGameDialog.java
com.apocalypsedefense.app.ExitConfirmationDialog.java
com.apocalypsedefense.app.InGameActivity.java
com.apocalypsedefense.app.InstructionsDialog.java
com.apocalypsedefense.app.NewGameSettingsActivity.java
com.apocalypsedefense.app.OverwriteExistingGameDialog.java
com.apocalypsedefense.app.gameplay_visuals.AndroidLogAdapter.java
com.apocalypsedefense.app.gameplay_visuals.GameFacade.java
com.apocalypsedefense.app.gameplay_visuals.GameObject.java
com.apocalypsedefense.app.gameplay_visuals.GameSurfaceView.java
com.apocalypsedefense.app.gameplay_visuals.GameThread.java
com.apocalypsedefense.app.gameplay_visuals.OnGameEndListener.java
com.apocalypsedefense.app.gameplay_visuals.OnStatsChangedListener.java
com.apocalypsedefense.app.gameplay_visuals.Sprite.java
com.apocalypsedefense.core.ActorType.java
com.apocalypsedefense.core.Armor.java
com.apocalypsedefense.core.GameData.java
com.apocalypsedefense.core.GameState.java
com.apocalypsedefense.core.Game.java
com.apocalypsedefense.core.Gun.java
com.apocalypsedefense.core.LogAdapter.java
com.apocalypsedefense.core.MapElement.java
com.apocalypsedefense.core.Map.java
com.apocalypsedefense.core.Movement.java
com.apocalypsedefense.core.Person.java
com.apocalypsedefense.core.Point.java
com.apocalypsedefense.core.PrintLogAdapter.java
com.apocalypsedefense.core.Shared.java
com.apocalypsedefense.core.SurvivorManager.java
com.apocalypsedefense.core.Survivor.java
com.apocalypsedefense.core.Weapon.java
com.apocalypsedefense.core.ZombieManager.java
com.apocalypsedefense.core.Zombie.java
com.apocalypsedefense.core.testDriver.java