Game Development Reference
In-Depth Information
1.
Tank will randomly change direction every turn_time interval, which is
between 2 and 5 seconds.
2.
Tank will choose to drive (80% chance) or to stand still (20% chance).
3.
If tank chose to drive, it will keep driving for drive_time , which is between 1
and 5 seconds.
4.
Same goes with waiting, but wait_time (0.5 - 2 seconds) will be used for
duration.
5.
Direction changes and driving / waiting are independent.
This will make an impression that our tank is driving around looking for enemies.
Tank Fighting State
When tank finally sees an opponent, it will start fighting. Fighting motion should be more
energetic than roaming, we will need a sharper set of choices in change_direction
among other things.
08-ai/entities/components/ai/tank_fighting_state.rb
1 class TankFightingState < TankMotionState
2 def initialize (object, vision)
3 super
4 @object = object
5 @vision = vision
6 end
7
8 def update
9 change_direction if should_change_direction?
10 if substate_expired?
11 rand > 0.2 ? drive : wait
12 end
13 end
14
15 def change_direction
16 change = case rand ( 0. . 100 )
17 when 0. . 20
18 -45
19 when 20. . 40
20 45
21 when 40. . 60
22 90
23 when 60. . 80
24 -90
25 when 80. . 90
26
135
Search WWH ::




Custom Search