Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void update() {
- super.update();
- joyInput.update();
- float inpX = joyInput.VelocityX;
- float inpY = joyInput.VelocityY;
- if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_LEFT]) {
- inpX = -1;
- Rotation = 270;
- }
- if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_RIGHT]) {
- inpX = 1;
- Rotation = 90;
- }
- if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_DOWN]) {
- inpY = 1;
- Rotation = 180;
- }
- if(Engine.Current.Input.Gamepad.Buttons[Input.GAMEPAD_DPAD_UP]) {
- inpY = -1;
- Rotation = 0;
- }
- X += inpX * (WALK_SPEED * Engine.Current.DeltaTime);
- Y += inpY * (WALK_SPEED * Engine.Current.DeltaTime);
- Engine.Current.Graphics.Camera.X = X - (Engine.Current.Graphics.ViewWidth / 2);
- Engine.Current.Graphics.Camera.Y = Y - (Engine.Current.Graphics.ViewHeight / 2);
- int finger = 0;
- if((finger = Engine.Current.Input.isTouchingZone(0, 0, Engine.Current.Graphics.ViewWidth, Engine.Current.Graphics.ViewHeight)) != -1) {
- Input.TouchState state = Engine.Current.Input.Touches[finger];
- aimX = state.X;
- aimY = state.Y;
- // Convert player position from world-space, to screen-space
- float ptfX = (X - Engine.Current.Graphics.Camera.X) - state.X;
- float ptfY = (Y - Engine.Current.Graphics.Camera.Y) - state.Y;
- Rotation = (float)Math.toDegrees(Math.atan2(-ptfX, ptfY));
- recalculateForward();
- if(nextAttack < 0) {
- GunItem currGun = Guns.get(EquippedGun);
- currGun.Gun.FireEffect.createInstance().play();
- nextAttack = currGun.Gun.Speed;
- Bullet bullet = new Bullet();
- bullet.Speed = 15;
- bullet.LifeTime = 3.0f;
- bullet.Rotation = Rotation;
- bullet.Damage = currGun.Gun.Damage;
- float bullX = sprites[currGun.Gun.Sprite].Width / 2;
- float bullY = sprites[currGun.Gun.Sprite].Height / 2;
- float fwXFactor = ForwardX * 19;
- float fwYFactor = ForwardY * 19;
- bullet.X = X + bullX - (Bullet.Drawable.Width / 2) + fwXFactor;
- bullet.Y = Y + bullY - (Bullet.Drawable.Height / 2) + fwYFactor;
- Game.current.World.spawn(bullet);
- }
- }
- nextAttack -= Engine.Current.DeltaTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement