Class: Spacewar::Player
- Inherits:
-
Chingu::GameObject
- Object
- Chingu::GameObject
- Spacewar::Player
- Defined in:
- lib/spacewar/spacewar.rb
Instance Method Summary collapse
- #accelerate ⇒ Object
-
#initialize(input, options = {}) ⇒ Player
constructor
A new instance of Player.
- #turn_left ⇒ Object
- #turn_right ⇒ Object
- #update ⇒ Object
Methods inherited from Chingu::GameObject
Constructor Details
#initialize(input, options = {}) ⇒ Player
Returns a new instance of Player.
131 132 133 134 135 136 |
# File 'lib/spacewar/spacewar.rb', line 131 def initialize(input, ={}) super() @image = Image[[:image]] self.input = input self.max_velocity = 1 end |
Instance Method Details
#accelerate ⇒ Object
138 139 140 141 |
# File 'lib/spacewar/spacewar.rb', line 138 def accelerate self.velocity_x += Gosu::offset_x(self.angle, 0.5) * self.max_velocity self.velocity_y += Gosu::offset_y(self.angle, 0.5) * self.max_velocity end |
#turn_left ⇒ Object
148 149 150 151 |
# File 'lib/spacewar/spacewar.rb', line 148 def turn_left # The same can be achieved without trait 'effect' as: self.angle -= 4.5 rotate(-4.5) end |
#turn_right ⇒ Object
143 144 145 146 |
# File 'lib/spacewar/spacewar.rb', line 143 def turn_right # The same can be achieved without trait 'effect' as: self.angle += 4.5 rotate(4.5) end |
#update ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/spacewar/spacewar.rb', line 153 def update self.velocity_x *= 0.99 # dampen the movement self.velocity_y *= 0.99 @x %= $window.width # wrap around the screen @y %= $window.height end |