-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marriage.as
142 lines (115 loc) · 2.64 KB
/
Marriage.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
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.*;
import net.flashpunk.utils.*;
import net.flashpunk.Sfx;
public class Marriage extends Entity
{
public var husband: Person = null;
public var wife: Person = null;
public var children: Vector.<Person> = new Vector.<Person>();
public var sameSex:Boolean;
public var age: Number = 0;
public var nextBaby: Number = 4;
public var piety:Number = 5;
[Embed(source = 'assets/baby.mp3')]
private const BABY1:Class;
[Embed(source = 'assets/baby2.mp3')]
private const BABY2:Class;
[Embed(source = 'assets/baby3.mp3')]
private const BABY3:Class;
public var baby: Array = [new Sfx(BABY1), new Sfx(BABY2), new Sfx(BABY3)];
[Embed(source = 'assets/wedding.mp3')]
private const WEDDING:Class;
public var wedding:Sfx = new Sfx(WEDDING);
public function Marriage (a: Person, b: Person)
{
if (a.gender == "male")
{
husband = a;
wife = b;
}else
{
wife = a;
husband = b;
}
if (a.gender == b.gender)
{
sameSex = true;
piety = -35;
}else
{
sameSex = false;
}
husband.marriage = this;
wife.marriage = this;
layer = -1;
nextBaby = 2 + Math.random() * 2;
wedding.play();
}
public override function update (): void
{
if (husband == null)
{
return
}
age += 0.002;
nextBaby -= 0.002;
if (nextBaby < 0) {
if (Math.random() < 0.5) {
nextBaby = 1.0 + Math.random() * 1.5;
} else {
nextBaby = 100000;
}
if (sameSex == false)
{
var child: Person = new Person();
child.x = wife.x + Math.random() * 16 - 8;
child.y = wife.y + Math.random() * 16 - 8;
children.push(child);
FP.world.add(child);
var world:Level = FP.world as Level;
world.piety += 0.02
if (world.piety > 1)
{
world.piety = 1;
}
FP.choose(baby).play();
}
}
}
public function other(a:Person):Person
{
if (husband == a)
{
return wife;
}
return husband;
}
public override function render (): void
{
if (husband == null)
{
return
}
Draw.linePlus(husband.x, husband.y, wife.x, wife.y, 0x800000, 1.0, 3.0);
var midx: Number = (husband.x + wife.x) * 0.5;
var midy: Number = (husband.y + wife.y) * 0.5;
for each (var child: Person in children) {
if (child.alive)
{
Draw.linePlus(midx, midy, child.x, child.y, 0x000000);
}
}
}
public function end_marriage():void
{
husband.marriage = null;
wife.marriage = null;
husband = null;
wife = null;
}
}
}