iMackshun

Character in Battle Constructor

Mar 9th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.19 KB | None | 0 0
  1. package com.iMackshun.Games.SoulBlazeDroid.RPGObjects;
  2.  
  3. import com.badlogic.gdx.graphics.g2d.Animation;
  4. import com.badlogic.gdx.graphics.g2d.Sprite;
  5. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  6. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  7. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  8.  
  9. public class CharacterInBattle {
  10.     // Class Properties
  11.     private int X;
  12.     private int Y;
  13.     private int DestinationX;
  14.     private int DestinationY;
  15.     private int StoredX;
  16.     private int StoredY;
  17.     private String WhichCharacter;
  18.     private TextureRegion[] ArcionRegions, RandRegions, Regions;
  19.     private TextureRegion CurrentRegion, TestRegion;
  20.     private Animation LeftRun;
  21.     private Boolean Moving;
  22.     private float stateTime;
  23.     private float Timer = 0;
  24.     private int MoveSpeed = 1;
  25.     private boolean Attacking = false;
  26.     private boolean Attacked = false;
  27.     private TextureAtlas SpriteAtlas;
  28.     private Sprite Character;
  29.  
  30.     // Constructor
  31.     public CharacterInBattle(int X, int Y, String WhichCharacter) {
  32.         this.X = X;
  33.         this.Y = Y;
  34.         this.DestinationX = X;
  35.         this.DestinationY = Y;
  36.         this.WhichCharacter = WhichCharacter;
  37.        
  38.         SpriteAtlas = new TextureAtlas("Packs/SpritePack.atlas");
  39.         ArcionRegions = new TextureRegion[3];
  40.         RandRegions = new TextureRegion[3];
  41.         Regions = new TextureRegion[3];
  42.         ArcionRegions[0] = SpriteAtlas.findRegion("ArcionLeft0");
  43.         TestRegion = SpriteAtlas.findRegion("ArcionLeft0");
  44.         ArcionRegions[1] = SpriteAtlas.findRegion("ArcionLeft1");
  45.         ArcionRegions[2] = SpriteAtlas.findRegion("ArcionLeft2");
  46.         RandRegions[0] = SpriteAtlas.findRegion("RandLeft0");
  47.         RandRegions[1] = SpriteAtlas.findRegion("RandLeft1");
  48.         RandRegions[2] = SpriteAtlas.findRegion("RandLeft2");
  49.        
  50.         //Determine which character to draw.
  51.         if(WhichCharacter == "Arcion"){
  52.             CurrentRegion = ArcionRegions[0];
  53.             LeftRun = new Animation(0.1f, ArcionRegions);
  54.             Regions = ArcionRegions;
  55.         }
  56.         if(WhichCharacter == "Rand"){
  57.             CurrentRegion = RandRegions[0];
  58.             LeftRun = new Animation(0.1f, RandRegions);
  59.             Regions = RandRegions;
  60.         }
  61.         Character = new Sprite(TestRegion);
  62.     }
  63.  
  64.     // Methods
  65.     // Update Method, Called Every frame
  66.     public void update(float delta) {
  67.         stateTime += delta;
  68.         Timer += delta;
  69.         Character.setPosition(X, Y);
  70.         //Character.setRegion(CurrentRegion);
  71.         CheckMovement();
  72.         CheckAnimation();
  73.         if (Timer >= 5) {
  74.             Attacked = true;
  75.             Attacked = false;
  76.             DestinationX = StoredX;
  77.             DestinationY = StoredY;
  78.             Attacking = false;
  79.         }
  80.  
  81.     }
  82.  
  83.     public void draw(SpriteBatch batch) {
  84.         Character.draw(batch);
  85.     }
  86.  
  87.     public void CheckMovement() {
  88.         if (X < DestinationX) {
  89.             Moving = true;
  90.             X += MoveSpeed;
  91.         }
  92.         if (X > DestinationX) {
  93.             Moving = true;
  94.             X -= MoveSpeed;
  95.         }
  96.         if (Y < DestinationY) {
  97.             Moving = true;
  98.             Y += MoveSpeed;
  99.         }
  100.         if (Y > DestinationY) {
  101.             Moving = true;
  102.             Y -= MoveSpeed;
  103.         }
  104.         if (X == DestinationX && Y == DestinationY) {
  105.             Moving = false;
  106.         }
  107.     }
  108.  
  109.     public void CheckAnimation() {
  110.         if (Moving) {
  111.             CurrentRegion = LeftRun.getKeyFrame(stateTime);
  112.         }
  113.         if (!Moving) {
  114.             CurrentRegion = Regions[1];
  115.         }
  116.     }
  117.  
  118.     public void Attack() {
  119.         ResetTimer();
  120.         Attacking = true;
  121.         StoredX = X;
  122.         StoredY = Y;
  123.         DestinationX = X - 50;
  124.  
  125.     }
  126.  
  127.     public void ResetTimer() {
  128.         Timer = 0;
  129.     }
  130.  
  131.     // Getters and Setters
  132.  
  133.     public int getX() {
  134.         return X;
  135.     }
  136.  
  137.     public int getY() {
  138.         return Y;
  139.     }
  140.  
  141.     public int getDestinationX() {
  142.         return DestinationX;
  143.     }
  144.  
  145.     public int getDestinationY() {
  146.         return DestinationY;
  147.     }
  148.  
  149.     public int getStoredX() {
  150.         return StoredX;
  151.     }
  152.  
  153.     public int getStoredY() {
  154.         return StoredY;
  155.     }
  156.  
  157.     public TextureRegion[] getRegions() {
  158.         return Regions;
  159.     }
  160.  
  161.     public TextureRegion getCurrentRegion() {
  162.         return CurrentRegion;
  163.     }
  164.  
  165.     public Animation getLeftRun() {
  166.         return LeftRun;
  167.     }
  168.  
  169.     public Boolean getMoving() {
  170.         return Moving;
  171.     }
  172.  
  173.     public float getStateTime() {
  174.         return stateTime;
  175.     }
  176.  
  177.     public float getTimer() {
  178.         return Timer;
  179.     }
  180.  
  181.     public int getMoveSpeed() {
  182.         return MoveSpeed;
  183.     }
  184.  
  185.     public boolean isAttacking() {
  186.         return Attacking;
  187.     }
  188.  
  189.     public boolean isAttacked() {
  190.         return Attacked;
  191.     }
  192.  
  193.     public void setX(int x) {
  194.         X = x;
  195.     }
  196.  
  197.     public void setY(int y) {
  198.         Y = y;
  199.     }
  200.  
  201.     public void setDestinationX(int destinationX) {
  202.         DestinationX = destinationX;
  203.     }
  204.  
  205.     public void setDestinationY(int destinationY) {
  206.         DestinationY = destinationY;
  207.     }
  208.  
  209.     public void setStoredX(int storedX) {
  210.         StoredX = storedX;
  211.     }
  212.  
  213.     public void setStoredY(int storedY) {
  214.         StoredY = storedY;
  215.     }
  216.  
  217.     public void setRegions(TextureRegion[] regions) {
  218.         Regions = regions;
  219.     }
  220.  
  221.     public void setCurrentRegion(TextureRegion currentRegion) {
  222.         CurrentRegion = currentRegion;
  223.     }
  224.  
  225.     public void setLeftRun(Animation leftRun) {
  226.         LeftRun = leftRun;
  227.     }
  228.  
  229.     public void setMoving(Boolean moving) {
  230.         Moving = moving;
  231.     }
  232.  
  233.     public void setStateTime(float stateTime) {
  234.         this.stateTime = stateTime;
  235.     }
  236.  
  237.     public void setTimer(float timer) {
  238.         Timer = timer;
  239.     }
  240.  
  241.     public void setMoveSpeed(int moveSpeed) {
  242.         MoveSpeed = moveSpeed;
  243.     }
  244.  
  245.     public void setAttacking(boolean attacking) {
  246.         Attacking = attacking;
  247.     }
  248.  
  249.     public void setAttacked(boolean attacked) {
  250.         Attacked = attacked;
  251.     }
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment