public static boolean isTouchingCannon(Vector3 touchPos) { Cannon cannon = GameScreen.cannon; Vector2 origin = cannon.getPosition(); origin.x = Utils.convertToWorld(origin.x); origin.y = Utils.convertToWorld(origin.y); origin.sub(new Vector2(cannon.wrapper.width / 2, cannon.wrapper.height / 2)); Vector2 end = new Vector2(cannon.wrapper.width, cannon.wrapper.height); Rectangle rect = new Rectangle(origin.x, origin.y, end.x, end.y); return rect.contains(touchPos.x, touchPos.y); }
@Override public void fire() { Vector2 bullet_position = new Vector2( Utils.convertToWorld(body.getPosition().x), Utils.convertToWorld(body.getPosition().y)); bullet_position = bullet_position.add( new Vector2(0, -Constants.ENEMY_HEIGHT / 2 - Constants.BULLET_HEIGHT / 2)); Bullet bullet = new IceBullet(bullet_position, GameScreen.world, 0, true); float target_angle = (float) (Math.PI / 2 + Math.atan2( (double) this.getPosition().y - GameScreen.cannon.getPosition().y, (double) this.getPosition().x - GameScreen.cannon.getPosition().x)); bullet.body.setLinearVelocity( new Vector2( (float) ((-4f) * Math.sin(target_angle)), (float) ((2f) * Math.cos(target_angle)))); GameScreen.bullets.add(bullet); }