Today was a suprisingly productive day. Not only productive but everything I tried to do worked almost instantly which is something I’m not usually used to with programming. While this applies mostly to the maze game I was working on with a friend today, it is also true for my Devember project Space Invaders. I cleaned up my code a little bit, it’s not yet using classes and headers but at least everything is structured in different functions for now. I also implemented the SDLimage lib and can now use PNGs instead of BMPs. I also succeeded in putting several enemies on the screen so that the screen looks like this right now:
I already know that I won’t have to much time tomorrow and on Friday but I’m hoping to implement enemie-movement and maybe even the shooting and damage before the weekend. Once all the basic functionality is done I will try to add the twist I’ve come up with.
This is what my main function looks like at the moment:
int main (int argc, char* args[]) { shipPos.x = (SCREEN_WIDTH/2); shipPos.y = (SCREEN_HEIGHT/2); enemiePos.x = 50; enemiePos.y = 50; //Start SDL and create window if (!init()) { printf("Initialization failes! \n"); } else { //Load media if (!loadMedia()) { printf("Failed to load media! \n"); } else { //(what, where, destination, where) SDL_BlitSurface(playerShip, NULL, surface, &shipPos); for (int i = 1; i < sizeof(enemies) + 1; i++) { enemiePos.x = 50 + i*50; //enemiePos.y = 50; SDL_BlitSurface(enemieShip, NULL, surface, &enemiePos); } // Main loop while (!quit) { while (SDL_PollEvent(&event) != 0) { //X is pressed by user if (event.type == SDL_QUIT) { quit = true; } //User presses a key else if (event.type == SDL_KEYDOWN) { //move players position based on key press switch (event.key.keysym.sym) { case SDLK_UP: shipPos.y -= 1; break; case SDLK_DOWN: shipPos.y += 1; break; case SDLK_LEFT: shipPos.x -= 1; break; case SDLK_RIGHT: shipPos.x += 1; break; //default: //break; } } } //Update ships position (what, where, destination, where) SDL_BlitSurface(playerShip, NULL, surface, &shipPos); //update window SDL_UpdateWindowSurface(window); } } } //Close SDL close(); return 0; }