Advertisement
Guest User

Untitled

a guest
Sep 12th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. @Override
  2.     public void update() {
  3.         super.update();
  4.  
  5.         joyInput.update();
  6.  
  7.         float inpX = joyInput.VelocityX;
  8.         float inpY = joyInput.VelocityY;
  9.  
  10.         if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_LEFT]) {
  11.             inpX = -1;
  12.             Rotation = 270;
  13.         }
  14.  
  15.         if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_RIGHT]) {
  16.             inpX = 1;
  17.             Rotation = 90;
  18.         }
  19.  
  20.         if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_DOWN]) {
  21.             inpY = 1;
  22.             Rotation = 180;
  23.         }
  24.  
  25.         if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_UP]) {
  26.             inpY = -1;
  27.             Rotation = 0;
  28.         }
  29.  
  30.         X += inpX * (WALK_SPEED * Engine.Current.DeltaTime);
  31.         Y += inpY * (WALK_SPEED * Engine.Current.DeltaTime);
  32.  
  33.         Engine.Current.Graphics.Camera.X = X - (Engine.Current.Graphics.ViewWidth / 2);
  34.         Engine.Current.Graphics.Camera.Y = Y - (Engine.Current.Graphics.ViewHeight / 2);
  35.  
  36.         int finger = 0;
  37.         if((finger = Engine.Current.Input.isTouchingZone(0, 0, Engine.Current.Graphics.ViewWidth, Engine.Current.Graphics.ViewHeight)) != -1) {
  38.             Input.TouchState state = Engine.Current.Input.Touches[finger];
  39.  
  40.             aimX = state.X;
  41.             aimY = state.Y;
  42.  
  43.             // Convert player position from world-space, to screen-space
  44.             float ptfX = (X - Engine.Current.Graphics.Camera.X) - state.X;
  45.             float ptfY = (Y - Engine.Current.Graphics.Camera.Y) - state.Y;
  46.  
  47.             Rotation = (float)Math.toDegrees(Math.atan2(-ptfX, ptfY));
  48.             recalculateForward();
  49.  
  50.             if(nextAttack < 0) {
  51.                 GunItem currGun = Guns.get(EquippedGun);
  52.                 currGun.Gun.FireEffect.createInstance().play();
  53.                 nextAttack = currGun.Gun.Speed;
  54.  
  55.                 Bullet bullet = new Bullet();
  56.                 bullet.Speed = 15;
  57.                 bullet.LifeTime = 3.0f;
  58.                 bullet.Rotation = Rotation;
  59.                 bullet.Damage = currGun.Gun.Damage;
  60.  
  61.                 float bullX = sprites[currGun.Gun.Sprite].Width / 2;
  62.                 float bullY = sprites[currGun.Gun.Sprite].Height / 2;
  63.                 float fwXFactor = ForwardX * 19;
  64.                 float fwYFactor = ForwardY * 19;
  65.  
  66.                 bullet.X = X + bullX - (Bullet.Drawable.Width / 2) + fwXFactor;
  67.                 bullet.Y = Y + bullY - (Bullet.Drawable.Height / 2) + fwYFactor;
  68.  
  69.                 Game.current.World.spawn(bullet);
  70.             }
  71.         }
  72.         nextAttack -= Engine.Current.DeltaTime;
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement