Skip to content

Commit

Permalink
Add aim indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblockguy committed Aug 1, 2020
1 parent 2a418df commit da9b86d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit da9b86d

Please sign in to comment.