If you think the Android project ProjectSierra 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
/*
Copyright 2014 Seth Traverse/*www.java2s.com*/
This file is part of Project Sierra.
Project Sierra is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Project Sierra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Project Sierra. If not, see <http://www.gnu.org/licenses/>.
*/package ca.viaware.game.entity;
import ca.viaware.game.rendering.Renderable;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
publicclass Entity implements Renderable {
privatefloat x;
privatefloat y;
privatefloat width;
privatefloat height;
private TextureRegion texture;
privatefloat originX;
privatefloat originY;
privatefloat scaleX;
privatefloat scaleY;
privatefloat rotation;
privateboolean removeFlag;
public Entity(float x, float y, float width, float height, TextureRegion texture) {
setX(x);
setY(y);
setWidth(width);
setHeight(height);
setTexture(texture);
setScaleX(1);
setScaleY(1);
}
publicvoid update(float delta) {}
@Override
publicvoid render(SpriteBatch batch) {
batch.draw(getTexture(),getX(),getY(),getOriginX(),getOriginY(),getWidth(),getHeight(),getScaleX(),getScaleY(),getRotation());
}
publicfloat getX() {
return x;
}
publicvoid setX(float x) {
this.x = x;
}
publicfloat getY() {
return y;
}
publicvoid setY(float y) {
this.y = y;
}
publicfloat getWidth() {
return width;
}
publicvoid setWidth(float width) {
this.width = width;
}
publicfloat getHeight() {
return height;
}
publicvoid setHeight(float height) {
this.height = height;
}
publicfloat getOriginX() {
return originX;
}
publicvoid setOriginX(float originX) {
this.originX = originX;
}
publicfloat getOriginY() {
return originY;
}
publicvoid setOriginY(float originY) {
this.originY = originY;
}
publicfloat getScaleX() {
return scaleX;
}
publicvoid setScaleX(float scaleX) {
this.scaleX = scaleX;
}
publicfloat getScaleY() {
return scaleY;
}
publicvoid setScaleY(float scaleY) {
this.scaleY = scaleY;
}
publicfloat getRotation() {
return rotation;
}
publicvoid setRotation(float rotation) {
this.rotation = rotation;
}
public TextureRegion getTexture() {
return texture;
}
publicvoid setTexture(TextureRegion texture) {
this.texture = texture;
}
publicfloat getCenteredX() {
return (getX() + (getWidth() / 2)) * getScaleX();
}
publicfloat getCenteredY() {
return (getY() + (getHeight() / 2)) * getScaleY();
}
public Vector2 getLocationVector() {
returnnew Vector2(getX(), getY());
}
public Rectangle getRectangle() {
returnnew Rectangle(getX(), getY(), getWidth(), getHeight());
}
publicboolean collides(Entity other) {
return other.getRectangle().overlaps(getRectangle());
}
publicfloat calcDirection(Entity other) {
float horz = other.getX() - getX();
float vert = other.getY() - getY();
return (float) Math.atan(horz / vert);
}
publicvoid setRemoveFlag(boolean remove) {
this.removeFlag = remove;
}
publicboolean getRemoveFlag() {
return removeFlag;
}
}