Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.iMackshun.Games.SoulBlazeDroid.RPGObjects;
- import com.badlogic.gdx.graphics.g2d.Animation;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- public class CharacterInBattle {
- // Class Properties
- private int X;
- private int Y;
- private int DestinationX;
- private int DestinationY;
- private int StoredX;
- private int StoredY;
- private String WhichCharacter;
- private TextureRegion[] ArcionRegions, RandRegions, Regions;
- private TextureRegion CurrentRegion, TestRegion;
- private Animation LeftRun;
- private Boolean Moving;
- private float stateTime;
- private float Timer = 0;
- private int MoveSpeed = 1;
- private boolean Attacking = false;
- private boolean Attacked = false;
- private TextureAtlas SpriteAtlas;
- private Sprite Character;
- // Constructor
- public CharacterInBattle(int X, int Y, String WhichCharacter) {
- this.X = X;
- this.Y = Y;
- this.DestinationX = X;
- this.DestinationY = Y;
- this.WhichCharacter = WhichCharacter;
- SpriteAtlas = new TextureAtlas("Packs/SpritePack.atlas");
- ArcionRegions = new TextureRegion[3];
- RandRegions = new TextureRegion[3];
- Regions = new TextureRegion[3];
- ArcionRegions[0] = SpriteAtlas.findRegion("ArcionLeft0");
- TestRegion = SpriteAtlas.findRegion("ArcionLeft0");
- ArcionRegions[1] = SpriteAtlas.findRegion("ArcionLeft1");
- ArcionRegions[2] = SpriteAtlas.findRegion("ArcionLeft2");
- RandRegions[0] = SpriteAtlas.findRegion("RandLeft0");
- RandRegions[1] = SpriteAtlas.findRegion("RandLeft1");
- RandRegions[2] = SpriteAtlas.findRegion("RandLeft2");
- //Determine which character to draw.
- if(WhichCharacter == "Arcion"){
- CurrentRegion = ArcionRegions[0];
- LeftRun = new Animation(0.1f, ArcionRegions);
- Regions = ArcionRegions;
- }
- if(WhichCharacter == "Rand"){
- CurrentRegion = RandRegions[0];
- LeftRun = new Animation(0.1f, RandRegions);
- Regions = RandRegions;
- }
- Character = new Sprite(TestRegion);
- }
- // Methods
- // Update Method, Called Every frame
- public void update(float delta) {
- stateTime += delta;
- Timer += delta;
- Character.setPosition(X, Y);
- //Character.setRegion(CurrentRegion);
- CheckMovement();
- CheckAnimation();
- if (Timer >= 5) {
- Attacked = true;
- Attacked = false;
- DestinationX = StoredX;
- DestinationY = StoredY;
- Attacking = false;
- }
- }
- public void draw(SpriteBatch batch) {
- Character.draw(batch);
- }
- public void CheckMovement() {
- if (X < DestinationX) {
- Moving = true;
- X += MoveSpeed;
- }
- if (X > DestinationX) {
- Moving = true;
- X -= MoveSpeed;
- }
- if (Y < DestinationY) {
- Moving = true;
- Y += MoveSpeed;
- }
- if (Y > DestinationY) {
- Moving = true;
- Y -= MoveSpeed;
- }
- if (X == DestinationX && Y == DestinationY) {
- Moving = false;
- }
- }
- public void CheckAnimation() {
- if (Moving) {
- CurrentRegion = LeftRun.getKeyFrame(stateTime);
- }
- if (!Moving) {
- CurrentRegion = Regions[1];
- }
- }
- public void Attack() {
- ResetTimer();
- Attacking = true;
- StoredX = X;
- StoredY = Y;
- DestinationX = X - 50;
- }
- public void ResetTimer() {
- Timer = 0;
- }
- // Getters and Setters
- public int getX() {
- return X;
- }
- public int getY() {
- return Y;
- }
- public int getDestinationX() {
- return DestinationX;
- }
- public int getDestinationY() {
- return DestinationY;
- }
- public int getStoredX() {
- return StoredX;
- }
- public int getStoredY() {
- return StoredY;
- }
- public TextureRegion[] getRegions() {
- return Regions;
- }
- public TextureRegion getCurrentRegion() {
- return CurrentRegion;
- }
- public Animation getLeftRun() {
- return LeftRun;
- }
- public Boolean getMoving() {
- return Moving;
- }
- public float getStateTime() {
- return stateTime;
- }
- public float getTimer() {
- return Timer;
- }
- public int getMoveSpeed() {
- return MoveSpeed;
- }
- public boolean isAttacking() {
- return Attacking;
- }
- public boolean isAttacked() {
- return Attacked;
- }
- public void setX(int x) {
- X = x;
- }
- public void setY(int y) {
- Y = y;
- }
- public void setDestinationX(int destinationX) {
- DestinationX = destinationX;
- }
- public void setDestinationY(int destinationY) {
- DestinationY = destinationY;
- }
- public void setStoredX(int storedX) {
- StoredX = storedX;
- }
- public void setStoredY(int storedY) {
- StoredY = storedY;
- }
- public void setRegions(TextureRegion[] regions) {
- Regions = regions;
- }
- public void setCurrentRegion(TextureRegion currentRegion) {
- CurrentRegion = currentRegion;
- }
- public void setLeftRun(Animation leftRun) {
- LeftRun = leftRun;
- }
- public void setMoving(Boolean moving) {
- Moving = moving;
- }
- public void setStateTime(float stateTime) {
- this.stateTime = stateTime;
- }
- public void setTimer(float timer) {
- Timer = timer;
- }
- public void setMoveSpeed(int moveSpeed) {
- MoveSpeed = moveSpeed;
- }
- public void setAttacking(boolean attacking) {
- Attacking = attacking;
- }
- public void setAttacked(boolean attacked) {
- Attacked = attacked;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment