Skip to content

Commit

Permalink
Add tread marks
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblockguy committed Jan 19, 2021
1 parent 550869b commit de1970c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 12 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif
# ----------------------------

SHELL = bash
IMAGE_NAMES = {{{pl,en}_{base,turret},shell}_{0..8},mine_{0..2}}
IMAGE_NAMES = {{{pl,en}_{base,turret},shell,tread}_{0..8},mine_{0..2}}
CONVIMG_INPUT = $(shell echo src/data/gfx/trimmed/$(IMAGE_NAMES).png) src/data/gfx/tileset.png src/data/gfx/bg_tank.png src/data/gfx/fg_tank.png
CONVIMG_OUTPUT = $(shell echo src/data/gfx/$(IMAGE_NAMES).{c,h}) src/data/gfx/tileset.c src/data/gfx/tileset.h src/data/gfx/bg_tank.c src/data/gfx/bg_tank.h src/data/gfx/fg_tank.c src/data/gfx/fg_tank.h src/data/gfx/palette.c src/data/gfx/palette.h src/data/gfx/gfx.h src/data/gfx/enemy_palette.bin
BLENDER_OUTPUT = $(shell echo src/data/gfx/rendered/$(IMAGE_NAMES).png)
Expand Down
1 change: 1 addition & 0 deletions src/data/gfx/convimg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ converts:
- trimmed/pl_*.png
- trimmed/shell_*.png
- trimmed/mine_*.png
- trimmed/tread_*.png
- bg_tank.png
- fg_tank.png
- explosion.png
Expand Down
65 changes: 65 additions & 0 deletions src/graphics/dynamic_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ gfx_UninitedSprite(pl_turret_13, pl_turret_3_width, pl_turret_3_height);
gfx_UninitedSprite(pl_turret_14, pl_turret_2_width, pl_turret_2_height);
gfx_UninitedSprite(pl_turret_15, pl_turret_1_width, pl_turret_1_height);

gfx_UninitedSprite(tread_9, tread_7_width, tread_7_height);
gfx_UninitedSprite(tread_10, tread_6_width, tread_6_height);
gfx_UninitedSprite(tread_11, tread_5_width, tread_5_height);
gfx_UninitedSprite(tread_12, tread_4_width, tread_4_height);
gfx_UninitedSprite(tread_13, tread_3_width, tread_3_height);
gfx_UninitedSprite(tread_14, tread_2_width, tread_2_height);
gfx_UninitedSprite(tread_15, tread_1_width, tread_1_height);

gfx_UninitedSprite(shell_9, shell_7_width, shell_7_height);
gfx_UninitedSprite(shell_10, shell_6_width, shell_6_height);
gfx_UninitedSprite(shell_11, shell_5_width, shell_5_height);
Expand Down Expand Up @@ -72,6 +80,25 @@ extern gfx_sprite_t * const tank_turrets[NUM_TANK_TYPES][16] = {
}
};

extern gfx_sprite_t * const tread_sprites[16] = {
tread_0,
tread_1,
tread_2,
tread_3,
tread_4,
tread_5,
tread_6,
tread_7,
tread_8,
(gfx_sprite_t*)tread_9_data,
(gfx_sprite_t*)tread_10_data,
(gfx_sprite_t*)tread_11_data,
(gfx_sprite_t*)tread_12_data,
(gfx_sprite_t*)tread_13_data,
(gfx_sprite_t*)tread_14_data,
(gfx_sprite_t*)tread_15_data,
};

extern gfx_sprite_t * const shell_sprites[16] = {
shell_0,
shell_1,
Expand Down Expand Up @@ -250,6 +277,44 @@ extern const uint8_t en_turret_y_offsets[16] = {
en_turret_1_offset_y,
};

extern const uint8_t tread_x_offsets[16] = {
tread_0_offset_x,
tread_1_offset_x,
tread_2_offset_x,
tread_3_offset_x,
tread_4_offset_x,
tread_5_offset_x,
tread_6_offset_x,
tread_7_offset_x,
tread_8_offset_x,
tank_sprite_total_width - tread_7_offset_x - tread_7_width,
tank_sprite_total_width - tread_6_offset_x - tread_6_width,
tank_sprite_total_width - tread_5_offset_x - tread_5_width,
tank_sprite_total_width - tread_4_offset_x - tread_4_width,
tank_sprite_total_width - tread_3_offset_x - tread_3_width,
tank_sprite_total_width - tread_2_offset_x - tread_2_width,
tank_sprite_total_width - tread_1_offset_x - tread_1_width,
};

extern const uint8_t tread_y_offsets[16] = {
tread_0_offset_y,
tread_1_offset_y,
tread_2_offset_y,
tread_3_offset_y,
tread_4_offset_y,
tread_5_offset_y,
tread_6_offset_y,
tread_7_offset_y,
tread_8_offset_y,
tread_7_offset_y,
tread_6_offset_y,
tread_5_offset_y,
tread_4_offset_y,
tread_3_offset_y,
tread_2_offset_y,
tread_1_offset_y,
};

extern const uint8_t shell_x_offsets[16] = {
shell_0_offset_x,
shell_1_offset_x,
Expand Down
5 changes: 5 additions & 0 deletions src/graphics/dynamic_sprites.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern gfx_sprite_t *tank_turrets[NUM_TANK_TYPES][16];
extern gfx_sprite_t *const enemy_bases_unconv[9];
extern gfx_sprite_t *const enemy_turrets_unconv[9];

extern gfx_sprite_t *tread_sprites[9];

extern gfx_sprite_t *shell_sprites[16];

extern gfx_sprite_t *mine_sprites[4];
Expand All @@ -23,6 +25,9 @@ extern const uint8_t en_base_y_offsets[16];
extern const uint8_t en_turret_x_offsets[16];
extern const uint8_t en_turret_y_offsets[16];

extern const uint8_t tread_x_offsets[16];
extern const uint8_t tread_y_offsets[16];

extern const uint8_t shell_x_offsets[16];
extern const uint8_t shell_y_offsets[16];

Expand Down
11 changes: 5 additions & 6 deletions src/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "gui.h"
#include "../data/gfx/enemy_pal.h"
#include "tiles.h"
#include "repalettize.h"

bool needs_redraw;

Expand All @@ -23,6 +22,7 @@ void init_graphics() {
for(uint8_t i = 1; i < 8; i++) {
gfx_FlipSpriteY(tank_bases[PLAYER][i], tank_bases[PLAYER][16 - i]);
gfx_FlipSpriteY(tank_turrets[PLAYER][i], tank_turrets[PLAYER][16 - i]);
gfx_FlipSpriteY(tread_sprites[i], tread_sprites[16 - i]);
gfx_FlipSpriteY(shell_sprites[i], shell_sprites[16 - i]);
}
}
Expand Down Expand Up @@ -71,11 +71,10 @@ void render() {
// restrict drawing to only the play area, to prevent the banners from being overwritten
gfx_SetClipRegion(SCREEN_X_CONST(0), SCREEN_Y_CONST(-TILE_SIZE), SCREEN_X_CONST(LEVEL_SIZE_X * TILE_SIZE),
SCREEN_Y_CONST((LEVEL_SIZE_Y - 2) * TILE_SIZE));
for(auto *it: PhysicsBody::objects) {
it->render(0);
}
for(auto *it: PhysicsBody::objects) {
it->render(1);
for(uint8_t layer = 0; layer < 3; layer++) {
for(auto *it: PhysicsBody::objects) {
it->render(layer);
}
}
gfx_SetClipRegion(0, 0, LCD_WIDTH, LCD_HEIGHT);
profiler_end(render_pbs);
Expand Down
2 changes: 1 addition & 1 deletion src/objects/mine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Mine::process() {
}

void Mine::render(uint8_t layer) {
if(layer != 0) return;
if(layer != 1) return;
profiler_add(render_mines);

if(countdown > EXPLOSION_ANIM) {
Expand Down
2 changes: 0 additions & 2 deletions src/objects/physicsbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "../fwd.h"
#include "../physics/physics.h"

#define MAX_OBJECTS 255

class PhysicsBody {
public:
PhysicsBody();
Expand Down
2 changes: 1 addition & 1 deletion src/objects/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Shell::process() {
}

void Shell::render(uint8_t layer) {
if(layer != 1) return;
if(layer != 2) return;
profiler_add(render_shells);

uint8_t sprite = direction;
Expand Down
21 changes: 20 additions & 1 deletion src/objects/tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Tank::Tank(const serialized_tank_t *ser_tank, uint8_t id) {
tread_rot = 0;
shot_cooldown = 0;
mine_cooldown = 0;
tread_distance = TREAD_DISTANCE;
draw_treads = false;

if(id == 0) {
game.player = this;
Expand Down Expand Up @@ -90,7 +92,24 @@ void Tank::process() {
}

void Tank::render(uint8_t layer) {
if(layer != 1) return;
if(layer == 0) {
tread_distance += abs(velocity_x) + abs(velocity_y);
if(draw_treads) {
gfx_TransparentSprite(tread_sprite, tread_pos.xmin, tread_pos.ymin);
redraw_tiles(&tread_pos, 0);
draw_treads = false;
}
if(tread_distance > TREAD_DISTANCE) {
uint8_t base_index = (((uint8_t) -((tread_rot >> (INT_BITS - 8)) - 64)) >> 3) & 0xF;
get_sprite_footprint(&tread_pos, this, tread_sprites, tread_x_offsets, tread_y_offsets, base_index);
tread_distance -= TREAD_DISTANCE;
tread_sprite = tread_sprites[base_index];
gfx_TransparentSprite(tread_sprite, tread_pos.xmin, tread_pos.ymin);
redraw_tiles(&tread_pos, 0);
draw_treads = true;
}
}
if(layer != 2) return;
profiler_add(render_tanks);

uint8_t base_index = (((uint8_t) -((tread_rot >> (INT_BITS - 8)) - 64)) >> 3) & 0xF;
Expand Down
9 changes: 9 additions & 0 deletions src/objects/tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../fwd.h"

#include <cstdint>
#include <graphx.h>

#include "../ai/ai_state.h"
#include "../physics/collision.h"
Expand All @@ -27,6 +28,8 @@ typedef uint8_t tank_type_t;
#define SHOT_COOLDOWN 5
#define MINE_COOLDOWN 10

#define TREAD_DISTANCE (TILE_SIZE / 3)

#define MAX_NUM_TANKS 16

enum {
Expand Down Expand Up @@ -65,9 +68,15 @@ class Tank: public PhysicsBody {
uint8_t num_mines = 0;
uint8_t shot_cooldown;
uint8_t mine_cooldown;
uint tread_distance;
ai_move_state_t ai_move;
ai_fire_state_t ai_fire;

// Used to (somewhat lazily) draw stuff on the background across two frame buffers
bool draw_treads;
gfx_sprite_t *tread_sprite;
gfx_region_t tread_pos;

// Kill this physics body, then destroy it
void kill();
void process();
Expand Down
Binary file modified tank.blend
Binary file not shown.

0 comments on commit de1970c

Please sign in to comment.