Android Open Source - ProjectSierra Entity






From Project

Back to project page ProjectSierra.

License

The source code is released under:

GNU General Public License

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/*w  w w. j  a  va2s .co m*/

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;

public class Entity implements Renderable {
  private float x;
  private float y;
  private float width;
  private float height;
  
  private TextureRegion texture;
  
  private float originX;
  private float originY;
  
  private float scaleX;
  private float scaleY;
  
  private float rotation;
  
  private boolean 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);
  }

  public void update(float delta) {}
  
  @Override
  public void render(SpriteBatch batch) {
    batch.draw(getTexture(),getX(),getY(),getOriginX(),getOriginY(),getWidth(),getHeight(),getScaleX(),getScaleY(),getRotation());
  }

  public float getX() {
    return x;
  }

  public void setX(float x) {
    this.x = x;
  }

  public float getY() {
    return y;
  }

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

  public float getWidth() {
    return width;
  }

  public void setWidth(float width) {
    this.width = width;
  }

  public float getHeight() {
    return height;
  }

  public void setHeight(float height) {
    this.height = height;
  }

  public float getOriginX() {
    return originX;
  }

  public void setOriginX(float originX) {
    this.originX = originX;
  }

  public float getOriginY() {
    return originY;
  }

  public void setOriginY(float originY) {
    this.originY = originY;
  }

  public float getScaleX() {
    return scaleX;
  }

  public void setScaleX(float scaleX) {
    this.scaleX = scaleX;
  }

  public float getScaleY() {
    return scaleY;
  }

  public void setScaleY(float scaleY) {
    this.scaleY = scaleY;
  }

  public float getRotation() {
    return rotation;
  }

  public void setRotation(float rotation) {
    this.rotation = rotation;
  }

  public TextureRegion getTexture() {
    return texture;
  }

  public void setTexture(TextureRegion texture) {
    this.texture = texture;
  }

  public float getCenteredX() {
    return (getX() + (getWidth() / 2)) * getScaleX();
  }
  
  public float getCenteredY() {
    return (getY() + (getHeight() / 2)) * getScaleY();
  }
  
  public Vector2 getLocationVector() {
    return new Vector2(getX(), getY());
  }
  
  public Rectangle getRectangle() {
    return new Rectangle(getX(), getY(), getWidth(), getHeight());
  }
  
  public boolean collides(Entity other) {
    return other.getRectangle().overlaps(getRectangle());
  }
  
  public float calcDirection(Entity other) {
    float horz = other.getX() - getX();
    float vert = other.getY() - getY();
    
    return (float) Math.atan(horz / vert);
  }
  
  public void setRemoveFlag(boolean remove) {
    this.removeFlag = remove;
  }
  
  public boolean getRemoveFlag() {
    return removeFlag;
  }
}




Java Source Code List

ca.viaware.api.audio.AudioUtils.java
ca.viaware.api.gui.base.VButton.java
ca.viaware.api.gui.base.VFrame.java
ca.viaware.api.gui.base.VLabel.java
ca.viaware.api.gui.base.VListElement.java
ca.viaware.api.gui.base.VList.java
ca.viaware.api.gui.base.VMenuBar.java
ca.viaware.api.gui.base.VMenuItem.java
ca.viaware.api.gui.base.VMenu.java
ca.viaware.api.gui.base.VPanel.java
ca.viaware.api.gui.base.VPopupMenu.java
ca.viaware.api.gui.base.VScrollPane.java
ca.viaware.api.gui.base.VScrollingList.java
ca.viaware.api.gui.base.VTextBox.java
ca.viaware.api.gui.base.event.CloseListener.java
ca.viaware.api.logging.Log.java
ca.viaware.api.net.ConnectionHandlerRunnerThread.java
ca.viaware.api.net.ConnectionHandler.java
ca.viaware.api.net.ConnectionListenerThread.java
ca.viaware.api.parse.CommandParser.java
ca.viaware.api.sql.DatabaseFactory.java
ca.viaware.api.sql.DatabaseResults.java
ca.viaware.api.sql.DatabaseRow.java
ca.viaware.api.sql.Database.java
ca.viaware.api.sql.exceptions.ViaWareSQLException.java
ca.viaware.api.sql.factory.BaseFactory.java
ca.viaware.api.sql.factory.obj.DatabaseObject.java
ca.viaware.api.utils.StringUtils.java
ca.viaware.game.Globals.java
ca.viaware.game.ProjectSierra.java
ca.viaware.game.android.AndroidLauncher.java
ca.viaware.game.assets.TilesetLoader.java
ca.viaware.game.assets.TilesetManager.java
ca.viaware.game.assets.Tileset.java
ca.viaware.game.desktop.DesktopLauncher.java
ca.viaware.game.entities.MapObject.java
ca.viaware.game.entity.Entity.java
ca.viaware.game.entity.MovingEntity.java
ca.viaware.game.entity.events.MoveEvent.java
ca.viaware.game.rendering.Renderable.java
ca.viaware.game.screens.GameScreen.java
ca.viaware.game.world.Map.java
ca.viaware.mapmaker.ConstructionKit.java
ca.viaware.mapmaker.gui.components.SidebarButton.java
ca.viaware.mapmaker.gui.windows.assets.editor.EditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.animation.AnimationEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.clothing.ClothingEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.consumable.ConsumableEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.dialog.DialogEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.effect.EffectEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.intelligence.IntelligenceEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.living.LivingEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.quest.QuestEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.sound.SoundEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.weapon.WeaponEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.editor.worldstatic.StaticEditorWindow.java
ca.viaware.mapmaker.gui.windows.assets.explorer.AssetExplorerWindow.java
ca.viaware.mapmaker.gui.windows.control.ControlWindow.java
ca.viaware.mapmaker.gui.windows.world.editor.DesignPanel.java
ca.viaware.mapmaker.gui.windows.world.editor.SidebarListener.java
ca.viaware.mapmaker.gui.windows.world.editor.SidebarPanel.java
ca.viaware.mapmaker.gui.windows.world.editor.WorldEditorWindow.java
ca.viaware.mapmaker.gui.windows.world.explorer.TopBar.java
ca.viaware.mapmaker.gui.windows.world.explorer.WorldExplorerWindow.java
ca.viaware.mapmaker.gui.windows.world.explorer.WorldListElement.java
ca.viaware.mapmaker.obj.GameManager.java
ca.viaware.mapmaker.obj.asset.AssetManager.java
ca.viaware.mapmaker.obj.asset.AssetType.java
ca.viaware.mapmaker.obj.asset.GameAsset.java
ca.viaware.mapmaker.obj.asset.render.AnimationAsset.java
ca.viaware.mapmaker.obj.asset.render.TextureAsset.java
ca.viaware.mapmaker.obj.asset.sys.DialogAsset.java
ca.viaware.mapmaker.obj.asset.sys.EffectAsset.java
ca.viaware.mapmaker.obj.asset.sys.IntelligenceAsset.java
ca.viaware.mapmaker.obj.asset.sys.QuestAsset.java
ca.viaware.mapmaker.obj.asset.sys.SoundAsset.java
ca.viaware.mapmaker.obj.asset.world.ClothingAsset.java
ca.viaware.mapmaker.obj.asset.world.ConsumableAsset.java
ca.viaware.mapmaker.obj.asset.world.LivingAsset.java
ca.viaware.mapmaker.obj.asset.world.StaticAsset.java
ca.viaware.mapmaker.obj.asset.world.WeaponAsset.java
ca.viaware.mapmaker.obj.world.MapObject.java
ca.viaware.mapmaker.obj.world.WorldManager.java
ca.viaware.mapmaker.obj.world.World.java
ca.viaware.tileset.Globals.java
ca.viaware.tileset.Region.java
ca.viaware.tileset.TilesetCreator.java
ca.viaware.tileset.gui.BasicButton.java
ca.viaware.tileset.gui.LabelAndTextPanel.java
ca.viaware.tileset.gui.RawImagePanel.java
ca.viaware.tileset.gui.RawImageWindow.java
ca.viaware.tileset.gui.SidebarPanel.java
ca.viaware.tileset.gui.listeners.SidebarListener.java
ca.viaware.tileset.utils.FileUtils.java
ca.viaware.tileset.utils.Utils.java