forked from maffei2443/TP2_2_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry.rb
333 lines (271 loc) · 7.06 KB
/
try.rb
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
$yellow = 0xff_ffff00
$orange = 0xff_ff8000
# class Dessert
# def initialize(name, calories)
# @name=name
# @calories=calories
# end
# def healthy?
# if(@calories<200)
# return true
# else
# return false
# end
# end
# def delicious?
# return true
# end
# end
# class JellyBean < Dessert
# def initialize(name, calories, flavor)
# @name=name
# @calories=calories
# @flavor=flavor
# end
# def delicious?
# return true unless @flavor == "black licorice"
# end
# end
require 'gosu'
class Sprite
def initialize(name)
@spriteform = Gosu::Image.new(name)
end
def draw( x, y, z)
@spriteform.draw(x, y - (2 * (z - 1)), z, 1, 1)
end
end
class Hitbox
def initialize(x, y, zlist, width, length)
@width = width
@length = length
@x = x
@y = y
@zlist = zlist
end
def x()
@x
end
def x=(x)
@x = x
end
def y()
@y
end
def y=(y)
@y = y
end
def zlist()
@zlist
end
def width()
@width
end
def length()
@length
end
def check_hit(x_hit, y_hit, zlist_hit, width_hit, ln_hit)
heightimp = false
@zlist.each do |heightLevel|
zlist_hit.each do
|hitheight|
if (heightLevel == hitheight)
heightimp = true
end
end
end
if (((@x > x_hit + width_hit or x_hit > @x + @width) or (@y > y_hit + ln_hit or y_hit > @y + @length)) or (heightimp == false))
return false
else
return true
end
end
end
class GameObject
def initialize(name, x, y, zlist, width, length)
@name = name
@sprite = Sprite.new(name + ".png")
@hitbox = Hitbox.new(x,y,zlist,width,length)
end
def draw()
@sprite.draw(@x, @y, @z)
end
def hit?(obj)
return @hitbox.check_hit(obj.hitbox.x, obj.hitbox.y, obj.hitbox.zlist, obj.hitbox.width, obj.hitbox.length)
end
def hitbox()
@hitbox
end
def execgl()
end
end
class Falcon < GameObject
def initialize(name, x, y, zlist, width, length)
@movCoolDownTimerV = 0
@movCoolDownTimerH = 0
@name = name
@sprites = [Sprite.new(name + "1.png"), Sprite.new(name + "2.png"),Sprite.new(name + "3.png"),Sprite.new(name + "4.png"),Sprite.new(name + "5.png")]
@hitbox = Hitbox.new(x,y,zlist,width,length)
@spritestate = 1
@spriteStateCounter = 0
end
def draw()
@sprites[@spritestate - 1].draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0])
Gosu::Image.new(@name + @spritestate.to_s + ".png").draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0]-1, 1, 1, 0xff_464678, :default)
end
def mov_up()
if (@hitbox.zlist[0] < 35)
5.times do
@hitbox.zlist[0] = @hitbox.zlist[0] + 1
end
@movCoolDownTimerV = 2
end
end
def mov_down()
if (@hitbox.zlist[0] > 9)
5.times do
@hitbox.zlist[0] = @hitbox.zlist[0] - 1
end
@movCoolDownTimerV = 2
end
end
def mov_right()
if (@hitbox.y + @hitbox.length < 480 - 32)
3.times do
@hitbox.y = @hitbox.y + 1
@hitbox.x = @hitbox.x + 1
@movCoolDownTimerH = 2
end
end
end
def mov_left()
if (@hitbox.x > 32)
3.times do
@hitbox.y = @hitbox.y - 1
@hitbox.x = @hitbox.x - 1
@movCoolDownTimerH = 2
end
end
end
def execgl() # Obs: nao faz sentigo execgl estar num obj do jogo ser responsavel pelo jogo. Tirar daqui
# Sugestao : update_falcon() E funcao externa paragame_loop
@spriteStateCounter = @spriteStateCounter + 1
if(@spriteStateCounter == 6)
@spriteStateCounter = 0
@spritestate = @spritestate + 1
if(@spritestate == 6)
@spritestate = 1
end
end
if @movCoolDownTimerV > 0
@movCoolDownTimerV = @movCoolDownTimerV - 1
end
if @movCoolDownTimerH > 0
@movCoolDownTimerH = @movCoolDownTimerH - 1
end
if ((Gosu.button_down? Gosu::KB_UP) and (@movCoolDownTimerV == 0))
self.mov_up
end
if ((Gosu.button_down? Gosu::KB_DOWN) and (@movCoolDownTimerV == 0))
self.mov_down
end
if ((Gosu.button_down? Gosu::KB_RIGHT) and (@movCoolDownTimerH == 0))
self.mov_right
end
if ((Gosu.button_down? Gosu::KB_LEFT) and (@movCoolDownTimerH == 0))
self.mov_left
end
end
end
class Hiero < GameObject
def initialize(name, x, y, zlist, width, length)
@movCoolDownTimer = 0
@name = name
@sprite = Sprite.new(name + ".png")
@hitbox = Hitbox.new(x,y,zlist,width,length)
end
def draw()
@sprite.draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0])
Gosu::Image.new(@name + ".png").draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0] - 1, 1, 1, 0xff_464678, :default)
end
def execgl()
if @movCoolDownTimer > 0
@movCoolDownTimer = @movCoolDownTimer - 1
elsif(@movCoolDownTimer == 0)
@hitbox.y = @hitbox.y + 1
@hitbox.x = @hitbox.x - 1
@movCoolDownTimerH = 2
end
end
end
class DesertFalconGUI < Gosu::Window
def initialize
super 640, 480
self.caption = "Desert Falcon"
@font = Gosu::Font.new(self, "Arial", 32)
@boopIterator = 0
@sysTime = (Time.now.to_f * 1000)
@FPScount = 0.0
@objArray = []
@objArray.insert(-1,Falcon.new("falcon", 32, 288, [25], 32, 32))
end
def make10tallObj(z1)
return [z1,z1 + 1,z1 + 2,z1 + 3,z1 + 4,z1 + 5,z1 + 6,z1 + 7,z1 + 8,z1 + 9]
end
def update
@objArray.each do |obj|
obj.execgl
end
srand Random.new_seed
if (rand(1000).to_i == 0)
@objArray.insert(- 1,Hiero.new("hiero", 288 + (rand(320).to_i), 32, make10tallObj((rand(7).to_i + 1) * 5), 16, 16))
end
@objArray.each do |obj|
if (obj.hit?(@objArray[0]) and obj.class == Hiero.new("hiero",0,0,[0],0,0).class)
@objArray.delete(obj)
elsif (obj.hitbox.x < 32)
@objArray.delete(obj)
end
end
end
def draw
Gosu.draw_rect(0, 0, 640, 32, Gosu::Color.argb(0xff_a00000), 46, :default)
Gosu.draw_rect(0, 0, 32, 480, Gosu::Color.argb(0xff_a00000), 46, :default)
Gosu.draw_rect(608, 0, 32, 480, Gosu::Color.argb(0xff_a00000), 46, :default)
Gosu.draw_rect(0, 448, 640, 32, Gosu::Color.argb(0xff_a00000), 46, :default)
Gosu.draw_rect(32, 32, 576, 416, Gosu::Color.argb(0xff_F0C88C), 0, :default)
# Desenha tela inicial
title = "DESERT FALCON 2017 XD"
pos = 32
color = $yellow
tam = title.length
for i in 0..tam do
if title[i] == ' '
pos += 80
else
@font.draw(title[i], pos, 0, 47, 1, 1, color, :default)
pos += 20
if color == $yellow
color = $orange
else
color = $yellow
end
end
end
# Final da tela
@font.draw("FPS := " + @FPScount.to_s, 32, 448, 47, 1, 1, 0xff_8000ff, :default)
@boopIterator = @boopIterator + 1
if (@boopIterator > 60)
@font.draw("BOOP!", 513, 448, 47, 1, 1, 0xff_8000ff, :default)
end
if (@boopIterator == 120)
@boopIterator = 0
@FPScount = 120 / (((Time.now.to_f * 1000) - @sysTime) / 1000)
@sysTime = (Time.now.to_f * 1000)
end
@objArray.each do |objecttorender|
objecttorender.draw
end
end
end
DesertFalconGUI.new.show