1
1
Fork 0
Browse Source

demo

emscriptem
alistair 3 years ago
parent
commit
11aa5ea2f9
  1. 2
      c-colours
  2. 2
      src/draw.c
  3. 8
      src/game.c
  4. 30
      src/main.c

2
c-colours

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit ebf612394a92e9f697ed56c55fc236cb72b511c7
Subproject commit fbf7c2522688fbf4d7f2fef852f34fbffe602ef6

2
src/draw.c

@ -728,6 +728,7 @@ void redraw_buffer(SDL_Renderer * ren) { @@ -728,6 +728,7 @@ void redraw_buffer(SDL_Renderer * ren) {
}
#else
update_viewport(player.physics);
viewport_pos.x += SDL_GetTicks() / 3;
#endif
static struct timespec last = {};
@ -784,6 +785,7 @@ void redraw_buffer(SDL_Renderer * ren) { @@ -784,6 +785,7 @@ void redraw_buffer(SDL_Renderer * ren) {
lplayer.colliding);
draw_collision_poly(ren, &lplayer);
draw_forces(ren, &lplayer);
fprintf(stdout, "draw call");
if (game_paused) {
SDL_Rect r = {.x = 0, .y = 0, .w = width, .h = height};

8
src/game.c

@ -1259,17 +1259,19 @@ void advance_thing(Body * thing) { @@ -1259,17 +1259,19 @@ void advance_thing(Body * thing) {
// printf("delta: %f\n", time_delta);
if (time_delta > 19) {
printf("ERROR too slow: %f\n", time_delta);
#ifndef EMSCRIPTEN
time_delta = 19;
#endif
quality--;
}
#ifndef EMSCRIPTEN
if (time_delta < MIN_PHYSICS_STEP) {
#ifndef EMSCRIPTEN
SDL_Delay(MIN_PHYSICS_STEP);
#endif
advance_thing(thing);
return;
}
#endif
thing->last_advance_time = now;
// collisions
@ -1764,7 +1766,7 @@ int step(void) { @@ -1764,7 +1766,7 @@ int step(void) {
static int first_run = 0;
if (!first_run) {
start_audio();
// play_game_sound(game_sounds.background, -1, BC_MUSIC);
play_game_sound(game_sounds.background, -1, BC_MUSIC);
first_run = 1;
game_paused = 1;
}

30
src/main.c

@ -47,7 +47,7 @@ struct SDL_Window* make_window(void) { @@ -47,7 +47,7 @@ struct SDL_Window* make_window(void) {
return SDL_CreateWindow("space_game",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1000, 1000,
1920, 1080,
SDL_WINDOW_SHOWN);
#endif
}
@ -60,7 +60,7 @@ void redraw(struct SDL_Renderer * ren) { @@ -60,7 +60,7 @@ void redraw(struct SDL_Renderer * ren) {
}
int physics_loop(void *ptr) {
game_paused = 1;
game_paused = 0;
while (1) {
if (step()) {
// display end level screen
@ -87,14 +87,12 @@ int physics_loop(void *ptr) { @@ -87,14 +87,12 @@ int physics_loop(void *ptr) {
}
void mainloop(void *ren) {
step();
printf("main loop\n");
if (!in_game) {
draw_end_screen(ren);
} else {
redraw(ren);
}
}
int game(void) {
@ -152,14 +150,13 @@ int game(void) { @@ -152,14 +150,13 @@ int game(void) {
if (eee)
printf("startgame(): %s\n", eee), SDL_ClearError();
#ifndef EMSCRIPTEN
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg(mainloop, ren, -1, 1);
#else
SDL_Thread *physics_thread;
physics_thread = SDL_CreateThread(physics_loop, "physics", (void *)ren);
#else
emscripten_set_main_loop_arg(mainloop, ren, -1, 1/*block*/);
#endif
int count = 0;
int close = 0;
@ -189,14 +186,15 @@ emscripten_set_main_loop_arg(mainloop, ren, -1, 1/*block*/); @@ -189,14 +186,15 @@ emscripten_set_main_loop_arg(mainloop, ren, -1, 1/*block*/);
}
/* Redraw Screen */
#ifdef __EMSCRIPTEN__
step();
if (!in_game) {
draw_end_screen(ren);
} else {
redraw(ren);
printf("step loop\n");
/*
if (step()) {
// display end level screen
in_game = false;
next_level();
in_game = true;
}
*/
#endif
}
}

Loading…
Cancel
Save