-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flag.as
52 lines (43 loc) · 1.49 KB
/
Flag.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
package {
import flash.display.MovieClip;
import Box2D.Dynamics.Contacts.b2Contact;
import flash.geom.Point;
import flash.events.Event;
import Box2D.Dynamics.b2Body;
public class Flag extends MovieClip {
public var info:informBlockListPlatform;
public static const Name:String = "flag";
public var isOpen:Boolean = false;
public function Flag(loc:Point) {
// constructor code
this.x = loc.x;
this.y = loc.y;
this.gotoAndStop(1);
if(stage) addStage();
this.addEventListener(Event.ADDED_TO_STAGE, addStage);
}
public function addStage(event:Event = null):void
{
if(event) this.removeEventListener(Event.ADDED_TO_STAGE, addStage);
info = informBlockListPlatform.GetInformBlock(stage);
info.contactListener.addFunction(CompleteGame);
var body:b2Body = info.createWorld.createStaticBox(this.x, this.y, 40, 60);
body.GetFixtureList().SetSensor(true);
body.GetUserData().name = Flag.Name;
}
public function CompleteGame(contact:b2Contact):void
{
if(isOpen) return;
if((contact.GetFixtureA().GetBody().GetUserData().name == "bodyControl" ||
contact.GetFixtureB().GetBody().GetUserData().name == "bodyControl") &&
(contact.GetFixtureA().GetBody().GetUserData().name == "flag" ||
contact.GetFixtureB().GetBody().GetUserData().name == "flag"))
{
isOpen = true;
this.gotoAndStop(2);
if(InfoGlobal.EndLevel) InfoGlobal.EndLevel.call();
else info.game.CompleteGame();
}
}
}
}