Game Development Reference
In-Depth Information
# 04-prototype-optimized/entities/bullet.rb
class Bullet
# ...
def update
# ...
fly_speed = Game . adjust_speed( @speed )
fly_distance = ( Gosu . milliseconds - @fired_at ) * 0.001 * fly_speed
@x , @y = point_at_distance(fly_distance)
# ...
end
# ...
end
# 04-prototype-optimized/entities/camera.rb
class Camera
# ...
def update
shift = Game . adjust_speed( @target . speed)
@x += shift if @x < @target . x - $window . width / 4
@x -= shift if @x > @target . x + $window . width / 4
@y += shift if @y < @target . y - $window . height / 4
@y -= shift if @y > @target . y + $window . height / 4
zoom_delta = @zoom > 0 ? 0.01 : 1.0
zoom_delta = Game . adjust_speed(zoom_delta)
# ...
end
# ...
end
There is one more trick to make the game playable even at very low FPS. You can
simulate such conditions by adding sleep 0.3 to GameWindow#draw method. At
that framerate game cursor is very unresponsive, so you may want to start showing native
mouse cursor when things get ugly, i.e. when update interval exceeds 200 milliseconds:
# 04-prototype-optimized/game_window.rb
class GameWindow < Gosu :: Window
# ...
def needs_cursor?
Game . update_interval > 200
end
# ...
end
Search WWH ::




Custom Search