Game Development Reference
In-Depth Information
class TankPhysics < Component
# ...
def change_direction (new_direction)
change = (new_direction - object . direction + 360 ) % 360
change = 360 - change if change > 180
if change > 90
@speed = 0
elsif change > 45
@speed *= 0.33
elsif change > 0
@speed *= 0.66
end
object . direction = new_direction
end
# ...
end
Implementing Terrain Speed Penalties
Now, let's see how can we make terrain influence our movement. It sounds reasonable for
TankPhysics to consult with Map about speed penalty of current tile:
# 06-physics/entities/map.rb
class Map
# ...
def movement_penalty (x, y)
tile = tile_at(x, y)
case tile
when @sand
0.33
else
0
end
end
# ...
end
# 06-physics/entities/components/tank_physics.rb
class TankPhysics < Component
# ...
def update
# ...
speed = apply_movement_penalty( @speed )
shift = Utils . adjust_speed(speed)
# ...
end
Search WWH ::




Custom Search