2018-01-07 14:19:35 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <math.h>
|
2018-01-09 13:22:10 +01:00
|
|
|
#include <time.h>
|
2018-01-07 14:19:35 +01:00
|
|
|
#include <SDL2/SDL.h>
|
2018-01-09 13:22:10 +01:00
|
|
|
#include <SDL2/SDL_image.h>
|
|
|
|
#include <SDL2/SDL_ttf.h>
|
|
|
|
|
|
|
|
#include "vector.h"
|
2018-01-07 14:19:35 +01:00
|
|
|
|
|
|
|
#ifndef __nullptr__
|
|
|
|
#define Nullptr(type) (type *)0
|
|
|
|
#endif // __nullptr__
|
|
|
|
|
|
|
|
void DrawFrame();
|
|
|
|
void INITIALIZE();
|
|
|
|
void QUIT();
|
|
|
|
void GAMELOOP();
|
|
|
|
void mousePress(SDL_MouseButtonEvent b);
|
2018-01-07 14:45:07 +01:00
|
|
|
void keyPress(SDL_KeyboardEvent b);
|
2018-01-08 00:45:32 +01:00
|
|
|
void windowChanged(SDL_WindowEvent b);
|
|
|
|
void toggleFullscreen();
|
2018-01-07 14:19:35 +01:00
|
|
|
|
|
|
|
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;
|
2018-01-08 00:45:32 +01:00
|
|
|
bool running = true, fullscreen = false;
|
2018-01-07 14:19:35 +01:00
|
|
|
|
|
|
|
int main(int argc, char * args[]){
|
2018-01-09 14:36:57 +01:00
|
|
|
system("bhi.exe");
|
2018-01-07 14:19:35 +01:00
|
|
|
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;
|
2018-01-07 14:45:07 +01:00
|
|
|
else keyPress(event.key);
|
2018-01-07 14:19:35 +01:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
mousePress(event.button);
|
|
|
|
break;
|
2018-01-08 00:45:32 +01:00
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
windowChanged(event.window);
|
|
|
|
break;
|
2018-01-07 14:19:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-07 14:45:07 +01:00
|
|
|
void keyPress(SDL_KeyboardEvent b){ // Debug prop
|
|
|
|
printf("Key pressed: ID is %d\n", b.keysym.scancode);
|
2018-01-08 00:45:32 +01:00
|
|
|
if (b.keysym.scancode == SDL_SCANCODE_F11) {
|
|
|
|
toggleFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleFullscreen(){
|
|
|
|
if (fullscreen) {
|
|
|
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
|
|
} else {
|
|
|
|
SDL_SetWindowFullscreen(window, 0);
|
|
|
|
}
|
|
|
|
fullscreen = !fullscreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowChanged(SDL_WindowEvent b){ // Debug prop
|
|
|
|
switch (b.event) {
|
|
|
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
|
|
|
printf("Window was resized to (%d|%d)!\n", event.window.data1, event.window.data2);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-07 14:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2018-01-09 14:36:57 +01:00
|
|
|
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
2018-01-08 00:45:32 +01:00
|
|
|
SDL_SetWindowResizable(window, true);
|
2018-01-07 14:19:35 +01:00
|
|
|
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);
|
2018-01-07 14:45:07 +01:00
|
|
|
// IMG_Quit();
|
2018-01-07 14:19:35 +01:00
|
|
|
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 */
|