From da9b86d5612ef08ee068b017a3ad8cfb2439f70f Mon Sep 17 00:00:00 2001 From: commandblockguy Date: Sat, 1 Aug 2020 01:07:05 -0500 Subject: [PATCH] Add aim indicator --- src/graphics.c | 25 +++++++++++++++++++++++++ src/graphics.h | 4 ++++ src/profiler.c | 2 ++ src/profiler.h | 1 + 4 files changed, 32 insertions(+) diff --git a/src/graphics.c b/src/graphics.c index 97a91f6..524ade7 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -294,6 +294,28 @@ uint8_t screen_to_tm_y(uint24_t screen_y) { return (screen_y - TILEMAP_BASE_Y) / HALF_TILE_PIXEL_HEIGHT; } +// todo: use sprites instead? +void draw_aim_dots(void) { + profiler_start(aim_indicator); + angle_t angle = tanks[0].barrel_rot; + int8_t dx = AIM_INDICATOR_DOT_DISTANCE * fast_cos(angle) / 256; + int8_t dy = AIM_INDICATOR_DOT_DISTANCE * fast_sin(angle) / 256; + + int24_t x = SCREEN_X(tanks[0].phys.position_x) + dx; + int24_t y = SCREEN_Y(tanks[0].phys.position_y) + dy; + + while(x > SCREEN_X(0) && x < SCREEN_X(LEVEL_SIZE_X * TILE_SIZE) && + y > SCREEN_Y(0) && y < SCREEN_Y(LEVEL_SIZE_Y * TILE_SIZE)) { + gfx_SetColor(COL_LIVES_TXT); + pdraw_RectRegion(x - AIM_INDICATOR_RADIUS, y - AIM_INDICATOR_RADIUS, + 2 * AIM_INDICATOR_RADIUS + 1, 2 * AIM_INDICATOR_RADIUS + 1); + gfx_FillCircle(x, y, AIM_INDICATOR_RADIUS); + x += dx; + y += dy; + } + profiler_end(aim_indicator); +} + void render_tank(tank_t *tank) { int j; @@ -370,6 +392,9 @@ void render(level_t *level) { } profiler_end(render_tanks); + // todo: move to GUI section? + draw_aim_dots(); + profiler_start(swapdraw); gfx_SwapDraw(); profiler_end(swapdraw); diff --git a/src/graphics.h b/src/graphics.h index a2f8eb2..1747c6b 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -121,6 +121,10 @@ typedef struct { #define TANK_SPRITE_SIZE_X 28 #define TANK_SPRITE_SIZE_Y 24 +// todo: get an actual value? +#define AIM_INDICATOR_DOT_DISTANCE 30 +#define AIM_INDICATOR_RADIUS 2 + void initGraphics(void); void render(level_t *level); //Render tilemap, tanks, and UI during the game loop diff --git a/src/profiler.c b/src/profiler.c index 0659572..ea47178 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -43,6 +43,7 @@ void profiler_print(void) { profiler_field_last( gfx_wait, 2); profiler_field_last( tilemap, 2); profiler_field_last( render_tanks, 2); + profiler_field_last( aim_indicator, 2); profiler_field_last( swapdraw, 2); profiler_field_last( undraw, 2); profiler_field_last( store_bg, 2); @@ -63,6 +64,7 @@ void profiler_print(void) { profiler_field_average( gfx_wait, 2); profiler_field_average( tilemap, 2); profiler_field_average( render_tanks, 2); + profiler_field_average( aim_indicator, 2); profiler_field_average( swapdraw, 2); profiler_field_average( undraw, 2); profiler_field_average( store_bg, 2); diff --git a/src/profiler.h b/src/profiler.h index a9d4a21..ef7efaf 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -15,6 +15,7 @@ typedef union { uint24_t gfx_wait; uint24_t tilemap; uint24_t render_tanks; + uint24_t aim_indicator; uint24_t swapdraw; uint24_t store_bg; uint24_t undraw;