Advertisement
acegiak

pitchfork homing

May 24th, 2013
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. @Override
  2. public void update(GameScreen game, float delta){
  3. super.update(game, delta);
  4.  
  5. Vector2 distance = this.body.getPosition().sub(game.hero.body.getPosition());
  6. if(distance.len() < (flying?ACTIVE_DISTANCE:ACTIVE_DISTANCE/2f) && alive){
  7. if(flying){
  8. game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(5f,0f).rotate(distance.angle())));
  9. game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(-5f,0f).rotate(distance.angle())));
  10. game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(2f,0f).rotate(distance.angle())));
  11. game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(-2f,0f).rotate(distance.angle())));
  12. }
  13. game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition());
  14.  
  15. if(flying){
  16. this.rotateToAngle(game, pointMeAt, TURN_DEGREES_PER_STEP);
  17. Vector2 move = new Vector2(0f,SPEED).rotate((float) Math.toDegrees(pointMeAt));
  18. this.accelerateToSpeed(game, move, new Vector2(ACCELERATION_RATE, ACCELERATION_RATE));
  19. //body.applyForceToCenter(move.scl(body.getMass()),true);
  20. }
  21. }else{
  22. this.body.setGravityScale(1f);
  23. }
  24. }
  25.  
  26. @Override
  27. public float reportRayFixture(Fixture fixture, Vector2 point,
  28. Vector2 normal, float fraction) {
  29. HashMap<String,Object> userData = ((HashMap<String,Object>)fixture.getBody().getUserData());
  30. if(userData.get("ENTITY") instanceof Hero){
  31. Vector2 distance = this.body.getPosition().sub(point);
  32. pointMeAt = (float) Math.toRadians(distance.angle()+90f);
  33. if(flying == false){
  34. flying = true;
  35. body.applyForceToCenter(0f, LAUNCH_PUSH, true);
  36. this.body.setGravityScale(0f);
  37. }
  38. }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement