-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel.js
More file actions
154 lines (147 loc) · 5.74 KB
/
level.js
File metadata and controls
154 lines (147 loc) · 5.74 KB
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
function Level(n) {
this.n = n
this.complete = false
this.locked = true
let budgets = [90, 80, 70, 250, 700, 300, 400, 750, 2000]
this.budget = budgets[n]
this.money = this.budget
this.started = false
let status = 'none'
this.load = function () {
changeScreen('game')
currentLevel = this
this.started = false
this.money = this.budget
status = 'none'
clearTroops()
let troops = blueTroops
let team = 'blue'
let offset = width / 2
switch (n) {
case 0:
for (let i = 0; i < 8; i++) {
troops.push(new Soldier(offset + width / 8, height / 2 + (i - 3.5) * width / 32, team))
}
break
case 1:
for (let i = 0; i < 9; i++) {
troops.push(new Soldier(offset + width / 8 + width / 32 * i, height / 2, team))
}
break
case 2:
for (let i = 0; i < 5; i++) {
troops.push(new Soldier(offset + width / 12, height / 2 + i * width / 32, team))
}
for (let i = 0; i < 3; i++) {
troops.push(new Archer(offset + width / 8, height / 12 + i * width / 32, team))
}
break
case 3:
for (let i = 0; i < 10; i++) {
troops.push(new Soldier(offset + width / 12, height / 2 + (i - 5) * width / 32, team))
}
for (let i = 0; i < 16; i++) {
troops.push(new Soldier(offset + width / 24, height / 2 + (i - 8) * width / 32, team))
}
for (let i = 0; i < 10; i++) {
troops.push(new Soldier(offset + width / 8, height / 2 + (i - 5) * width / 32, team))
}
break
case 4:
for (let i = 0; i < 16; i++) {
troops.push(new Soldier(offset + width / 12, height / 2 + (i - 8) * width / 32, team))
}
for (let i = 0; i < 16; i++) {
troops.push(new Soldier(offset + width / 24, height / 2 + (i - 8) * width / 32, team))
}
for (let i = 0; i < 16; i++) {
troops.push(new Soldier(offset + width / 8, height / 2 + (i - 8) * width / 32, team))
}
for (let i = 0; i < 16; i++) {
troops.push(new Archer(offset + width / 3, height / 2 + (i - 8) * width / 32, team))
}
break
// troops.push(new Necromancer(offset + width / 4, height / 2, team))
// troops.push(new Summoner(offset + width / 4 + width / 16, height / 2, team))
case 5:
for (let i = 0; i < 10; i++) {
troops.push(new Summoner(offset + width / 2.5, height / 2 + (i - 5) * width / 32, team))
}
break
case 6:
for (let i = 0; i < 10; i++) {
troops.push(new Shield(offset + width / 6, height / 2 + (i - 5) * width / 32, team))
troops.push(new Archer(offset + width / 3, height / 2 + (i - 5) * width / 32, team))
}
break
case 7:
for (let i = 0; i < 7; i++) {
troops.push(new Reaper(offset + width / 6, height / 2 + (i - 3) * width / 32, team))
troops.push(new EWizard(offset + width / 3, height / 2 + (i - 3) * width / 16, team))
}
troops.push(new Summoner(offset + width / 5, height / 2 + width / 7, team))
troops.push(new Summoner(offset + width / 5, height / 2 - width / 7, team))
troops.push(new Necromancer(offset + width / 5, height / 2, team))
break
case 8:
for (let i = 0; i < 29; i++) {
troops.push(new Shield(offset + width / 32, height / 2 + (i - 15) * width / 64, team))
troops.push(new Spear(offset + width / 16, height / 2 + (i - 15) * width / 64, team))
// troops.push(new Spear(offset + width / 32 + width / 16, height / 2 + (i - 15) * width / 64, team))
}
break
}
}
this.update = function () {
if (this.started) {
if (status == 'none') {
if (redTroops.length == 0) {
battling = false
status = 'defeat'
}
if (blueTroops.length == 0) {
battling = false
status = 'victory'
}
}
}
if (status == 'defeat') {
this.defeat()
} else if (status == 'victory') {
this.victory()
}
}
this.defeat = function () {
rectMode(CENTER)
fill(200)
rect(width / 2, height / 2, width, width / 6)
textSize(width / 12)
noStroke()
fill(0)
textAlign(CENTER, CENTER)
text('Defeat', width / 2, height / 2)
if (mouseIsPressed) {
currentLevel.load()
// currentLevel = undefined
// changeScreen('level_select')
}
}
this.victory = function () {
this.complete = true
if (levels[n + 1]) {
levels[n + 1].locked = false
}
rectMode(CENTER)
fill(200)
rect(width / 2, height / 2, width, width / 6)
textSize(width / 12)
noStroke()
fill(0)
textAlign(CENTER, CENTER)
text('Victory!', width / 2, height / 2)
if (mouseIsPressed) {
currentLevel = undefined
changeScreen('level_select')
}
}
}