forked from NoahMilam/ruby_shootemup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.rb
More file actions
67 lines (59 loc) · 1.07 KB
/
Copy pathenemy.rb
File metadata and controls
67 lines (59 loc) · 1.07 KB
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
class Enemy
attr_reader :x, :y, :w, :h
def initialize(window,iX,iY)
@image = Gosu::Image.new(window,'enemy1.png',false)
@x = iX
@y = iY
@moveShip = 3
@direction = "left"
@edgeLeft = iX - 50
@edgeDown = iY + 100
@edgeRight = @x
@edgeUp = @y
@shot_time = 0
end
def hitBox
hitbox_x = ((@x).to_i..(@x + @image.width).to_i).to_a
hitbox_y = ((@y).to_i..(@y + @image.height).to_i).to_a
{:x => hitbox_x, :y => hitbox_y}
end
def shoot_count
@shot_time += 1
if @shot_time == 100
@shot_time = 0
puts "im shooting"
end
end
def get_shot_time
return @shot_time
end
def move
if @direction == "left"
@x -= @moveShip
if @x <= @edgeLeft
@direction = "down"
end
end
if @direction == "right"
@x += @moveShip
if @x >= @edgeRight
@direction = "up"
end
end
if @direction == "up"
@y -= @moveShip
if @y <= @edgeUp
@direction = "left"
end
end
if @direction == "down"
@y += @moveShip
if @y >= @edgeDown
@direction = "right"
end
end
end
def draw
@image.draw(@x,@y,StageLayer)
end
end