1
1
Fork 0
Browse Source

pause at end of level

emscriptem
alistair 4 years ago
parent
commit
578ac625f5
  1. 34
      src/draw.c
  2. 1
      src/draw.h
  3. 2
      src/game.c
  4. 2
      src/main.c

34
src/draw.c

@ -500,7 +500,8 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { @@ -500,7 +500,8 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) {
}
void draw_level_time(SDL_Renderer *ren, struct environment * e) {
void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) {
static SDL_Renderer *ren = NULL;
static TTF_Font* font = NULL;
if (!font) {
font = TTF_OpenFont("TerminusTTF.ttf", 18);
@ -509,20 +510,15 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) { @@ -509,20 +510,15 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) {
printf("%s\n", err);
}
}
int margin = height / 10;
SDL_Rect position = {.x = margin, .y = height - margin};
struct colour colour = e->colours.fg1;
int minutes = level_time / 60000;
float seconds = level_time * 0.001;
char time_string[250];
snprintf(time_string, 250, "%d:%.4f", minutes, seconds);
if (!ren) {
ren = rend;
}
SDL_Colour sdl_col = {colour.r, colour.g, colour.b, 255};
SDL_Rect position = {.x = pos.x, .y = pos.y};
SDL_SetRenderDrawColor(ren, colour.r, colour.g, colour.b, 255);
SDL_Surface *surf = TTF_RenderText_Solid(font, time_string, sdl_col);
SDL_Surface *surf = TTF_RenderText_Solid(font, text, sdl_col);
SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surf);
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
@ -533,6 +529,22 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) { @@ -533,6 +529,22 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) {
}
void draw_level_time(SDL_Renderer *ren, struct environment * e) {
int margin = height / 10;
Vect position = {.x = margin, .y = height - margin};
struct colour colour = e->colours.fg1;
int minutes = level_time / 60000;
float seconds = level_time * 0.001;
char time_string[250];
snprintf(time_string, 250, "%d:%.4f", minutes, seconds);
draw_text(ren, position, colour, time_string);
}
void redraw_buffer(SDL_Renderer * ren) {
static int mousex = 0;
static int mousey = 0;

1
src/draw.h

@ -35,6 +35,7 @@ extern Vect viewport_pos; @@ -35,6 +35,7 @@ extern Vect viewport_pos;
extern int width, height;
void draw_text(SDL_Renderer *ren, Vect pos, struct colour colour, char *text);
#endif

2
src/game.c

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "game.h"
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mutex.h>
@ -1530,6 +1531,7 @@ void step(int interval) { @@ -1530,6 +1531,7 @@ void step(int interval) {
if (player.physics->position.x > world.uniques_index[ROOM_W]->room
->floor.items[world.uniques_index[ROOM_W]->room->floor.numItems - 1]->position.x) {
SDL_Delay(1000);
next_level();
level_timer_update(true);
}

2
src/main.c

@ -40,7 +40,7 @@ void redraw(struct SDL_Renderer * ren) { @@ -40,7 +40,7 @@ void redraw(struct SDL_Renderer * ren) {
int physics_loop(void *ptr) {
while (true) {
step(10);
SDL_Delay(5);
SDL_Delay(10);
}
}

Loading…
Cancel
Save