From 9b94a6cc15f942c7dd23b6f661a81e989f760aeb Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Sun, 7 Jan 2018 14:19:35 +0100 Subject: [PATCH] Initial commit with push --- .gitignore | 14 ++++++++ main.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ce7281 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +*.dll +*.depend +*.cbp +*.layout +sdl2-config +*.exclude +*.o +*.a +*.psd +*.exe diff --git a/main.c b/main.c new file mode 100644 index 0000000..0f90f0e --- /dev/null +++ b/main.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include + +#ifndef __nullptr__ +#define Nullptr(type) (type *)0 +#endif // __nullptr__ + +void DrawFrame(); +void INITIALIZE(); +void QUIT(); +void GAMELOOP(); +void mousePress(SDL_MouseButtonEvent b); +void mousePress(); + +const int width = 1600; // TODO: Fullscreen +const int height = 900; + +Uint8 * keystate; // TODO: export all this into scenery and enemy waves +SDL_Window * window; +SDL_Renderer * renderer; +SDL_Event event; +bool running = true; + +int main(int argc, char * args[]){ + INITIALIZE(); + while (running) { + GAMELOOP(); + DrawFrame(); + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + running = false; + break; + case SDL_KEYDOWN: + if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) running = false; + else keyPress(); + break; + case SDL_MOUSEBUTTONDOWN: + mousePress(event.button); + break; + } + } + } + QUIT(); + return 0; +} /* main */ + +void GAMELOOP() { + keystate = SDL_GetKeyboardState(NULL); +} /* GAMELOOP */ + +void mousePress(SDL_MouseButtonEvent b){ // Debug prop + if (b.button == SDL_BUTTON_LEFT) { + printf("Left mouse pressed...\n"); + } else if (b.button == SDL_BUTTON_RIGHT) { + printf("Right mouse pressed...\n"); + } else { + printf("Unknown mouse button pressed: %d\n", b.button); + } +} + +void keyPress(){ // Debug prop + +} + +void DrawFrame(){ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + + // Draw Game here + + SDL_RenderPresent(renderer); +} + +void INITIALIZE() { + srand(time(NULL)); + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); + else printf("SDL was successfully initialized!\n"); + + window = SDL_CreateWindow("Asteroids Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); + printf("Window was created!\n"); + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + printf("Renderer was created!\n"); +} /* INITIALIZE */ + +void QUIT(){ + printf("De-initializing started...\n"); + free(keystate); + //IMG_Quit(); + printf("Quitting SDL_IMG finished!\n"); + SDL_DestroyRenderer(renderer); + printf("De-initializing renderer finished!\n"); + SDL_DestroyWindow(window); + printf("De-initializing window finished!\n"); + SDL_Quit(); + printf("Quitting SDL finished!\n"); + printf("De-initializing finished!\n"); +} /* QUIT */