110 lines
3.0 KiB
C
110 lines
3.0 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
#include <ncurses.h>
|
|
#include <unistd.h>
|
|
#include <termios.h>
|
|
#include <limits.h>
|
|
#include <time.h>
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_image.h>
|
|
|
|
#include "hash.h"
|
|
#include "structure.h"
|
|
#include "base.h"
|
|
#include "move.h"
|
|
#include "triangles.h"
|
|
#include "entities.h"
|
|
#include "display.h"
|
|
#include "generation.h"
|
|
|
|
double sim_time ;
|
|
|
|
int main(int argc, char** argv) {
|
|
srand(time(NULL));
|
|
|
|
//-------------------------------------------------------------------------------//
|
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
|
printf("error initializing SDL: %s\n", SDL_GetError());
|
|
}
|
|
SDL_Window* win = SDL_CreateWindow("Game",
|
|
SDL_WINDOWPOS_CENTERED,
|
|
SDL_WINDOWPOS_CENTERED,
|
|
1500, 1000, 0);
|
|
|
|
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
|
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
|
|
SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_BLEND);
|
|
|
|
//-------------------------------------------------------------------------------//
|
|
|
|
if(SDL_Init(SDL_INIT_AUDIO)) {
|
|
fprintf(stderr, "cannot initialize audio");
|
|
exit(1);
|
|
}
|
|
SDL_SetRelativeMouseMode(true) ;
|
|
|
|
/* -------------------------------------------------------- */
|
|
int fps = 60 ;
|
|
int interval = 1000000/fps ;
|
|
double intervalf = 1.0/((double)(fps)) ;
|
|
|
|
init_csts() ;
|
|
init_hashtbl() ;
|
|
init_draworder() ;
|
|
trInit();
|
|
parse_rooms(5);
|
|
import_digits(rend) ;
|
|
import_letters(rend) ;
|
|
sim_time = 0.0 ;
|
|
clock_t origin = clock();
|
|
clock_t finish = clock();
|
|
|
|
clock_t entstart = clock();
|
|
clock_t entend = clock();
|
|
float delta;
|
|
while(true) {
|
|
resetRenderer(rend) ;
|
|
|
|
origin = clock();
|
|
SDL_SetRenderDrawColor(rend, 255, 255, 255, SDL_ALPHA_OPAQUE) ;
|
|
entend = clock();
|
|
playerActions(((float)entend - (float)entstart)/CLOCKS_PER_SEC) ;
|
|
generate_nearby_chunks(1);
|
|
|
|
entend = clock();
|
|
update_entities(((float)entend - (float)entstart)/CLOCKS_PER_SEC);
|
|
entstart = clock();
|
|
|
|
drawCurrentRoom(rend);
|
|
drawData(rend) ;
|
|
drawHPbar(rend);
|
|
finish = clock();
|
|
|
|
fade_dmg = max(fade_dmg-5, 0);
|
|
|
|
delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC;
|
|
drawNumberToRenderer(rend, digits, (int)(1.0f/delta), 720, 60, 75/2, 105/2, 0);
|
|
drawNumberToRenderer(rend, digits, (int)(10*sim_time), 720, 110, 75/2, 105/2, 0);
|
|
drawNumberToRenderer(rend, digits, coins, 1500/2-55, 1000 - 70, 75/3, 105/3, 0);
|
|
updateRenderer(rend) ;
|
|
sim_time += delta + intervalf ;
|
|
usleep(interval) ;
|
|
}
|
|
free_digits(digits) ;
|
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
SDL_DestroyRenderer(rend);
|
|
SDL_DestroyWindow(win);
|
|
SDL_Quit();
|
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
printf("Done\n") ;
|
|
|
|
return 0;
|
|
} |