-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level.as
219 lines (172 loc) · 4.23 KB
/
Level.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.*;
import net.flashpunk.utils.*;
import Player;
public class Level extends World
{
[Embed(source="assets/church_overview_2.png")]
public static var bgGfx: Class;
[Embed(source="assets/prayer_club.gif")]
public static var prayer: Class;
public var yearText: Text;
public var time: Number = 0;
public var nextNewbie: Number = 0.5;
public var pan:Boolean=false;
public var player:Player;
public var selected:Person = null;
public var hover:Person = null;
public var offset_x:Number = 0;
public var offset_y:Number = 0;
public static const PAN_AREA: Number = 30;
public static const MAX_PAN_SPEED: Number = 2;
public var piety:Number = 0.5;
public var pietySprite:Image;
public function Level()
{
addGraphic(new Stamp(bgGfx), 0, -80, -60);
yearText = new Text("1994", 4, 4);
yearText.scrollX = yearText.scrollY = 0;
pietySprite = new Image(prayer);
pietySprite.scrollX = pietySprite.scrollY = 0;
pietySprite.scale = 0.4;
addGraphic(pietySprite, -5, 570, 440);
addGraphic(yearText);
var a: Person = new Person();
var b: Person = new Person();
var c: Person = new Person();
var d: Person = new Person();
add(a);
add(b);
add(c);
add(d);
player = new Player();
add(player);
}
public function marry(a:Person, b:Person):void
{
if (a == b)
{
return;
}
if (a.alive == false || b.alive == false)
{
piety = piety - 0.4;
return;
}
if (a.marriage)
{
piety = piety - 0.2;
if (a.marriage.other(a) == b)
{
a.marriage.end_marriage();
return;
}
a.marriage.end_marriage();
}
if (b.marriage)
{
piety = piety - 0.2;
b.marriage.end_marriage();
}
var marriage:Marriage = new Marriage(a, b);
piety = piety + 0.01*marriage.piety;
add(marriage);
}
public override function update (): void
{
super.update();
aweful_control_code();
time += 0.004;
yearText.text = "" + int(1994 + time);
}
public function aweful_control_code():void
{
var last_hover:Person = hover;
hover = collidePoint("Person", mouseX, mouseY) as Person;
if (hover)
{
hover.hover_over();
}
if (Input.mousePressed)
{
selected = collidePoint("Person", mouseX, mouseY) as Person;
if (selected)
{
selected.select();
}
}
if (Input.mouseReleased)
{
if (selected)
{
if (hover)
{
marry(selected, hover)
}
selected.unselect();
selected = null;
}
}
var dx: Number, dy: Number;
//Panning
if (Input.mouseX < PAN_AREA)
{
dx = -(1.0 - Input.mouseX / PAN_AREA) * MAX_PAN_SPEED;
FP.camera.x = Math.max(-80, FP.camera.x + dx);
}
if (Input.mouseX > 640 - PAN_AREA)
{
dx = (1.0 - (640 - Input.mouseX) / PAN_AREA) * MAX_PAN_SPEED;
FP.camera.x = Math.min(80, FP.camera.x + dx);
}
if (Input.mouseY < PAN_AREA)
{
dy = -(1.0 - Input.mouseY / PAN_AREA) * MAX_PAN_SPEED;
FP.camera.y = Math.max(-60, FP.camera.y + dy);
}
if (Input.mouseY > 480 - PAN_AREA)
{
dy = (1.0 - (480 - Input.mouseY) / PAN_AREA) * MAX_PAN_SPEED;
FP.camera.y = Math.min(60, FP.camera.y + dy);
}
time += 0.002;
yearText.text = "" + int(1994 + time);
nextNewbie -= 0.002;
if (nextNewbie < 0) {
nextNewbie = 0.25 + Math.random()*0.5;
var person: Person = new Person();
person.age = Math.random()*40 + 18;
person.x = 280 + Math.random() * 120 ;
person.y = 455 + Math.random() * 30;
add(person);
}
}
public override function render():void
{
super.render()
if (selected)
{
if (hover)
{
Draw.linePlus(hover.x, hover.y, selected.x, selected.y, 0x000000);
}else {
Draw.linePlus(mouseX, mouseY, selected.x, selected.y, 0x000000);
}
}
//Draw piety bar
if (piety < 0)
{
piety = 0;
}
if (piety > 1)
{
piety = 1;
}
Draw.rect(FP.camera.x + 565, FP.camera.y + 30, 40, 410, 0x000000);
Draw.rect(FP.camera.x + 570, ((1 - piety) * 400) + FP.camera.y + 35, 30, piety * 400, 0xF5B800);
}
}
}