-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.rb
More file actions
69 lines (57 loc) · 1009 Bytes
/
Player.rb
File metadata and controls
69 lines (57 loc) · 1009 Bytes
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
68
69
class Player
attr_reader :score
def initialize(id)
if id == 1
@image = Gosu::Image.new("media/Green.bmp")
else
@image = Gosu::Image.new("media/Redsus.bmp")
end
@x = @y = @vel_x = @vel_y = @angle = 0.0
@score = 0
@playerID = id
end
def warp(x,y)
@x, @y = x,y
end
def turn_left
@angle -= 4.5
end
def turn_right
@angle += 4.5
end
def accelereate
@vel_x += Gosu.offset_x(@angle,0.5)
@vel_y += Gosu.offset_y(@angle,0.5)
end
def move
@x += @vel_x
@y += @vel_y
@x %= 1024
@y %= 720
@vel_x *= 0.95
@vel_y *= 0.95
end
def draw
@image.draw_rot(@x,@y,1,@angle)
end
def getID
return @playerID
end
def score
@score
end
def stop
@vel_x = 0
@vel_y = 0
end
def collect_stars(stars)
stars.reject! do |star|
if Gosu.distance(@x,@y,star.x,star.y) < 35
@score +=10
true
else
false
end
end
end
end