Game Development Reference
In-Depth Information
We
have
to
add @speed_modifier to Tank class
and
use
it
in
TankPhysics#update when calculating movement distance.
# 11-powerups/entities/tank.rb
class Tank < GameObject
# ...
attr_accessor :speed_modifier
# ...
def reset_modifiers
# ...
@speed_modifier = 1
end
# ...
end
# 11-powerups/entities/components/tank_physics.rb
class TankPhysics < Component
# ...
def update
# ...
new_x, new_y = x, y
speed = apply_movement_penalty( @speed )
shift = Utils . adjust_speed(speed) * object . speed_modifier
# ...
end
# ...
end
Camera#update has also refer to Tank#speed_modifier , otherwise the operator
will fail to catch up and camera will be lagging behind.
class Camera
# ...
def update
# ...
shift = Utils . adjust_speed(
@target . physics . speed) . floor *
@target . speed_modifier + 1
# ...
end
# ...
end
Search WWH ::




Custom Search