-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.wren
185 lines (179 loc) · 4.4 KB
/
main.wren
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
import "audio" for AudioEngine
import "dome" for Window
import "graphics" for Canvas, Color, Font, ImageData
import "input" for Keyboard, Mouse
import "random" for Random
var HI = "0"
var VERSION = "30" // changes with each commit
var MODE = "not-playing" // either "playing" or "not-playing"
class Wall {
FINISH {_fin}
speed {_speed}
random {_rand}
construct new() {
_rand = Random.new()
_y = -100
_x = 960
_speed = random.float(5.0, 15.0)
_ychanger = 80
}
draw() {
if (_x <= 0) _fin = true
_ychanger = _ychanger - 1
if (_ychanger >= 60) {
_y = _y - 5
} else if (_ychanger >= 20) {
_y = _y + 5
} else if (_ychanger >= 0) {
_y = _y - 5
} else {
_ychanger = 80
}
Canvas.rectfill(_x, _y-50, 30, 500, Color.hex("444"))
Canvas.rectfill(_x, _y+550, 30, 500, Color.hex("444"))
_x = _x - 10
}
}
class Nuke {
FINISH {_fin}
x {_x}
y {_y}
speed {_speed}
random {_rand}
rot {_r}
rep {_rep}
dor {_dor}
construct new(startx) {
_rand = Random.new()
_dor = random.int(1, 5)
_y = 0
_x = startx
_speed = random.float(5.0, 15.0)
_rot = 0
_rep = 20
}
draw() {
if (y > 544) _fin = true
_rep = rep - 1
if (rep >= 15) {
_rot = _rot - dor
} else if (rep >= 5) {
_rot = _rot + dor
} else if (rep >= 0) {
_rot = _rot - dor
} else {
_rep = 20
}
_x = x + _rot
Canvas.rectfill(x, y, 15, 40, Color.hex("444"))
Canvas.rectfill(x-15/2, y+5, 30, 10, Color.hex("444"))
//Canvas.trianglefill(x+50, y, x, y-20, x, y+20, Color.hex("444"))
_y = y+speed
}
}
class Triangle {
x {_x}
y {_y}
FINISH {_fin}
speed {_speed}
random {_rand}
construct new(sy) {
_rand = Random.new()
_y = sy
_x = 0
_speed = random.float(10.0, 25.0)
}
draw() {
if (x > 960) _fin = true
Canvas.trianglefill(x+50, y, x, y-20, x, y+20, Color.hex("444"))
_x = x+speed
}
}
class main {
cutfloat(flt) {
_sflt = flt.toString
_dotindex = _sflt.indexOf(".")
_fract = flt.fraction.toString
if (_fract == "0") return _sflt + ".00"
if (_fract.count >= 2) return _sflt[0.._dotindex] + _fract[2..2]
}
construct new() {}
init() {
_audioset = 0
_channel = ""
_uptime = 0
_shapes = []
_rand = Random.new()
_wait = _rand.float(0.25, 0.5)
_tick = 0
_intro = ImageData.loadFromFile("./intro.png")
AudioEngine.load("menu", "menumusic.wav")
AudioEngine.load("game", "gamemusic.wav")
Font.load("OpenSans", "./OpenSans.ttf", 25)
Mouse.hidden = true
Canvas.resize(960, 544)
Window.title = "insane CURSEr c"+VERSION
Window.resize(Canvas.width, Canvas.height)
}
update() {
if ((MODE == "not-playing") && (_audioset == 0)) {
_channel = AudioEngine.play("menu", 100, true)
_audioset = 1
}
if (MODE == "playing") {
if (_audioset==0) {
_channel = AudioEngine.play("game", 100, true)
_audioset = 1
}
_tick = _tick+1
if (_tick >= 60 * _wait) {
if (_rand.int(2) == 0) {
_shapes.add(Triangle.new(_rand.int(544)))
} else if (_rand.int(2) == 0) {
_shapes.add(Nuke.new(_rand.int(960)))
} else if (_rand.int(2) == 0){
_shapes.add(Wall.new())
}
_tick = 0
_wait = _rand.float(0.25, 0.5)
}
}
_shapes.each { |shape|
if (shape.FINISH == true) {
_shapes.removeAt(_shapes_iterator)
}
_shapes_iterator = _shapes_iterator + 1
}
_shapes_iterator = 0
if ((MODE == "not-playing") && (Keyboard.isKeyDown("return"))) {
MODE = "playing"
_channel.stop()
_audioset = 0
}
}
draw(alpha) {
if (MODE == "playing") {
_uptime = _uptime+1/30
Canvas.cls()
Font["OpenSans"].print("survived "+cutfloat(_uptime).toString+" secs", 10, 10, Color.white)
Canvas.circlefill(Mouse.x, Mouse.y, 5, Color.white)
_shapes.each { |shape|
shape.draw()
}
if (Canvas.pget(Mouse.x, Mouse.y) == Color.hex("444")) {
_shapes = []
if (_uptime > Num.fromString(HI)) HI = cutfloat(_uptime).toString
_uptime = 0
MODE = "not-playing"
_channel.stop()
_audioset = 0
}
} else {
Canvas.cls()
_intro.draw(0,0)
Canvas.circlefill(Mouse.x, Mouse.y, 5, Color.white)
Font["OpenSans"].print("Press <RETURN> to start the chaos\nHIGHSCORE: "+HI, 10, 10, Color.white)
}
}
}
var Game = main.new()