FileLogo

App Screenshot

Cosmic Intruders (SDL2, Windows)

This is also a beginner project, a Space Invaders clone. The lesson I aim for is handling many many objects and events the c++ way. When you hit an alien it explodes and dissolves into four rotating fragments that fall down. When any of those fragments hit a barrier, that particular brick again bursts into four pieces that rotate while falling down. Those fragments don't destroy your spaceship, but the fact they are on screen and come at you adds some excitement.

The basic pattern you need to escalate complexity like that is amazingly powerful:
     Thing *things[CRAZY_BIG_NUMBER_OF_OBJECTS];//Instances are pointers
     aliens alienInstance[NUMBER_OF_ALIENS];//for example
     for (i = 0; i      for (i = 0; i < CRAZY_BIG_NUMBER_OF_OBJECTS; i++) things[i]->initiate(i); //Everything initiated in one single call before entering game loop. BODACIOUS.
     //LATER IN GAME LOOP
     for (i = 0; i < CRAZY_BIG_NUMBER_OF_OBJECTS; i++) things[i]->update(i); //Update method, again one single call for everything. WICKED.
The trick being that Thing has initiate() and update() as pure virtuals:
     virtual void initiate(int i) = 0;
     virtual void update(int i) = 0;
And those are defined by each subclass differently, e.g.:
     class aliens : public Thing{
     virtual void initiate(int i) {...whatever...};}
I made the sound effects myself using Audacity, distorting generated tones until it fits. And the different sprites I made as well, to avoid monotony when leveling up. That is only if you manage to level up without crashing, unfortunately it's not stable yet. There's a bug that shuts the whole thing down when you move the mouse inbetween screens, even though my intention is to have blocked SDL from listening to mouse movements in these cases. If you know why, please tell me where the bug is. Please don't attempt to move the mouse when a new level starts before the aliens have started moving, too.

App Screenshot
Download Game and Code 


Copyright © 2016-2018 FileNewOpen.com