Game Development Reference
In-Depth Information
Simulating Physics
To make the game more realistic, we will spice things up with some physics. This is the
feature set we are going to implement:
1.
Collision detection. Tank will bump into other objects - stationary tanks. Bullets will
not go through them either.
2.
Terrain effects. Tank will go fast on grass, slower on sand.
Adding Enemy Objects
It's boring to play alone, so we will make a quick change and spawn some stationary tanks
that will be deployed randomly around the map. They will be stationary in the beginning,
but we will still need a dummy AI class to replace PlayerInput :
06-physics/entities/components/ai_input.rb
1 class AiInput < Component
2 def control (obj)
3 self . object = obj
4 end
5 end
A quick and dirty way to spawn some tanks would be when initializing PlayState :
class PlayState < GameState
# ...
def initialize
@map = Map . new
@camera = Camera . new
@object_pool = ObjectPool . new( @map )
@tank = Tank . new( @object_pool , PlayerInput . new( @camera ))
@camera . target = @tank
# ...
50. times do
Tank . new( @object_pool , AiInput . new)
end
end
Search WWH ::




Custom Search