-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.rb
38 lines (31 loc) · 860 Bytes
/
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
class Ball
attr_accessor :x_coordinate, :y_coordinate, :z_coordinate,
:velocity_x, :velocity_y, :image
def initialize(x_coordinate, y_coordinate, z_coordinate)
@x_coordinate = x_coordinate
@y_coordinate = y_coordinate
@z_coordinate = z_coordinate
@velocity_x = 0
@velocity_y = -0.1
@image = Gosu::Image.new("images/ball.gif")
end
def update_position(time_elapsed)
self.x_coordinate = x_coordinate + velocity_x * time_elapsed
self.y_coordinate = y_coordinate + velocity_y * time_elapsed
end
def draw
image.draw(image_x_coordinate, image_y_coordinate, z_coordinate)
end
def image_width
image.width
end
def image_height
image.height
end
def image_x_coordinate
x_coordinate - image_width / 2
end
def image_y_coordinate
y_coordinate - image_height / 2
end
end