Skip to content

luludak/GalaxyInvaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Galaxy Invaders

GalaxyInvaders

This is the implementation of the Space Invaders, related to an assignment of an interview process. It is a full-game implementation, with different enemies, game levels increasing in difficulty. The game also allows parameterization via the configuration file.

The Game

Tha user tries to eliminate all the alien armadas that is faced against. This is done by firing rockets against the aliens. The aliens also throw bombs against the user. If the user eliminates all the aliens armada, a new, more powerful arises (and difficulty level becomes higher), increasing in speed, more difficult ("zombie") enemies and probability of throwing bombs.

Game interactions are implemented exactly as described in assignment specification. One important deviation, is the "zombie" alien. This is a Type 1 alien having more than 1 life, but when it is damaged and holds its last life, it turns into a Type 2 enemy. I did this in order to increase an enemy diversity and add some dramatization to the game.

Setup

This project is for DEMONSTRATION purposes only, as the small game engine provided for it to run is proprietary and was NOT included in the release. I might implement my own at some point once time allows, so that you can actually compile and play the project. I used g++ compiler (developed on Mac OS X) and SDL. The makefile was used to setup and compile the project.

Development

More specifically, the game assets are split into respective Model classes (Alien, AlienArmada, etc), containing traits and behaviour, decoupled of business logic and view rendering.

Business logic is also separated in different Controller classes (GamePhysics, GameState), while also configuration is separately handled with another manager class and is loaded via a separate file. Any output is also written to an external file.

The game View is handled in EngineMain()'s game loop, but in a decoupled manner from business logic also utilized in it. This way, an MVC pattern is defined, based on an OOP-oriented approach.

In total, I tried to refine the code, comment it well and clarify my design and development decisions extensively.

Resources Management

In order to achieve users management, several decisions are made regarding memory utilization, caching and branch prediction. For the alien armada, an array of static size is selected to be used (which stores the data sequentially in memory, enabling better cache hits). Also, the armada is initialized ONLY once, and the traits are handled in order to indicate an enemy is dead or the whole armada is dead, thus reviving it. This way, memory is preserved.

Another important aspect for memory efficiency, is the choice for the player to fire only if there is no other rocket in the scene, and for the aliens, to throw a rocket only if there is not one already active. This allows the handling of the rockets just by some simple coordinates (x,y) integer variables. If I had to support multiple rockets/bombs, I would have to utilize a dynamic structure (such as a vector) and perform addition/deletion operations of assets on it, decreasing in memory efficiency and hurting cache usage. By observation, the original game seems to follow a similar pattern, and User Experience does not seem degraded.

In addition, a minimum amount of branches was used in code, considering there is no branch prediction. As another important aspect, I tried to set the conditional statement operations in an order that will enable good short-circuiting. For instance:

if (rocketY != 0 && EnginePhysics::checkIfSpritesCollide(make_pair(rocketX, rocketY), alien.getCoordinates())) {}

In his code, the check of the rocketY variable will prevent the much more complex execution of the collision check (containing internally more branches) from execute.

Finally, I could possibly have done some additional tricks to save resources, such as reserving the rightmost/leftmost alive alien for the checks on the boundaries. The same could be done when checking for rockets and bombs collision check, checking only in that column for aliens/the player. I have not added them to my implementation as time does not allow at this point, but this would be the next steps to optimize it further, given the chance.

About

A "space invaders"-style game.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published