-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenemy.rb
53 lines (48 loc) · 1.08 KB
/
enemy.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
class Enemy
attr_reader :x, :y, :window, :player
def initialize(animation, window, player)
@animation = animation
@x = rand * 1280
@y = rand * 960
@player = player
@window = window
end
def draw
img = @animation[Gosu::milliseconds / 100 % @animation.size];
img.draw(@x - img.width / 2.0, @y - img.height / 2.0,
ZOrder::Enemys, 1, 1)
attack_player
end
def attack_player
if $timer > 75 && Gosu::distance(@x, @y, @player.x, @player.y) < 200 && $timer % 5 == 0 then
dmg = 1
case
when $level < 2
dmg +=1
when $level < 5
dmg +=2
when $level < 10
dmg +=3
when $level < 20
dmg +=4
when $level < 30
dmg +=8
when $level < 50
dmg +=15
when $level < 60
dmg +=25
when $level < 75
dmg +=50
when $level < 90
dmg +=75
else
dmg += rand(75..500)
end
$score -= dmg
@punch = Gosu::Sample.new(window, "assets/punch.mp3").play
true
else
false
end
end
end