My timeline of text editors
I’ve been coding on and off since the beginning of the 90’s and along this journey I’ve been stumbling over quite a few editors and IDE:s. In this post I will go through some of them. It’s a selection of …
I’ve been coding on and off since the beginning of the 90’s and along this journey I’ve been stumbling over quite a few editors and IDE:s. In this post I will go through some of them. It’s a selection of …
Recently I have been doing a lot of researching for my new game. In order to develop a larger game, I really need to acquire as much knowledge beforehand as possible and avoid the most common pitfalls. I need a …
During my vacation I’ve been drawing pixel art for my next game and brainstormed around some basic game structure. Creating pixel graphics is consuming a lot of time. In round terms it takes at least 5 hours (for me, the …
When I’ve been building for different platforms in C++. I’ve experienced that there are no easy way to get the path to important directories. Each platform has it’s own code to get it’s own specific paths, and they are also …
While the project is in development phase it is very convenient to have all the assets laying around in folders. But when it’s time to distribute your game it doesn’t look as professional when everything is lying all over the …
Spacefight – Packing all the resources into one file – Part 10 Read more »
In software development there are different types of bugs. C++ is a hard typed language which makes it easy for the compiler to detect errors in the code. So if there is type error (int is not a float, or …
Spacefight – Gamecrash, memory leaks and frustration – Part 8 Read more »
Now the game is as far in the development phase and things are moving around on the screen! In order to put some logic into the game I’ll need some kind of a collision detection. I will use a very …
Spacefight – Things are moving, but do they collide? – Part 7 Read more »
All games contain loops of some sort. The most important loop in the game is simply called “game-loop”. This is a short example how it will run:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// Creates a vector of pointers to GameObjects AnimationLibrary* animLib = new AnimationLibrary(); animLib->init(); SoundLibrary* sndLib = new SoundLibrary(); sndLib->init(); std::vector<GameObject*> gameObjectList; gameObjectList.push_back(new Enemy(400, 50, animLib, sndLib)); gameObjectList.push_back(new Player(400, 400, animLib, sndLib)); // Init all the objects before running them for(std::vector<GameObject*>::iterator it = gameObjectList.begin(); it != gameObjectList.end(); it++){ (*it)->init(); // Loads graphics, sounds and other properties } SDL_Event event; bool gameIsRunning = false; while(gameIsRunning){ // Check if game is quitting, in that case, leave the loop while(SDL_PollEvent(&event)){ if(event.type == SDL_QUIT){ gameIsRunning = false; } } // Sort the gameObjectList std::sort(gameObjectList.begin(), gameObjectList.end(), mySorter); /* Iterate through the list of gameobjects. * Using C++11's auto here instead of the tedious declaration. */ for(auto it = gameObjectList.begin(); it != gameObjectList.end(); it++){ (*it)->listen(event); (*it)->update(gameObjectList); (*it)->draw(screen); // Screen is the framebuffer // passed to all objects. } Collision::collisionCheck(gameObjectList); // The collision detection // is a separate function // and topic itself. // MORE code here, removing and deleting dead objects // checking whether player is alive, any enemies left etc. SDL_Flip(screen); // Update the screen. SDL_Delay(1000/FPS); // Wait for a bit ~20ms } |
This is a short version of what is happening in the code. …
In the last post I made a GameObject class. Now it’s time to subclass from the GameObject class into an enemy. The enemy object will make use of the shared functionality in GameObject, like position, access to a shared AnimationLibrary …
Spacefight – Subclassing into enemies, player and other stuff – part 5 Read more »
A lot of objects in the game has a many things in common. They contain an Animationlibrary, a position on the screen, width and height. They also got common functions like: Listen Sends any event from the user’s keyboard/mouse/joystick to …