forked from theblackcascade/Invaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputManager.as
78 lines (77 loc) · 2.11 KB
/
InputManager.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
73
74
75
76
77
78
package
{
import flash.display.Sprite;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.text.TextField;
import flash.ui.KeyboardType;
public class InputManager// это капец, но я не хотел разрастания game.as
{
private var MouseEnabled:Boolean = false;
private static var _instance:InputManager = new InputManager();
public static function get Instance():InputManager//делаем синглетон
{
trace("getInstance");
return _instance;
}
public function InputManager():void
{
trace("Constructor");
if(_instance)
throw new Error("Use Instance Field");
}
public function KeyDownListener(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case 90:
this.toggleInputSource();
break;
case 37:
GameObjectPool.Instance.Search("hero").startFollowing(0,300);
break;
case 39:
GameObjectPool.Instance.Search("hero").startFollowing(490,300);
break;
case 32:
GameObjectPool.Instance.Search("hero").startFire();
Game.Instance.debugText.text = "Bang!";
break;
default:
break;
}
}
public function KeyUpListener(e:KeyboardEvent):void
{
GameObjectPool.Instance.Search("hero").stopFollowing();
GameObjectPool.Instance.Search("hero").stopFire();
}
public function MouseMoveListener(e:MouseEvent):void
{
GameObjectPool.Instance.Search("hero").startFollowing(e.stageX,300);
}
public function toggleInputSource():void
{
if(MouseEnabled)
{
Game.Instance.removeEventListener(MouseEvent.MOUSE_MOVE,MouseMoveListener);
Game.Instance.removeEventListener(MouseEvent.CLICK,ClickListener);
MouseEnabled = false;
}
else
{
Game.Instance.addEventListener(MouseEvent.MOUSE_MOVE,MouseMoveListener);
Game.Instance.addEventListener(MouseEvent.CLICK,ClickListener);
MouseEnabled = true;
}
}
public function ClickListener(e:MouseEvent):void
{
GameObjectPool.Instance.Search("hero").startFire();
}
}
}