Game Development Reference
In-Depth Information
end
if @object . speed_modifier < 1.5 && health > 50
required << TankSpeedPowerup
end
if health < 100
required << RepairPowerup
end
if health < 190
required << HealthPowerup
end
required
end
def change_direction
closest_powerup = @vision . closest_powerup(
* required_powerups)
if closest_powerup
@seeking_powerup = true
angle = Utils . angle_between(
@object . x, @object . y,
closest_powerup . x, closest_powerup . y)
@object . physics . change_direction(
angle - angle % 45 )
else
@seeking_powerup = false
# ... choose random direction
end
@changed_direction_at = Gosu . milliseconds
@will_keep_direction_for = turn_time
end
# ...
def turn_time
if @seeking_powerup
rand ( 100. . 300 )
else
rand ( 1000. . 3000 )
end
end
end
It is simple as that, and our AI tanks are now getting buffed on their spare time.
Search WWH ::




Custom Search