-
Notifications
You must be signed in to change notification settings - Fork 1
/
Planet.as
119 lines (105 loc) · 3.19 KB
/
Planet.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package {
import flash.display.MovieClip;
import flash.geom.ColorTransform;
import fl.motion.Color;
import flash.events.MouseEvent;
import flash.geom.Point;
public class Planet extends MovieClip {
var population:Number;
public var spaceHub:SpaceHub = null;
var color:Color;
public var pName;
var infomenu:PlanetInfoMenu;
public var board:SpaceBoard;
public function Planet(myName:String, sb:SpaceBoard) {
this.pName = myName;
this.board = sb;
planetName.nameBox.text = pName;
this.scaleX = .25;
this.scaleY = .25;
this.planetSphere.rotation = (Math.random()*300)+30;
this.population = Math.floor(Math.random()*1293)*Math.floor(Math.random()*4321)*2382;
this.addEventListener(MouseEvent.CLICK, clicked);
this.addEventListener(MouseEvent.MOUSE_OVER, mouseover);
this.addEventListener(MouseEvent.MOUSE_OUT, mouseout);
//random color
//random
}
public function popPackages() {
var numPkg:int = 0;
if (spaceHub != null) {
numPkg = 6; //Math.floor(Math.random()*(population/100000000));
}
var i:int;
for (i=0; i < numPkg; i++) {
spaceHub.addPackage(Package.generateRandom());
}
if (infomenu != null) {
infomenu.updateMenu();
}
if (spaceHub != null) {
trace("Adding " + numPkg + "pkgs to " + pName + "for a total of " + spaceHub.packages.length);
}
}
public function addSpaceHub(sh:SpaceHub):void {
if (board.cashOnHand > SpaceHub.NEW_HUB_COST) {
board.adjustCashOnHand(-SpaceHub.NEW_HUB_COST);
this.spaceHub = sh;
//adjust planet sprite based on hub size
planetSphere.gotoAndPlay("SmallSpaceport");
board.drawRoutes();
} else {
trace("No monies :(");
}
}
public function removeSpaceHub():void {
//deduct cost-to-close from treasury
//disallow new arrivals
//wait until empty, then delete object
//OR close immediately, lose packages. In this case pay package value.
if (board.cashOnHand > spaceHub.costToClose()) {
trace("closing hub on " + pName);
board.adjustCashOnHand(-spaceHub.costToClose());
this.spaceHub = null;
//adjust planet sprite based on hub size
planetSphere.gotoAndPlay("NoSpaceport");
board.drawRoutes();
} else {
trace("No monies :(");
}
}
public function getCenter():Point {
return new Point(this.x, this.y);
}
public function clicked(me:MouseEvent) {
trace("Oh dearie me, I have been clicked!");
this.openInfoMenu();
}
public function toggleSpaceport() {
if (this.spaceHub != null) {
removeSpaceHub();
} else {
addSpaceHub(new SpaceHub(50, 2));
}
}
public function mouseover(me:MouseEvent) {
//this.planetName.alpha = 1;
//planetName.nameBox.text = pName;
}
public function mouseout(me:MouseEvent) {
//this.planetName.alpha = 0;
//planetName.nameBox.text = pName;
}
public function openInfoMenu() {
infomenu = new PlanetInfoMenu(this);
infomenu.x = stage.stageWidth/2;
infomenu.y = stage.stageHeight/2;
stage.addChild(infomenu);
infomenu.closingX.addEventListener(MouseEvent.CLICK, function() {
stage.removeChild(infomenu);
infomenu = null;
});
//addChild(new InfoMenu(this));
}
}
}