Game Development Reference
In-Depth Information
_sprite =
Renderer::GetInstance()->CreateSprite(path);
_sprite->Position = _position;
_sprite->Rotation = _rotation;
_sprite->Scale = _scale;
auto texSz = _sprite->GetSize();
texSz.x /= 2.0f;
texSz.y /= 2.0f;
_sprite->Origin = texSz;
}
Most of the work done in this method involves copying over the current transform-
ation properties to the sprite, as well as setting the origin of the sprite to the centre
of the image. Now if everything is connected up properly you should be able to build
and run the game to see your player ship (which can be moved with the controls you
set) and enemies appearing from the right side of the screen every five seconds, un-
less you specified a different interval. The enemies should also move towards the
left side of the screen.
So the enemies move towards the player, and then pass right through. This is where
we need to add in a collision system to check when the enemies crash into the play-
er, and later on when the bullets hit the enemies.
Collision detection
A collision system manages all of the calculations required to add a basic level of
physics to your game by allowing objects to collide with each other and have some
gameplay or visual effect. The key role of the collision system is to determine if a
collision has occurred (collision detection). However, it may also be in charge of the
response to a collision, depending on the needs of the game. In some cases, that is
handled elsewhere and the collision system can be dedicated to detecting the colli-
sion and letting another system handle the response.
There are a lot of different ways to manage and run a collision system, but as usual
with games you just need to stick to whatever gets the job done to your require-
ments. In this case we're not going to go and implement fancy acceleration struc-
Search WWH ::




Custom Search