-
Notifications
You must be signed in to change notification settings - Fork 5
/
TestGameplay.as
72 lines (51 loc) · 1.61 KB
/
TestGameplay.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package sentinel.testing.states
{
import sentinel.framework.client.Keyboard;
import sentinel.framework.client.KeyboardState;
import sentinel.framework.events.KeyboardEvent;
import sentinel.gameplay.world.BaseWorld;
import sentinel.gameplay.states.GameplayState;
import sentinel.gameplay.ui.BaseUI;
public class TestGameplay extends GameplayState
{
public function TestGameplay(world:BaseWorld, ui:BaseUI)
{
super(world, ui);
keyboard.addEventListener(KeyboardEvent.KEY_PRESSED, _keyPress);
}
public override function deconstruct():void
{
keyboard.removeEventListener(KeyboardEvent.KEY_PRESSED, _keyPress);
super.deconstruct();
}
private function _keyPress(event:KeyboardEvent):void
{
if (event.keyCode === Keyboard.Q)
{
exit();
}
if (event.keyCode === Keyboard.P)
{
world.frozen = !world.frozen;
}
}
protected override function update():void
{
var kbd:KeyboardState = keyboard.getState();
if (kbd.isDown(Keyboard.A)) world.camera.x -= 3;
if (kbd.isDown(Keyboard.D)) world.camera.x += 3;
if (kbd.isDown(Keyboard.W)) world.camera.y -= 3;
if (kbd.isDown(Keyboard.S)) world.camera.y += 3;
if (kbd.isDown(Keyboard.LEFT_ARROW)) world.camera.rotation -= 0.01;
if (kbd.isDown(Keyboard.RIGHT_ARROW)) world.camera.rotation += 0.01;
if (kbd.isDown(Keyboard.UP_ARROW)) world.camera.zoom += 0.01;
if (kbd.isDown(Keyboard.DOWN_ARROW)) world.camera.zoom -= 0.01;
super.update();
}
protected function exit():void
{
// Override for exit action here.
// e.g. load the main menu state.
}
}
}