Incursion is a single-player 2D shooting game. The player controls a tank trying to reach the exit while there are walls and boulders that block the tank, and enemies that attack the tank. This game requires an Xbox controller. Use the left joystick to move the tank and the right joystick to rotate the turret. Reach the exit on the top right corner to win. This is another project built using my own engine, using C++ and OpenGL.
Apart from the normal version, I also made a "text version" of the game, replacing all entities with text.
There are several things noticeable in the tank basic control.
First is the movement. Just like a tank in the real world, it cannot rotate itself while not moving around. So whenever the tank rotates, it has to move at the same time, making it feels more like a real vehicle.
Here is the control for the tank. As we can see when the tank rotates, it calls a function GetTurnedToward() to get the half-way direction of rotation. And the velocity is calculated based on current orientation and joystick magnitude, making sure that the tank rotates and moves at the same time.
Another feature of basic control is the control of the turret. The turret will rotate towards the direction of the right joystick in case there is a right joystick input. And when the right joystick is not pushed, the turret rotates together with the tank.
From the code above we can see how this works: when the tank is rotating(when the left joystick is rotating), the turret rotates as well. And when the right joystick is rotating, the turret turned towards the target orientation no matter what the current orientation is.
There is tile-based raycasting implemented so the enemies can sense the player tank.
Here is the function for tile-based 2D raycast. What it does is starting from the current position, try to figure out which tile it is going to hit next if the ray goes this way. Once it finds the next tile, it will find the exact position the ray touches the tile, then use this position as the new start position. Keep repeating this until the ray meets a solid tile or reach maximum distance.
There is a simple tile-based 2D physics that handles collisions between entities and collisions between solid tiles and entities.
Here is the map update and how the entity-vs-wall physics handled. All the entities have a disc collider and each tile has a square collider. So entity-vs-entity physics is just pushing two discs out of each other when intersected.
The way we handle entity-vs-wall is by checking all the eight tiles around the entity using the tile coordinates. If any of the tiles are solid as is intersecting with the entity, the entity will be pushed out of the square.
Control of tank and turret simulates real vehicle and feels good.
Text hitting effects look funny.
The architecture getting a little messy.
Too much redundant code. Should have more helper functions.
Have more helper functions and make the architecture better.
Add more enemies and items.