|
|
|
@ -8,8 +8,6 @@
@@ -8,8 +8,6 @@
|
|
|
|
|
Vect viewport_pos; |
|
|
|
|
int width, height; |
|
|
|
|
|
|
|
|
|
bool high_contrast_mode = 0; |
|
|
|
|
|
|
|
|
|
/* generic rendering functions */ |
|
|
|
|
int MAX_ONSCREEN_OBJECTS = 99; |
|
|
|
|
|
|
|
|
@ -485,7 +483,7 @@ void draw_environment(SDL_Renderer * ren, const struct environment *scene) {
@@ -485,7 +483,7 @@ void draw_environment(SDL_Renderer * ren, const struct environment *scene) {
|
|
|
|
|
|
|
|
|
|
int k = 0; |
|
|
|
|
// printf("from 0 to (room tiles) %d - 1, res %d width %d\n", E_ROOM_TILES, E_ROOM_RES, E_ROOM_WIDTH);
|
|
|
|
|
for (int i = 0; i < E_ROOM_TILES - 1; i++) { |
|
|
|
|
for (int i = 0; i < E_ROOM_TILES - 2; i++) { |
|
|
|
|
for (int j = 0; j < E_ROOM_RES; j++) { |
|
|
|
|
k++; |
|
|
|
|
Vect *left; |
|
|
|
@ -541,20 +539,38 @@ void draw_environment(SDL_Renderer * ren, const struct environment *scene) {
@@ -541,20 +539,38 @@ void draw_environment(SDL_Renderer * ren, const struct environment *scene) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static TTF_Font *fonts[3]; |
|
|
|
|
|
|
|
|
|
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", 22); |
|
|
|
|
void load_fonts(void) { |
|
|
|
|
fonts[0] = TTF_OpenFont("TerminusTTF.ttf", 22); |
|
|
|
|
fonts[1] = TTF_OpenFont("TerminusTTF.ttf", 66); |
|
|
|
|
const char *err = SDL_GetError(); |
|
|
|
|
if (err) { |
|
|
|
|
printf("%s\n", err); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!ren) { |
|
|
|
|
ren = rend; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void draw_text(SDL_Renderer *ren, enum FontNames fontID, Vect pos, struct colour colour, char *text) { |
|
|
|
|
|
|
|
|
|
TTF_Font *font = fonts[fontID]; |
|
|
|
|
|
|
|
|
|
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, text, sdl_col); |
|
|
|
|
|
|
|
|
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surf); |
|
|
|
|
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h); |
|
|
|
|
SDL_RenderCopy(ren, texture, NULL, &position); |
|
|
|
|
|
|
|
|
|
SDL_DestroyTexture(texture); |
|
|
|
|
SDL_FreeSurface(surf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void draw_text_default(SDL_Renderer *ren, Vect pos, struct colour colour, char *text) { |
|
|
|
|
TTF_Font* font = fonts[0]; |
|
|
|
|
|
|
|
|
|
SDL_Colour sdl_col = {colour.r, colour.g, colour.b, 255};
|
|
|
|
|
SDL_Rect position = {.x = pos.x, .y = pos.y}; |
|
|
|
@ -580,7 +596,7 @@ void draw_level_chooser_tbox(SDL_Renderer *ren) {
@@ -580,7 +596,7 @@ void draw_level_chooser_tbox(SDL_Renderer *ren) {
|
|
|
|
|
const struct environment *scene = get_scene_watch(); |
|
|
|
|
|
|
|
|
|
Vect pos = {.x= width - (width / 4), .y = height - (height / 10)}; |
|
|
|
|
draw_text(ren, pos, scene->colours.fg1, string); |
|
|
|
|
draw_text_default(ren, pos, scene->colours.fg1, string); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -621,12 +637,12 @@ int draw_end_screen(SDL_Renderer *ren) {
@@ -621,12 +637,12 @@ int draw_end_screen(SDL_Renderer *ren) {
|
|
|
|
|
char * end_str = "level over."; |
|
|
|
|
|
|
|
|
|
Vect position = {.x = width/4, .y = height / 4}; |
|
|
|
|
draw_text(ren, position, colour, end_str); |
|
|
|
|
draw_text_default(ren, position, colour, end_str); |
|
|
|
|
position.y += 60; |
|
|
|
|
|
|
|
|
|
char level_string[250]; |
|
|
|
|
snprintf(level_string, 250,"course: %d", level); |
|
|
|
|
draw_text(ren, position, colour, level_string); |
|
|
|
|
draw_text_default(ren, position, colour, level_string); |
|
|
|
|
position.y += 40; |
|
|
|
|
|
|
|
|
|
char fastest_time[250]; |
|
|
|
@ -634,14 +650,14 @@ int draw_end_screen(SDL_Renderer *ren) {
@@ -634,14 +650,14 @@ int draw_end_screen(SDL_Renderer *ren) {
|
|
|
|
|
seconds = fastest * 0.001; |
|
|
|
|
if (fastest > 0) { |
|
|
|
|
snprintf(fastest_time, 250, "old best time: %d:%.4f", minutes, seconds); |
|
|
|
|
draw_text(ren, position, colour, fastest_time); |
|
|
|
|
draw_text_default(ren, position, colour, fastest_time); |
|
|
|
|
position.y += 40; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
char qual_str[250]; |
|
|
|
|
snprintf(qual_str, 250, "physics quality: %d", quality); |
|
|
|
|
draw_text(ren, position, colour, qual_str); |
|
|
|
|
draw_text_default(ren, position, colour, qual_str); |
|
|
|
|
position.y += 40; |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
@ -669,15 +685,15 @@ int draw_end_screen(SDL_Renderer *ren) {
@@ -669,15 +685,15 @@ int draw_end_screen(SDL_Renderer *ren) {
|
|
|
|
|
snprintf(diff_str, 250, "DIFF: %.4f s", seconds); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
draw_text(ren, position2, colour, diff_str); |
|
|
|
|
draw_text_default(ren, position2, colour, diff_str); |
|
|
|
|
position2.y += 40; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
draw_text(ren, position2, colour, time_string); |
|
|
|
|
draw_text_default(ren, position2, colour, time_string); |
|
|
|
|
|
|
|
|
|
position.y += 200; |
|
|
|
|
char * ct_str = "press any key to continue"; |
|
|
|
|
draw_text(ren, position, colour, ct_str); |
|
|
|
|
draw_text_default(ren, position, colour, ct_str); |
|
|
|
|
|
|
|
|
|
SDL_RenderPresent(ren); |
|
|
|
|
return 0; |
|
|
|
@ -699,22 +715,36 @@ void draw_level_time(SDL_Renderer *ren, const struct environment * e) {
@@ -699,22 +715,36 @@ void draw_level_time(SDL_Renderer *ren, const struct environment * e) {
|
|
|
|
|
snprintf(level_string, 250,"course: %d", level); |
|
|
|
|
|
|
|
|
|
Vect position = {.x = margin, .y = height - margin}; |
|
|
|
|
draw_text(ren, position, colour, level_string); |
|
|
|
|
draw_text_default(ren, position, colour, level_string); |
|
|
|
|
position.y += 40; |
|
|
|
|
draw_text(ren, position, colour, time_string); |
|
|
|
|
draw_text_default(ren, position, colour, time_string); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void draw_pause_screen(SDL_Renderer *ren, struct environment *e) { |
|
|
|
|
|
|
|
|
|
char *game_name[] = { |
|
|
|
|
"A_s",
|
|
|
|
|
"Y_et",
|
|
|
|
|
"U_ntitled",
|
|
|
|
|
"G_ame",
|
|
|
|
|
"I_nvolving", |
|
|
|
|
"a",
|
|
|
|
|
"R_ock",
|
|
|
|
|
"W_ith",
|
|
|
|
|
"a",
|
|
|
|
|
"G_rappling",
|
|
|
|
|
"H_ook"}; |
|
|
|
|
|
|
|
|
|
char *te[] = { "GAME PAUSED.", |
|
|
|
|
"controls", |
|
|
|
|
"________", |
|
|
|
|
"pause/unpause: esc", |
|
|
|
|
"grapple and winch: left click", |
|
|
|
|
"grapple: right click", |
|
|
|
|
"grapple and pull: left click", |
|
|
|
|
"go to level: g", |
|
|
|
|
"mute/unmute: m", |
|
|
|
|
"high contrast mode: h", |
|
|
|
|
"quit: q" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -723,39 +753,53 @@ void draw_pause_screen(SDL_Renderer *ren, struct environment *e) {
@@ -723,39 +753,53 @@ void draw_pause_screen(SDL_Renderer *ren, struct environment *e) {
|
|
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(ren, bg.r, bg.g, bg.b, 255); |
|
|
|
|
int boxwidth = 360; |
|
|
|
|
int boxheight = 348; |
|
|
|
|
int boxheight = 388; |
|
|
|
|
int box_x = (2 * width / 3) - (boxwidth / 2); |
|
|
|
|
int box_y = (height - boxheight) / 2; |
|
|
|
|
SDL_Rect r = {.w = boxwidth, .h = boxheight, .x = box_x, .y = box_y}; |
|
|
|
|
SDL_RenderFillRect(ren, &r); |
|
|
|
|
|
|
|
|
|
Vect p = {.x = box_x + 10, .y = box_y + 10}; |
|
|
|
|
draw_text(ren, p, textc, te[0]); |
|
|
|
|
draw_text_default(ren, p, textc, te[0]); |
|
|
|
|
p.y += 60; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[1]); |
|
|
|
|
// SDL_GetScancodeName(input_map.goto_level);
|
|
|
|
|
draw_text_default(ren, p, textc, te[1]); |
|
|
|
|
p.y += 5; |
|
|
|
|
draw_text(ren, p, textc, te[2]); |
|
|
|
|
draw_text_default(ren, p, textc, te[2]); |
|
|
|
|
p.y += 35; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[3]); |
|
|
|
|
draw_text_default(ren, p, textc, te[3]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[4]); |
|
|
|
|
draw_text_default(ren, p, textc, te[4]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[5]); |
|
|
|
|
draw_text_default(ren, p, textc, te[5]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[6]); |
|
|
|
|
draw_text_default(ren, p, textc, te[6]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[7]); |
|
|
|
|
draw_text_default(ren, p, textc, te[7]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text(ren, p, textc, te[8]); |
|
|
|
|
draw_text_default(ren, p, textc, te[8]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
draw_text_default(ren, p, textc, te[9]); |
|
|
|
|
p.y += 40; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Vect p = {.x = box_x + 10, .y = box_y + 10};
|
|
|
|
|
p.x = width / 8; |
|
|
|
|
p.y = height / 9; |
|
|
|
|
int arlen = sizeof(game_name) / sizeof(game_name[0]); |
|
|
|
|
for (int i = 0; i < arlen; i ++) { |
|
|
|
|
draw_text(ren, LARGE, p, textc, game_name[i]); |
|
|
|
|
p.y += 75; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void redraw_buffer(SDL_Renderer * ren) { |
|
|
|
@ -796,7 +840,8 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -796,7 +840,8 @@ void redraw_buffer(SDL_Renderer * ren) {
|
|
|
|
|
|
|
|
|
|
const struct environment* scene = get_scene_watch(); |
|
|
|
|
draw_environment(ren, scene); |
|
|
|
|
draw_level_time(ren, scene); |
|
|
|
|
if (!game_paused) |
|
|
|
|
draw_level_time(ren, scene); |
|
|
|
|
SDL_UnlockMutex(player.physics->lock); |
|
|
|
|
|
|
|
|
|
for (int i=0; i < world.items.size; i++) { |
|
|
|
@ -849,6 +894,11 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -849,6 +894,11 @@ void redraw_buffer(SDL_Renderer * ren) {
|
|
|
|
|
draw_pause_screen(ren, scene); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (draw_watch.goto_level && in_game == false) { |
|
|
|
|
Vect pos = {.x=width/3, .y=height- height/4}; |
|
|
|
|
draw_text(ren, LARGE, pos, scene->colours.fg1, "Press a Key to Continue"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*if (newmousex != mousex || newmousey != mousey) {*/ /*mousey = newmousey;*/ |
|
|
|
|
/*mousex = newmousex;*/ |
|
|
|
|
/*for (int i = 0; i < 256; i++) {*/ |
|
|
|
|