forked from f3lixz/the-next-big-thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
84 lines (68 loc) · 1.69 KB
/
player.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require_relative "entity"
class Player < Entity
attr_reader :ssj
def initialize(window)
super(window, 0.0, 0.0, 0.0, @image = Gosu::Image.new(window, "resources/images/calle.png", false))
@vel_x = @vel_y = 0.0
@score = 0
@ssj = false
@spacePressed = false
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 accelerate
@vel_x += Gosu::offset_x(@angle, 0.5)
@vel_y += Gosu::offset_y(@angle, 0.5)
end
def toggleSSJ(window)
@ssj = !@ssj
@image = Gosu::Image.new(window, "resources/images/calle.png", false)
if @ssj then
@image = Gosu::Image.new(window, "resources/images/callessj.png", false)
end
@zzj = @ssj
end
def update
handle_input
@x += @vel_x
@y += @vel_y
@x %= 640
@y %= 480
@vel_x *= 0.95
@vel_y *= 0.95
end
def handle_input
if @window.button_down? Gosu::KbLeft or @window.button_down? Gosu::GpLeft then
turn_left
end
if @window.button_down? Gosu::KbRight or @window.button_down? Gosu::GpRight then
turn_right
end
if @window.button_down? Gosu::KbUp or @window.button_down? Gosu::GpButton0 then
accelerate
end
if @window.button_down? Gosu::KbSpace
if !@spacePressed
@spacePressed = true
bullet = Bullet.new(@window, @x, @y, @angle, @ssj)
@window.entities << bullet
end
end
if !@window.button_down? Gosu::KbSpace
@spacePressed = false
end
if @window.button_down? Gosu::KbEnter or @window.button_down? Gosu::KbReturn then
toggleSSJ(@window)
end
end
def draw
@image.draw_rot(@x, @y, 1, @angle)
end
end