-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.rb
55 lines (44 loc) · 1.25 KB
/
ball.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
class Ball
attr_reader :shape
attr_accessor :x
attr_accessor :y
attr_reader :size
def initialize(window, x, y, size, direc)
@size = size
#Tamaina desberdineko bolak sortuko dira
if @size == 1
@animation = Gosu::Image.new("img/b1.png")
elsif @size == 2
@animation = Gosu::Image.new("img/b2.png")
elsif @size == 3
@animation = Gosu::Image.new("img/b3.png")
else
@animation = Gosu::Image.new("img/b4.png")
end
#Fisikak ezartzeko body bat sortu beharko dugu
body = CP::Body.new(10, INFINITY)
body.p = CP::Vec2.new(x, y)
body.v = CP::Vec2.new(6*direc, -10)
#Shape-ak fisikak emango dizkigu bolentzako
@shape = CP::Shape::Circle.new(body,
@animation.width / 2,
CP::Vec2.new(0,0))
@shape.e = 1
@shape.u = 0
@shape.group = 4
@shape.collision_type = :ball
#Fisikak jokoan sartuko ditugu
window.space.add_body(body)
window.space.add_shape(@shape)
end
def x
@shape.body.p.x
end
def y
@shape.body.p.y
end
#Funtzio honek bolak errendatuko ditu jokoan
def draw
@animation.draw(@shape.body.p.x - @animation.width / 2.0, @shape.body.p.y - @animation.height / 2.0, 2)
end
end