diff --git a/build-android/src/draw.c b/build-android/src/draw.c index 64cbdde..1a2ac6c 100644 --- a/build-android/src/draw.c +++ b/build-android/src/draw.c @@ -96,7 +96,13 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) { B = in_view(B); Vect E; E = in_view(player.physics->strings[i].end_point); - SDL_RenderDrawLine(ren, B.x, B.y, E.x, E.y); + + for (int j = -3; j < 3; j++) { + for (int k = -3; k < 3; k++) { + SDL_RenderDrawLine(ren, B.x + j, B.y + k, E.x + j, E.y + k); + } + + } } @@ -705,6 +711,101 @@ void draw_level_time(SDL_Renderer *ren, const struct environment * e) { } + +void draw_mute_button(SDL_Renderer *ren) { + + struct colour c = get_scene_watch()->colours.fg1; + struct colour i = get_scene_watch()->colours.bg; + + if (mute_button.held) { + struct colour t = c; + c = i; + i = t; + } + + + SDL_Rect rect; + + rect.x = mute_button.x; + rect.y = mute_button.y; + rect.w = mute_button.w; + rect.h = mute_button.h; + + + SDL_SetRenderDrawColor(ren, c.r, c.g, c.b, 255); + SDL_RenderFillRect(ren, &rect); + + rect.x += mute_button.w / 6; + rect.y += mute_button.w / 4; + rect.w = mute_button.w / 5; + rect.h = mute_button.h / 2; + + SDL_SetRenderDrawColor(ren, i.r, i.g, i.b, 255); + SDL_RenderFillRect(ren, &rect); + + int j = 0; + for (int i = rect.x + rect.w; i < rect.x + rect.w + mute_button.w / 5; i++) { + SDL_RenderDrawLine(ren, i, rect.y + j + rect.h, i, rect.y - j); + j++; + } + + j -= 8; + int bars = 0; + int bar_width = mute_button.w / 6; + if (!mute_button.state) { + for (int i = rect.x + rect.w + mute_button.w / 5; + i < mute_button.x + mute_button.w - 5; i++) { + if ((bars++) % bar_width >= bar_width / 2) { + SDL_RenderDrawLine(ren, i, rect.y + j + rect.h, i, rect.y - j); + } + if (i % 8 == 0) j += 4; + + } + } else { + int w = mute_button.w / 5; + int i = rect.x + rect.w + mute_button.w / 5 + w/2; + int j = rect.y + w / 2; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + i += 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + i -= 1; + + j += 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + j -= 1; + + j += 1; + i += 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + j -= 1; + i -= 1; + + i -= 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + i += 1; + + j -= 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + j += 1; + + j -= 1; + i -= 1; + SDL_RenderDrawLine(ren, i, j + w, i + w, j); + SDL_RenderDrawLine(ren, i + w, j + w, i, j); + j += 1; + i += 1; + + } + + +} + void draw_pause_screen(SDL_Renderer *ren, struct environment *e) { char *te[] = { "GAME PAUSED.", @@ -836,6 +937,7 @@ void redraw_buffer(SDL_Renderer * ren) { lplayer.colliding); draw_collision_poly(ren, &lplayer); draw_forces(ren, &lplayer); + draw_mute_button(ren); if (gameui.currently_bound_textbox) { draw_level_chooser_tbox(ren); diff --git a/build-android/src/game.c b/build-android/src/game.c index 38263f2..9323ebc 100644 --- a/build-android/src/game.c +++ b/build-android/src/game.c @@ -39,6 +39,7 @@ struct sg_times_list save_times_lst; struct draw_watcher draw_watch = {}; /* object that handles ui interactions in game.c and which draw watches */ struct textbox_info textboxes[1]; +struct button mute_button; struct ui_state gameui = {}; @@ -1709,9 +1710,21 @@ void startgame(SDL_Renderer * ren) { viewport_pos.x = player.physics->position.x - width / 2; viewport_pos.y = player.physics->position.y - height / 2; + + mute_button.x = 90.0/100 * width; + mute_button.y = 85.0/100 * height; + mute_button.w = 90; + mute_button.h = 90; + mute_button.state = mute; + mute_button.held = false; + //get_room(); } +bool aabb_check(float x, float y, float rx, float ry, float w, float h) { + return x > rx && x < rx + w && y > ry && y < ry + h; +} + double get_abs(double x,double y) { return (sqrt(x*x + y*y)); } @@ -1771,6 +1784,7 @@ void handle_input_event(SDL_Event event) { pull_rope(900); } if (sc == input_map.mute) { mute = !mute; + mute_button.state = mute; } if (sc == input_map.pause) { if (in_game) game_paused = !game_paused; @@ -1803,6 +1817,14 @@ void handle_input_event(SDL_Event event) { break; case SDL_MOUSEBUTTONDOWN: + + if (aabb_check(event.button.x, event.button.y, + mute_button.x, mute_button.y, mute_button.w, + mute_button.h)) { + mute_button.held = true; + break; + } + add_rope(event.button.x, event.button.y); if (event.button.button == input_map.mouse_attach_rope) mouse_down = true; @@ -1810,6 +1832,17 @@ void handle_input_event(SDL_Event event) { pull_rope(900); break; case SDL_MOUSEBUTTONUP: + + mute_button.held = false; + if (aabb_check(event.button.x, event.button.y, + mute_button.x, mute_button.y, mute_button.w, + mute_button.y)) { + mute = !mute; + mute_button.state = mute; + break; + } + + if (event.button.button == input_map.mouse_attach_rope) { mouse_down = false; delete_rope(); diff --git a/build-android/src/types.h b/build-android/src/types.h index 8f641d3..345b735 100644 --- a/build-android/src/types.h +++ b/build-android/src/types.h @@ -233,4 +233,14 @@ enum { E_ROOM_TILES = E_ROOM_WIDTH / E_ROOM_RES, }; + +struct button { + char *name; + bool state; + bool held; + int x, y, w, h; +}; + +extern struct button mute_button; + #endif