-
Notifications
You must be signed in to change notification settings - Fork 0
/
harpoon.rb
60 lines (48 loc) · 1.47 KB
/
harpoon.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
class Harpoon
attr_reader :shape
attr_reader :x
attr_reader :y
attr_reader :width
attr_reader :height
def initialize(window, x)
@x = x
@y = 450
@width = 16
@height = 321
@img = Gosu::Image.load_tiles("img/harpoon.png", @width, @height)
@imgNum = 0
@imgNumMax = 19
#Kolisioak lortzeko body bat sortu behar dugu lehenengo
body = CP::Body::new(1, INFINITY)
body.p = CP::Vec2.new(@x, @y)
body.v = CP::Vec2.new(0, -15)
body.f = CP::Vec2.new(0, -1)
#Kolisioentzako bektore karratua
shape_verts = [
CP::Vec2.new(-(@width / 2.0), (@height / 2.0)),
CP::Vec2.new((@width / 2.0), (@height / 2.0)),
CP::Vec2.new((@width / 2.0), -(@height / 2.0)),
CP::Vec2.new(-(@width / 2.0), -(@height / 2.0)),
]
#Kolisioak shape batekin kontrolatuko dira, body-ra itsatsita dagoena
#Aurreko bektoreak kolisioaren limiteak izango dira
@shape = CP::Shape::Poly.new(body, shape_verts, CP::Vec2.new(0,0))
@shape.e = 0
@shape.u = 0
@shape.group = 3
@shape.layers = 1
@shape.collision_type = :harpoon
#Body-a eta shape-a jokoan sartuko ditugu
window.space.add_body(body)
window.space.add_shape(@shape)
end
def draw
@img[@imgNum/10].draw(@shape.body.p.x - (@width / 2), @shape.body.p.y - (@height / 2), 2)
end
def update
@imgNum += 2
if @imgNum > @imgNumMax
@imgNum = 0
end
end
end