Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. public class Spearman extends Enemies {
  2. private Body spearman1;
  3. private TextureAtlas atlas;
  4. private Animation approaching,defeated;
  5. private float time;
  6. private TextureRegion spearmaninit;
  7.  
  8. private int spearmanstate=0;
  9.  
  10.  
  11. public Spearman(Play_State state,float x, float y){
  12. super(state,x,y);
  13. atlas=new TextureAtlas();
  14. atlas=Lone_Warrior1.getAtlas(3);
  15. time=0f;
  16.  
  17. Array<TextureRegion> frames=new Array<TextureRegion>();
  18. for(int i=0;i<3;i++)
  19. {
  20. frames.add(new TextureRegion(atlas.findRegion("Spearman"+i)));
  21. }
  22. approaching=new Animation(0.15f,frames);
  23. frames.clear();
  24. for(int i=0;i<5;i++)
  25. {
  26. frames.add(new TextureRegion(atlas.findRegion("Spearmandefeated"+i)));
  27. }
  28. defeated=new Animation(2.2f,frames);
  29. frames.clear();
  30. spearmaninit=new TextureRegion(atlas.findRegion("Spearman0"));
  31. setBounds(getX(),getY(),200/ Lone_Warrior1.PPM,170/Lone_Warrior1.PPM);
  32. setRegion(spearmaninit);
  33.  
  34. }
  35.  
  36. public void update(float dt){
  37.  
  38. if(spearmanstate!=-1) {
  39. setPosition(spearman1.getPosition().x - getWidth() / 2, (spearman1.getPosition().y - getHeight() / 2)+13/Lone_Warrior1.PPM);
  40. if (spearmanstate==0 && spearman1.getLinearVelocity().x>0)
  41. spearmanstate=1;
  42. if (spearmanstate==1 && spearman1.getLinearVelocity().x==0) {
  43. Play_State.bodiesToRemove.add(spearman1);
  44. Play_State.enemycounter++;
  45. spearmanstate = -1;
  46.  
  47. }
  48. if(spearmanstate==0)
  49. spearman1.setLinearVelocity(-2f,0);
  50. setRegion(getFrame(dt));
  51. }
  52. }
  53. public boolean check(){
  54. if(spearmanstate!=-1)
  55. return true;
  56. else
  57. return false;
  58. }
  59. public TextureRegion getFrame(float dt){
  60. TextureRegion region=null;
  61. region=approaching.getKeyFrame(time,true);
  62. if(spearmanstate==1)
  63. region=defeated.getKeyFrame(time);
  64. /* if(!region.isFlipX())
  65. region.flip(true,false);*/
  66. time=time+dt;
  67. return region;
  68.  
  69. }
  70.  
  71. @Override
  72. public void defineEnemy() {
  73. BodyDef bdef=new BodyDef();
  74. bdef.position.set(getX(),getY());
  75. bdef.type=BodyDef.BodyType.DynamicBody;
  76. spearman1=Play_State.world.createBody(bdef);
  77.  
  78. FixtureDef fdef=new FixtureDef();
  79. PolygonShape War1=new PolygonShape();
  80. War1.setAsBox(60/Lone_Warrior1.PPM,60/Lone_Warrior1.PPM);
  81.  
  82. fdef.shape=War1;
  83. fdef.filter.categoryBits=Lone_Warrior1.BIT_APPROACHING;
  84. fdef.filter.maskBits=Lone_Warrior1.BIT_GROUND|Lone_Warrior1.BIT_RUN|Lone_Warrior 1.BIT_ATTACK;
  85. spearman1.createFixture(fdef).setUserData("spearman1");
  86.  
  87. }
  88.  
  89. }
  90.  
  91. public abstract class Enemies extends Sprite {
  92. World world;
  93. Body b2body;
  94. public Enemies(){
  95.  
  96. }
  97. public Enemies(Play_State screen,float x, float y){
  98. this.world=screen.world;
  99. setPosition(x,y);
  100. defineEnemy();
  101. }
  102.  
  103. public abstract void defineEnemy();
  104. public abstract void update(float dt);
  105. public abstract boolean check();
  106. }
  107.  
  108. switch (a) {
  109. case 1:
  110. System.out.println("creating spearman");
  111. spearman.add(new Spearman(screen, (Lone_Warrior1.V_Width /Lone_Warrior1.PPM) + (Lone_Warrior1.x+``(i*500/Lone_Warrior1.PPM)), 100 / Lone_Warrior1.PPM));
  112. break;
  113. }
  114.  
  115. if(fb.getUserData()!=null&&fb.getUserData().equals("spearman1")){
  116. System.out.println("spearman attacked");
  117. if(fa.getUserData()!=null&&fa.getUserData().equals("warriorhighkick")){
  118. System.out.println("spearman lost!");
  119. //Spawner.berserkers.get(0).berserker1.applyForceToCenter(300,100,true);
  120. fb.getBody().applyForceToCenter(300,100,true);
  121. }
  122. else{
  123. System.out.println("spearman wins");
  124. //fa.getBody().applyForceToCenter(-300,0,true);
  125. if(!fa.getUserData().equals("Ground")&&!fa.getUserData().equals("spearman1")){
  126. Play_State.bodiesToRemove.add(fa.getBody());
  127. Warrior.posture=-1;}
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement