Android Open Source - Android-Tile-Based-Game Game Image






From Project

Back to project page Android-Tile-Based-Game.

License

The source code is released under:

MIT License

If you think the Android project Android-Tile-Based-Game 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 org.ruscoe.example.tilegame;
/*from  ww  w  .  j a v a2 s  .  c o  m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * The GameImage class represents an image used in the game.
 * 
 * Each instance contains a Bitmap image, a width / height
 * and an on-screen position.
 * 
 * @author Dan Ruscoe (ruscoe.org)
 * @version 1.0
 */
public class GameImage 
{
  protected Bitmap mImg = null;
  protected int mX = 0;
  protected int mY = 0;
  protected int mWidth = 0;
  protected int mHeight = 0;

  public GameImage(Context context)
  {
  }
  
  public GameImage(Context context, int drawable)
  {
    this.setDrawable(context, drawable);
  }

  public void setDrawable(Context context, int drawable)
  {
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;
    this.mImg = BitmapFactory.decodeResource(context.getResources(), drawable);

    mWidth = this.mImg.getWidth();
    mHeight = this.mImg.getHeight();
  }
  
  public void setBitmap(Bitmap bitmap)
  {
    if (bitmap != null)
    {
      this.mImg = bitmap;
      this.mWidth = bitmap.getWidth();
      this.mHeight = bitmap.getHeight();
    }
  }
  
  public Bitmap getBitmap()
  {
    return this.mImg;
  }

  public int getWidth()
  {
    return this.mWidth;
  }

  public int getHeight()
  {
    return this.mHeight;
  }
  
  void setX(int x)
  {
        this.mX = x;
    }

  public int getX()
  {
    return this.mX;
  }

  public void setY(int y)
  {
        this.mY = y;
  }

  public int getY()
  {
    return this.mY;
  }

  public void setCenterX(int centerX)
  {
    this.mX = (centerX - (this.getWidth() / 2));
  }
  
  public int getCenterX()
  {
    return (mX + (this.getWidth() / 2));
  }
  
  public void setCenterY(int centerY)
  {
    this.mY = (centerY - (this.getHeight() / 2));
  }
  
  public int getCenterY()
  {
    return (mY + (this.getHeight() / 2));
  }
}




Java Source Code List

org.ruscoe.example.tilegame.About.java
org.ruscoe.example.tilegame.GameImage.java
org.ruscoe.example.tilegame.GameTile.java
org.ruscoe.example.tilegame.GameUi.java
org.ruscoe.example.tilegame.GameUnit.java
org.ruscoe.example.tilegame.GameView.java
org.ruscoe.example.tilegame.Play.java
org.ruscoe.example.tilegame.PlayerUnit.java
org.ruscoe.example.tilegame.data.GameDAO.java
org.ruscoe.example.tilegame.data.GameLevelTileData.java
org.ruscoe.example.tilegame.data.GameTileData.java