-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
181 lines (181 loc) · 5.1 KB
/
main.ts
File metadata and controls
181 lines (181 loc) · 5.1 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
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
namespace SpriteKind {
export const polygon = SpriteKind.create()
export const none = SpriteKind.create()
}
function buildGun () {
gun = sprites.create(img`
. . . . . . . c 7 . . . . . . .
. . . . . . . c 7 . . . . . . .
. . . . . . . c 7 . . . . . . .
. . . . . . . c b . . . . . . .
. . . . . . . f f . . . . . . .
. . . . . . . c 7 . . . . . . .
. . . . . . . f f . . . . . . .
. . . . . . . 8 7 . . . . . . .
. . . . . . 8 8 5 6 . . . . . .
. . . . . . 8 7 5 6 . . . . . .
. . . . . c c c 6 6 6 . . . . .
. . . . 8 8 7 7 7 5 6 6 . . . .
. . 8 f f f c c 6 6 f f 6 6 . .
. 8 8 8 8 6 6 7 7 7 7 5 7 6 6 .
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
`, SpriteKind.Player)
gun.bottom = scene.screenHeight()
gun.right = 120
gun.setFlag(SpriteFlag.BounceOnWall, true)
}
function init_levels () {
Level_name = ["Beginner", "Default", "Advanced"]
r_min = [30, 10, 10]
r_max = [50, 30, 20]
level = 1
output = sprites.create(img`
.
`, SpriteKind.none)
output.y = 80
output.say(Level_name[level], 3000)
}
function gun_charging () {
gun.image.replace(7, 2)
b_gun_ready = false
start_gun_charging_time = game.runtime()
}
controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
if (!(b_changing_level)) {
level = 0
level_changed()
}
})
function launchSpinner () {
radius = Math.randomRange(r_min[level], r_max[level])
myPolygon = polygon.createPolygon(Math.randomRange(3, 10), radius, Math.randomRange(1, 14), 0)
mySpinner = spinner.createSpinner(myPolygon, Math.randomRange(0, 20), Direction.Random)
myPolygon.spokes = true
myPolygon.sprite.setKind(SpriteKind.polygon)
myPolygon.sprite.x = Math.randomRange(0, 160)
myPolygon.sprite.y = 30
myPolygon.sprite.vx = Math.randomRange(20, 150)
myPolygon.sprite.ax = Math.randomRange(-50, 50)
myPolygon.sprite.setFlag(SpriteFlag.BounceOnWall, true)
}
function start_game () {
info.setScore(0)
info.startCountdown(60)
gun.vx = 50 + level * 50
gun_ready()
launchSpinner()
}
function show_instructions () {
T = "Buttons: "
T = "" + T + "A = shoots. Left = Beginner. "
T = "" + T + "Up = Normal. Right = Advanced."
game.showLongText(T, DialogLayout.Center)
}
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
info.changeScoreBy(-1)
if (b_gun_ready) {
music.magicWand.play()
particle = sprites.create(img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . 2 2 2 . . . . . .
. . . . . . 4 b 4 4 . . . . . .
. . . . . 2 b 4 f 2 4 2 . . . .
. . . . 2 b b b f f 4 2 2 . . .
. . . . b b f 4 b b 4 4 2 . . .
. . . . 2 b f f b 4 f 2 4 . . .
. . . . . 2 4 4 2 b b 4 . . . .
. . . . . . 2 2 2 2 . . . . . .
. . . . . . . 2 . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`, SpriteKind.Player)
particle.bottom = gun.top
particle.x = gun.x
particle.vy = -100
particle.startEffect(effects.trail)
} else {
gun.startEffect(effects.ashes)
}
gun_charging()
})
controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
if (!(b_changing_level)) {
level = 2
level_changed()
}
})
function level_changed () {
b_changing_level = true
pause(1000)
spinner.destroySpinner(mySpinner)
output.say(Level_name[level], 3000)
pause(1000)
start_game()
b_changing_level = false
}
sprites.onOverlap(SpriteKind.Player, SpriteKind.polygon, function (sprite, otherSprite) {
if (!(b_in_overlap)) {
b_in_overlap = true
mySpinner.speed = 0
otherSprite.vx = 0
otherSprite.ax = 0
pause(200)
music.playTone(262, music.beat(BeatFraction.Half))
otherSprite.startEffect(effects.fire, 1000)
otherSprite.ay = 150
mySpinner.speed = 20
pause(300)
mySpinner.direction = Direction.Clockwise
pause(300)
mySpinner.direction = Direction.Clockwise
pause(500)
info.changeScoreBy(myPolygon.sides)
spinner.destroySpinner(mySpinner)
pause(500)
launchSpinner()
b_in_overlap = false
}
})
function gun_ready () {
gun.image.replace(2, 7)
b_gun_ready = true
}
controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
if (!(b_changing_level)) {
level = 1
level_changed()
}
})
let particle: Sprite = null
let T = ""
let mySpinner: spinner.Spinner = null
let myPolygon: Polygon = null
let radius = 0
let start_gun_charging_time = 0
let b_gun_ready = false
let output: Sprite = null
let level = 0
let r_max: number[] = []
let r_min: number[] = []
let Level_name: string[] = []
let gun: Sprite = null
let b_changing_level = false
let b_in_overlap = false
show_instructions()
init_levels()
b_in_overlap = false
b_changing_level = false
buildGun()
start_game()
game.onUpdate(function () {
if (game.runtime() - start_gun_charging_time > 1000) {
if (!(b_in_overlap)) {
gun_ready()
}
}
})