Alright I finally did it! I'm learning a gaming library, libGDX, which I especially liked cause of the particles

I'm starting to love those puppies. Anyway, I am following the Dustin Riley tutorials, and I was wondering: How would I be able to, instead of having the spaceship have 8 positions (up right, up, lower right, etc) , be able to press and hold A or D and have the ship rotate accordingly as well as have it "thrust" when W is pressed. I have this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public boolean keyDown(int keycode) { ship = world.getShip(); switch (keycode) { case Keys.W: ship.getVelocity().y += .1; break; case Keys.S: ship.getVelocity().y -= .1; break; case Keys.A: ship.getVelocity().x -= .1; break; case Keys.D: ship.getVelocity().x += .1; break; default: break; } return true; } |
and obviously that doesn't work for so many reasons. I don't even know why I did it, I knew it was ridiculous. And I know about
1
| Keyboard.enableRepeatEvents(true); |
but is there a good way to achieve what I am trying?
EDIT:
Here's the ship class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| package com.slyth.angrymasons.Models;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2;
public class Ship extends MovableEntity {
public Ship(Vector2 position, float width, float height, float rotation, float SPEED) { super(SPEED, rotation, width, height, position); }
public void update() { position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED)); if (velocity.x != 0 || velocity.y != 0) rotation = velocity.angle() - 90;
bounds.x = position.x; bounds.y = position.y; } } |