-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathitems.rb
699 lines (618 loc) · 16.5 KB
/
items.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# Copyright 2019 Victor David Santos
#
# This file is part of Super Bombinhas.
#
# Super Bombinhas is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Super Bombinhas is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Super Bombinhas. If not, see <https://www.gnu.org/licenses/>.
############################### classes abstratas ##############################
module Item
attr_reader :icon
def check(switch)
if switch[:state] == :taken
SB.player.add_item switch
switch[:obj] = self
return true
elsif switch[:state] == :used
return true
end
false
end
def set_icon(icon)
@icon = Res.img "icon_#{icon}"
end
def take(section, store, x = nil, y = nil, sound_id = :getItem)
info = SB.stage.find_switch self
if store
SB.player.add_item(info)
StageMenu.play_get_item_effect(x, y) if x && y
info[:state] = :temp_taken
else
use section, info
info[:state] = :temp_taken_used
end
SB.play_sound(Res.sound(sound_id))
end
def set_switch(switch)
switch[:state] = if switch[:state] == :taken
:taken_temp_used
elsif switch[:state] == :temp_taken
:temp_taken_used
else
:temp_used
end
end
end
class FloatingItem < GameObject
include Item
attr_reader :bomb_type
def initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, indices = nil, interval = nil, bomb_type = nil)
super x, y, w, h, img, img_gap, sprite_cols, sprite_rows
img_gap = Vector.new(0, 0) if img_gap.nil?
@active_bounds = Rectangle.new x + img_gap.x, y + img_gap.y, @img[0].width * 2, @img[0].height * 2
@state = 3
@counter = 0
@indices = indices
@interval = interval
@bomb_type = bomb_type
end
def update(section)
if SB.player.bomb.collide?(self) and (@bomb_type.nil? or SB.player.bomb.type == @bomb_type)
yield
@dead = true
return
end
unless SB.stage.stopped == :all
@counter += 1
if @counter == 10
if @state == 0 or @state == 1; @y -= 1
else; @y += 1; end
@state += 1
@state = 0 if @state == 4
@counter = 0
end
animate @indices, @interval if @indices
end
end
def take_anim(section, store)
take(section, store, @x - section.map.cam.x + @w, @y - section.map.cam.y)
end
def stop_time_immune?
true
end
def draw(map, section = nil, scale_x = 2, scale_y = 2, alpha = 255, color = 0xffffff)
super(map, scale_x, scale_y, alpha, color)
end
end
################################################################################
class FireRock < FloatingItem
LIGHT_TILES = [
[0, 0, 0],
[-1, 0, 50], [0, -1, 50], [1, 0, 50], [0, 1, 50],
[-1, -1, 125], [1, -1, 125], [-1, 1, 125], [1, 1, 125]
]
def initialize(x, y, args, section)
super x + 6, y + 7, 20, 20, :sprite_FireRock, Vector.new(-2, -17), 4, 1, [0, 1, 2, 3], 5
@score = case args
when '1' then 10
when '2' then 20
when '3' then 50
else 10
end
@color = case args
when '1' then 0xff6600
when '2' then 0x33ff33
when '3' then 0x3399ff
else 0xff9933
end
@active_bounds.x -= C::TILE_SIZE
@active_bounds.y -= C::TILE_SIZE
@active_bounds.w += 2 * C::TILE_SIZE
@active_bounds.h += 2 * C::TILE_SIZE
end
def update(section)
super(section) do
SB.player.stage_score += @score
SB.play_sound(Res.sound(:getFire))
end
end
def draw(map, section)
super(map, section, 2, 2, 255, @color)
section.add_light_tiles(LIGHT_TILES, @x, @y, @w, @h)
end
end
class Life < FloatingItem
def initialize(x, y, args, section, switch)
return if check switch
args = (args || '1').split(',', 3)
if args[1] == '$'
w = 32
h = 32
img = :sprite_megalife
else
x += 2
y += 2
w = 28
h = 28
img = :sprite_Life
end
super x, y, w, h, img, nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6
@lives = args[1] == '$' ? 5 : 1
end
def update(section)
super(section) do
take(section, false)
StageMenu.play_get_item_effect(@x - section.map.cam.x + @w / 2, @y - section.map.cam.y + @h / 2, :life)
section.add_effect(ScoreEffect.new(@x + @w / 2, @y, @lives, true))
end
end
def use(section, switch)
SB.stage.life_count += @lives
set_switch(switch)
true
end
end
class Key < FloatingItem
def initialize(x, y, args, section, switch)
@type = args.to_i
set_icon "Key#{@type}"
switch[:extra] = @type
return if check switch
super x + 3, y + 3, 26, 26, "sprite_Key#{@type}", Vector.new(-3, -3)
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
obj = section.active_object
if obj.is_a?(Door) && obj.locked && @type == obj.type
obj.unlock(section)
set_switch(switch)
end
end
end
class Attack1 < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :Attack1
if check switch
@bomb_type = :azul
return
end
super x + 2, y + 2, 28, 28, :sprite_Attack1, nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :azul
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type
angle = if b.facing_right; 0
else; 180; end
section.add Projectile.new(b.x + b.w / 2 - 10, b.y + b.h / 2 - 6, 1, angle, b)
set_switch(switch)
true
end
end
class Shield < FloatingItem
def initialize(x, y, args, section, switch)
set_icon "shield#{args}"
switch[:extra] = args
@bomb_type = case args
when '2' then :amarela
else :azul
end
return if check(switch)
super x + 2, y + 2, 28, 28, "sprite_shield#{args}", nil, 4, 2,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, @bomb_type
end
def update(section)
super(section) do
take_anim(section, SB.player.bomb.shielded)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type || b.shielded
b.shielded = true
set_switch(switch)
true
end
end
class Heart < FloatingItem
def initialize(x, y, args, section)
args = (args || '1').to_i
bomb = case args
when 1 then :vermelha
when 2 then :verde
when 3 then :branca
else nil
end
if bomb
x += 2
y += 2
w = 28
h = 28
else
w = 32
h = 32
end
super x, y, w, h, bomb.nil? ? 'sprite_megaHeart' : "sprite_heart#{args}", nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, bomb
end
def update(section)
super(section) do
if @bomb_type
SB.player.bomb.hp += 1
else
SB.player.bombs.each { |_, b| b.hp += 1 }
end
SB.play_sound(Res.sound(:getItem))
StageMenu.play_get_item_effect(@x - section.map.cam.x + @w / 2, @y - section.map.cam.y + @h / 2, :health)
end
end
end
class BoardItem < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :board
return if check switch
super x + 6, y + 3, 20, 26, :sprite_boardItem, Vector.new(-6, -3)
@item = true
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
if b.bottom
@board = Board.new(b.x + (b.facing_right ? 0 : b.w - 50), b.y + b.h - 2, b.facing_right, section, switch)
section.add(@board)
set_switch(switch)
true
else
false
end
end
end
class Hammer < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :hammer
return if check(switch)
super x + 7, y + 1, 18, 30, :sprite_hammer, Vector.new(-7, -1)
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
obj = section.active_object
if obj.is_a? Board
obj.take(section)
set_switch(switch)
return true
end
false
end
end
class Spring < GameObject
include Item
def initialize(x, y, args, section, switch)
@switch = switch
@w = 32
set_icon :spring
return if check(switch)
super x, y, 32, 32, :sprite_Spring, Vector.new(-2, -16), 3, 2
@active_bounds = Rectangle.new x, y - 16, 32, 48
@start_y = y
@state = 0
@timer = 0
@indices = [0, 4, 4, 5, 0, 5, 0, 5, 0, 5]
@passable = true
@ready = false
end
def update(section)
unless @ready
section.obstacles << self
@ready = true
end
b = SB.player.bomb
unless SB.stage.stopped == :all
if b.bottom == self
reset if @state == 4
@timer += 1
if @timer == 10
case @state
when 0 then @y += 8; @img_gap.y -= 8; b.y += 8
when 1 then @y += 6; @img_gap.y -= 6; b.y += 6
when 2 then @y += 4; @img_gap.y -= 4; b.y += 4
end
@state += 1
set_animation @state
@timer = 0
end
elsif @state > 0 and @state < 4
reset
end
if @state == 4
animate @indices, 7
@timer += 1
b.stored_forces.y = -18 if @timer <= 6
if @timer == 70
reset
elsif @timer == 7
@y = @start_y
@img_gap.y = -16
end
end
end
if b.collide?(self) and SB.key_pressed?(:up)
take(section, true, @x - section.map.cam.x + @w / 2, @y - section.map.cam.y + @h / 2)
@dead = true
section.obstacles.delete self
end
end
def reset
set_animation 0
@state = @timer = 0
@y = @start_y
@img_gap.y = -16
end
def use(section, switch)
b = SB.player.bomb
return false if b.bottom.nil?
x = b.facing_right ? b.x + b.w + @w : b.x - @w
return false if section.obstacle_at?(x, b.y)
x -= @w if b.facing_right
switch[:state] = :normal
spring = Spring.new(x, (b.y / C::TILE_SIZE).floor * C::TILE_SIZE, nil, section, @switch)
switch[:obj] = spring
section.add spring
end
def stop_time_immune?
true
end
def draw(map, section)
super(map, 2, 2)
if SB.player.bomb.collide?(self)
Res.img(:fx_Balloon2).draw(@x - map.cam.x, @y - map.cam.y - 40, 0, 2, 2)
end
end
end
class Attack2 < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :attack2
if check(switch)
@bomb_type = :vermelha
return
end
super x + 2, y + 2, 28, 28, :sprite_attack2, nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :vermelha
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type
section.add Projectile.new(b.x, b.y, 4, 270, b)
set_switch(switch)
true
end
end
class Herb < SBGameObject
include Item
def initialize(x, y, args, section, switch)
set_icon :herb
return if check(switch)
super x, y - 4, 30, 36, :sprite_herb, Vector.new(-3, -4)
@active_bounds = Rectangle.new(x - 3, y - 8, 36, 40)
end
def update(section)
if SB.player.bomb.collide?(self)
take(section, true, @x - section.map.cam.x + @w / 2, @y - section.map.cam.y + @h / 2)
@dead = true
end
end
def use(section, switch)
obj = section.active_object
if obj.is_a? Monep
obj.activate(section)
set_switch(switch)
end
end
end
class PuzzlePiece < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :puzzlePiece
@number = args.to_i
return if check(switch)
x_off = @number == 2 ? -8 : 0
y_off = @number == 4 ? -8 : 0
super(x + x_off, y + y_off, 32, 32, "sprite_puzzlePiece#{@number}")
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
obj = section.active_object
if obj.is_a? Puzzle
obj.add_piece(section, @number)
set_switch(switch)
end
end
end
class JillisStone < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :jillisStone
return if check(switch)
super(x + 6, y + 6, 20, 20, :sprite_jillisStone, Vector.new(0, -2), 3, 2, [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5], 7)
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
obj = section.active_object
if obj.is_a? MountainBombie
obj.activate
set_switch(switch)
end
end
end
class Attack3 < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :Attack3
if check(switch)
@bomb_type = :amarela
return
end
super x + 2, y + 2, 28, 28, :sprite_Attack3, nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :amarela
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type
b.set_aura(2, 900)
set_switch(switch)
true
end
end
class Attack4 < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :attack4
if check switch
@bomb_type = :azul
return
end
super x + 2, y + 2, 28, 28, :sprite_attack4, nil, 4, 2,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :azul
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type
angle = if b.facing_right; 0
else; 180; end
section.add Projectile.new(b.x + b.w / 2 - 4, b.y + b.h / 2 - 4, 9, angle, b)
set_switch(switch)
true
end
end
class Hourglass < FloatingItem
include Item
def initialize(x, y, args, section)
super x + 2, y + 2, 28, 28, :sprite_hourglass, nil, 8, 1,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :branca
end
def update(section)
super(section) do
SB.player.bomb.reset_cooldown
SB.play_sound(Res.sound(:getItem))
end
end
end
class Attack5 < FloatingItem
def initialize(x, y, args, section, switch)
set_icon :attack5
if check switch
@bomb_type = :azul
return
end
super x + 2, y + 2, 28, 28, :sprite_attack5, nil, 4, 2,
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7], 6, :azul
end
def update(section)
super(section) do
take_anim(section, true)
end
end
def use(section, switch)
b = SB.player.bomb
return false if b.type != @bomb_type
c_x = b.x + b.w / 2 - 10
c_y = b.y + b.h / 2 - 5
(0..7).each do |i|
angle = i * 45
section.add(Projectile.new(c_x, c_y, 11, angle, b))
end
set_switch(switch)
true
end
end
class Star < FloatingItem
def initialize(x, y, args, section, switch)
if switch[:state] == :used
SB.stage.star_count += 1
return
end
super x + 4, y + 4, 24, 24, :sprite_star, Vector.new(-8, -8), 3, 1, [0, 1, 2, 1], 10
end
def update(section)
super(section) do
switch = SB.stage.find_switch(self)
use(section, switch)
StageMenu.play_get_item_effect(@x - section.map.cam.x + @w / 2, @y - section.map.cam.y + @h / 2, :star)
SB.play_sound(Res.sound(:getItem))
end
end
def use(section, switch)
SB.stage.star_count += 1
SB.player.stage_score += 500
switch[:state] = :temp_used
end
end
class Spec < FloatingItem
def initialize(x, y, args, section, switch)
return if SB.player.specs.index(SB.stage.id)
if check(switch)
SB.stage.set_spec_taken
return
end
super x - 1, y - 1, 34, 34, :sprite_Spec, Vector.new(-12, -12), 2, 2, [0,1,2,3], 5
end
def update(section)
super(section) do
take(section, false)
end
if rand < 0.05
x = @x + rand(@w) - 7
y = @y + rand(@h) - 7
section.add_effect(Effect.new(x, y, :fx_Glow1, 3, 2, 6, [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0], 66))
end
end
def use(section, switch)
SB.player.stage_score += 1000
SB.stage.set_spec_taken
end
end