-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojectile.rb
49 lines (44 loc) · 1.17 KB
/
projectile.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
class Projectile
attr_accessor :enemy_timer, :special
def initialize(window, playerx, playery, playerangle, special = false)
@special = special
@beep = Gosu::Sample.new(window, "assets/coin_sound.wav")
@fire = Gosu::Sample.new(window, "assets/hadouken.mp3").play
@image = Gosu::Image.new(window, ["assets/hadouken.png", "assets/hadouken-red.png"].sample)
@image = Gosu::Image.new(window, "assets/hadouken-green.png") if @special
@x = playerx
@y = playery
@angle = playerangle
@vel_x = 0
@vel_y = 0
@enemy_timer = $timer if @special
end
def accelerate
@vel_x += Gosu::offset_x(@angle, 0.5)
@vel_y += Gosu::offset_y(@angle, 0.5)
end
def move
@x += @vel_x * 2
@y += @vel_y * 2
if @special
@x %= 1280
@y %= 960
end
end
def draw
@image.draw_rot(@x, @y, ZOrder::Projectile, @angle)
self.accelerate
end
def collect_enemies(enemies, projectiles)
enemies.reject! do |enemy|
if Gosu::distance(@x, @y, enemy.x, enemy.y) < 200 then
$score += 10
@beep.play
projectiles.delete self unless @special
true
else
false
end
end
end
end