diff --git a/src/controlscheme.c b/src/controlscheme.c index 77292e7..99d699f 100644 --- a/src/controlscheme.c +++ b/src/controlscheme.c @@ -33,6 +33,7 @@ void get_input_map(void) { input_map.pause = SDL_SCANCODE_ESCAPE; input_map.quit = SDL_SCANCODE_Q; input_map.goto_level = SDL_SCANCODE_G; + input_map.high_contrast_mode = SDL_SCANCODE_H; input_map.mouse_attach_rope_pull = SDL_BUTTON_LEFT; input_map.mouse_attach_rope = SDL_BUTTON_RIGHT; } diff --git a/src/controlscheme.h b/src/controlscheme.h index a48a351..d8a7c6e 100644 --- a/src/controlscheme.h +++ b/src/controlscheme.h @@ -22,6 +22,7 @@ struct InputMap { SDL_Scancode quit; SDL_Scancode pause; SDL_Scancode goto_level; + SDL_Scancode high_contrast_mode; Uint8 mouse_attach_rope_pull; Uint8 mouse_attach_rope; }; diff --git a/src/draw.c b/src/draw.c index 1a8fcbf..a394b9f 100644 --- a/src/draw.c +++ b/src/draw.c @@ -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) { 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) { } } +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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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++) {*/ diff --git a/src/draw.h b/src/draw.h index 851590e..e6d7d95 100644 --- a/src/draw.h +++ b/src/draw.h @@ -30,7 +30,19 @@ void add_to_view(draw_type kind, void * object); void redraw_buffer(SDL_Renderer * ren); -void draw_text(SDL_Renderer *ren, Vect pos, struct colour colour, char *text); +void draw_text_default(SDL_Renderer *ren, Vect pos, struct colour colour, char *text); + +enum FontNames { + DEFAULT, + LARGE +}; + + +void load_fonts(void); + +void draw_text(SDL_Renderer *ren, enum FontNames fontID, Vect pos, struct colour colour, char *text); + + int draw_end_screen(SDL_Renderer *ren); diff --git a/src/environment.c b/src/environment.c index c496f56..12e491d 100644 --- a/src/environment.c +++ b/src/environment.c @@ -70,9 +70,6 @@ struct colour_pallete get_pallete_high_contrast(void) { struct colour_pallete get_pallete (int seed) { struct colour base; - if (high_contrast_mode) - return get_pallete_high_contrast(); - int n = seed; int red = get_rand(&n) % 255; int blue = get_rand(&n) % 255; @@ -114,6 +111,12 @@ int comp(const void *one, const void *two) { return *(int*)one >= *(int*)two; } +void swap_palletes(struct environment *e) { + struct colour_pallete b = e->colours; + e->colours = e->coloursb; + e->coloursb = b; +} + struct environment get_scene_at(Vect coordinate, int seed) { // TODO: Environment needs to be shared between threads // - this implementation duplicates it: each thread that calls @@ -148,6 +151,10 @@ struct environment get_scene_at(Vect coordinate, int seed) { e.bg2 = new_arlst_wfree(E_ROOM_TILES, free); e.colours = get_pallete(seed); + e.coloursb = get_pallete_high_contrast(); + + if (draw_watch.high_contrast_mode) + swap_palletes(&e); Vect bit; bit.y = 100 * seed; diff --git a/src/environment.h b/src/environment.h index aefe92b..095823f 100644 --- a/src/environment.h +++ b/src/environment.h @@ -9,4 +9,8 @@ int destroy_environment(struct environment *e); const struct environment *get_scene_watch(void); +extern struct environment *environment_watch; + +void swap_palletes(struct environment *e); + #endif diff --git a/src/game.c b/src/game.c index e6f1b9b..694a084 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,7 @@ #include "game.h" #include "draw.h" #include "audio.h" +#include "environment.h" #include "types.h" #include #include @@ -104,7 +105,9 @@ void new_level_tb_close_callback(struct textbox_info*textbox, void*callback) { int lid = atoi(textbox->text_input); - gameui.goto_new_level = lid; + draw_watch.goto_level = true; + if (lid > 0) + gameui.goto_new_level = lid; } @@ -1643,6 +1646,7 @@ GlobWorld create_world() { } void startgame(SDL_Renderer * ren) { + load_fonts(); get_input_map(); textboxes[TB_LEVEL_CHOOSER].id = TB_LEVEL_CHOOSER; @@ -1650,7 +1654,7 @@ void startgame(SDL_Renderer * ren) { debug_ren = ren; - level = 0; + level = 1; save_times_lst = (struct sg_times_list){}; load_score_times("saves/times"); @@ -1752,6 +1756,9 @@ void handle_input_event(SDL_Event event) { gameui.currently_bound_textbox = textboxes + TB_LEVEL_CHOOSER; }; + if (sc == input_map.high_contrast_mode) { + swap_palletes(environment_watch); + } break; case SDL_KEYUP: @@ -1830,6 +1837,8 @@ int step(void) { } if (!game_paused) { + draw_watch.goto_level = false; + if (player.physics->position.x > world.uniques_index[ROOM_W]->room ->floor.items[3]->position.x) { level_timer_update(false); diff --git a/src/game.h b/src/game.h index f196701..c39da9a 100644 --- a/src/game.h +++ b/src/game.h @@ -14,9 +14,12 @@ extern int level; extern bool in_game; extern int quality; + struct draw_watcher { long best_time; bool finish_level; + bool goto_level; + bool high_contrast_mode; }; diff --git a/src/main.c b/src/main.c index 77fe9c9..a4227fa 100644 --- a/src/main.c +++ b/src/main.c @@ -168,11 +168,13 @@ int main (int argc, char** argv) { /* * TODO: + * - Fix open screen and pause screens * - Allow setting and saving/loading differnet control schemes * - Allow starting a specific level * - Allow adjusging level lengths? * - Ensure next_level doesn't leak memory * - fix that weird jitter + * - Fix open screen and pause screens * - make the end of level look sane * - restart level * - make sure goto level doesn't log an end-0f-level time diff --git a/src/types.h b/src/types.h index bec62bc..b4fc485 100644 --- a/src/types.h +++ b/src/types.h @@ -188,6 +188,7 @@ struct environment { ArrayList bg1; // doubles ArrayList bg2; // doubles struct colour_pallete colours; + struct colour_pallete coloursb; struct physics_collection physics; };