-
Notifications
You must be signed in to change notification settings - Fork 0
/
Owl.as
49 lines (42 loc) · 1.06 KB
/
Owl.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
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Keyboard;
public class Owl extends MovieClip {
private const ACCELERATION:int = 6; //Acceleration
public function Owl()
{
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
this.addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void
{
checkKeys();
}
private function checkKeys():void
{
if (KeyManager.isKeyDown(Keyboard.LEFT) && x > Game.MARGIN_X)
{
x = x - ACCELERATION;
}
else if (KeyManager.isKeyDown(Keyboard.RIGHT) && x < Game.WIDTH - Game.MARGIN_X)
{
x = x + ACCELERATION;
}
if (KeyManager.isKeyDown(Keyboard.UP) && y > 70)
{
y = y - ACCELERATION;
//vespino.currentFrame = 29;
}
else if (KeyManager.isKeyDown(Keyboard.DOWN) && y < Game.HEIGHT - Game.MARGIN_Y)
{
y = y + ACCELERATION;
//vespino.currentFrame = 32;
}
}
}
}