Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void update(GameScreen game, float delta){
- super.update(game, delta);
- Vector2 distance = this.body.getPosition().sub(game.hero.body.getPosition());
- if(distance.len() < (flying?ACTIVE_DISTANCE:ACTIVE_DISTANCE/2f) && alive){
- if(flying){
- game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(5f,0f).rotate(distance.angle())));
- game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(-5f,0f).rotate(distance.angle())));
- game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(2f,0f).rotate(distance.angle())));
- game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition().add(new Vector2(-2f,0f).rotate(distance.angle())));
- }
- game.world.rayCast(this, body.getPosition(), game.hero.body.getPosition());
- if(flying){
- this.rotateToAngle(game, pointMeAt, TURN_DEGREES_PER_STEP);
- Vector2 move = new Vector2(0f,SPEED).rotate((float) Math.toDegrees(pointMeAt));
- this.accelerateToSpeed(game, move, new Vector2(ACCELERATION_RATE, ACCELERATION_RATE));
- //body.applyForceToCenter(move.scl(body.getMass()),true);
- }
- }else{
- this.body.setGravityScale(1f);
- }
- }
- @Override
- public float reportRayFixture(Fixture fixture, Vector2 point,
- Vector2 normal, float fraction) {
- HashMap<String,Object> userData = ((HashMap<String,Object>)fixture.getBody().getUserData());
- if(userData.get("ENTITY") instanceof Hero){
- Vector2 distance = this.body.getPosition().sub(point);
- pointMeAt = (float) Math.toRadians(distance.angle()+90f);
- if(flying == false){
- flying = true;
- body.applyForceToCenter(0f, LAUNCH_PUSH, true);
- this.body.setGravityScale(0f);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement