Initial commit with push

This commit is contained in:
Michael Chen 2018-01-07 14:19:35 +01:00
commit 9b94a6cc15
2 changed files with 115 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -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

101
main.c Normal file
View File

@ -0,0 +1,101 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#include <SDL2/SDL.h>
#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 */