Android Open Source - RockFall-Android Abstract Entity






From Project

Back to project page RockFall-Android.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project RockFall-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 eu.raffprta.rockfall.core.entity;
//from ww  w. j  a va2  s.c  o  m
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;

import java.util.LinkedList;
import java.util.List;

import eu.raffprta.rockfall.core.sprite.*;

/**
 * Class to provide partial implementation of the Entity interface.
 */
public abstract class AbstractEntity implements Entity{

    private Sprite s;
    private FallableType id;
    private String name;
    private int x,y, velX, velY;

    private Rect collisionBox;

    public AbstractEntity(Sprite s, String name, FallableType id, int x, int y, int velX, int velY){
        this.s = s;
        this.name = name;
        this.id = id;
        this.x = x;
        this.y = y;
        this.velX = velX;
        this.velY = velY;
        // Add the collision box
        collisionBox = new Rect(x,y,x+s.getSprite().getWidth(),y+s.getSprite().getHeight());
    }

    public Bitmap getSprite(){
        return this.s.getSprite();
    }

    public FallableType getId(){
        return this.id;
    }

    public String toString(){
        return this.name;
    }

    public int getX(){
        return this.x;
    }
    public int getY(){
        return this.y;
    }
    public int getVelX(){
        return this.velX;
    }
    public int getVelY(){
        return this.velY;
    }

    public void update(int x, int y, int velX, int velY){
        this.x = x + velX;
        this.y = y + velY;
        this.velX = velX;
        this.velY = velY;
        this.collisionBox.set(x,y,x+s.getSprite().getWidth(),y+s.getSprite().getHeight());
    }

    public Rect getCollisionBox(){
        return this.collisionBox;
    }

    public boolean isCollidedWith(Entity e){
        return this.getCollisionBox().intersect(e.getCollisionBox());
    }

}




Java Source Code List

eu.raffprta.rockfall.app.GameCanvas.java
eu.raffprta.rockfall.app.GameIntent.java
eu.raffprta.rockfall.app.GameScreen.java
eu.raffprta.rockfall.app.MainGame.java
eu.raffprta.rockfall.app.MenuCanvas.java
eu.raffprta.rockfall.app.SpriteContainer.java
eu.raffprta.rockfall.app.StopWatch.java
eu.raffprta.rockfall.app.TouchHandler.java
eu.raffprta.rockfall.core.entity.AbstractEntity.java
eu.raffprta.rockfall.core.entity.EntityFactory.java
eu.raffprta.rockfall.core.entity.Entity.java
eu.raffprta.rockfall.core.entity.FallableType.java
eu.raffprta.rockfall.core.entity.Fallable.java
eu.raffprta.rockfall.core.entity.Powerup.java
eu.raffprta.rockfall.core.entity.Protagonist.java
eu.raffprta.rockfall.core.entity.Rock.java
eu.raffprta.rockfall.core.sprite.SpriteFactory.java
eu.raffprta.rockfall.core.sprite.SpriteSheet.java
eu.raffprta.rockfall.core.sprite.Sprite.java