So I had a working way to move the PlayerShip that was like this : if (playerclicksdown) y += 10 etc. But I wanted to do something more advanced so I made this :
package { import net.flashpunk.Entity; import net.flashpunk.FP; import net.flashpunk.graphics.Image; import net.flashpunk.utils.Input; import net.flashpunk.utils.Key;
/**
* ...
* @author Law
*/
public class PlayerShip extends Entity {
[Embed(source = "../assets/PlayerShipImage.png")]
private const IMAGE:Class;
private const MAX_UP_SPEED:int = 3;
private const MAX_DOWN_SPEED:uint = 2;
private var CURRENT_SPEED:int;
private const ACCELRATION:uint = 0.5;
public function PlayerShip() {
graphic = new Image(IMAGE);
x = 200;
y = 400;
setHitboxTo(graphic);
Input.define("up", Key.W, Key.UP);
Input.define("down", Key.S, Key.DOWN);
Input.define("left", Key.A, Key.LEFT);
Input.define("right", Key.D, Key.RIGHT);
}
override public function update():void {
if (Input.check("up") && CURRENT_SPEED < MAX_UP_SPEED) {
CURRENT_SPEED += ACCELRATION;
}
if (Input.check("down") && CURRENT_SPEED > MAX_DOWN_SPEED) {
CURRENT_SPEED -= ACCELRATION;
}
if (Input.check("right") && x + width < FP.screen.width) {
x += 2;
}
if (Input.check("left") && x > 0) {
x -= 2;
}
if (y + height < FP.screen.height && y > 0) {
y -= CURRENT_SPEED;
}
}
}
}
Soo could someone tell me what I am doing wrong , and no CURRENT_SPEED is not a const.