-
Notifications
You must be signed in to change notification settings - Fork 0
/
Key.as
60 lines (52 loc) · 1.52 KB
/
Key.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
package {
import flash.display.MovieClip;
import flash.events.Event;
import Box2D.Dynamics.b2Body;
import flash.geom.Point;
public class Key extends MovieClip {
public static const YELLOW:Number = 1;
public static const GREEN:Number = 2;
public static const RED:Number = 3;
public static const BLUE:Number = 4;
public var curColor:Number = YELLOW;
public static const Name:String = "key";
protected var info:informBlockListPlatform;
public var body:b2Body;
public function Key(color:Number, withoutBody:Boolean = false, loc:Point = null) {
// constructor code
if(color > 0 && color < 5) {
this.gotoAndStop(color);
this.curColor = color;
} else {
trace("error set color key");
}
if(loc)
{
this.x = loc.x;
this.y = loc.y;
}
if(!withoutBody) {
if(stage) addStage();
else this.addEventListener(Event.ADDED_TO_STAGE, addStage);
}
}
protected function addStage(event:Event = null):void
{
if(event) this.removeEventListener(Event.ADDED_TO_STAGE, addStage);
info = informBlockListPlatform.GetInformBlock(stage);
body = info.createWorld.createStaticBox(this.x, this.y, 45, 45);
body.GetFixtureList().SetSensor(true);
body.GetUserData().reference = this;
body.GetUserData().name = Name;
body.GetUserData().item = true;
body.GetUserData().activeObject = true;
}
public function Delete():void
{
if(this.parent) this.parent.removeChild(this);
if(body && info) {
info.game.player.arrayDelete.push(body);
}
}
}
}