Created
January 28, 2017 13:18
-
-
Save cdwijayarathna/cf4c6fe83182e1db37dbe0297f85eaf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.edu.unsw.mygame.entity; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.Sprite; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.math.Vector2; | |
/** | |
* Created by Asus PC on 8/19/2016. | |
*/ | |
public abstract class Entity { | |
protected Texture texture; | |
private Sprite sprite; | |
private boolean touched; | |
protected Vector2 pos, dir; | |
public Entity(Texture texture, Vector2 pos, Vector2 dir) { | |
this.texture = texture; | |
this.pos = pos; | |
this.dir = dir; | |
sprite = new Sprite(texture); | |
sprite.setSize(texture.getWidth(), texture.getHeight()); | |
} | |
public abstract void update(); | |
public void render (SpriteBatch sb) { | |
update(); | |
sb.draw(sprite, pos.x, pos.y); | |
} | |
public Vector2 getPos() { | |
return pos; | |
} | |
public boolean touchDown (float screenX, float screenY) { | |
if (screenX >= pos.x && screenX <= pos.x + texture.getWidth() && screenY <= pos.y + texture.getHeight() && screenY | |
>= pos.y) | |
touched = true; | |
return true; | |
} | |
public boolean touchUp (float screenX, float screenY) { | |
if (touched) { | |
doTouchLogic(); | |
touched = false; | |
} | |
return true; | |
} | |
public abstract boolean doTouchLogic (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment