diff --git a/makefile b/makefile index e04513b..64bd888 100644 --- a/makefile +++ b/makefile @@ -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) diff --git a/src/data/gfx/convimg.yaml b/src/data/gfx/convimg.yaml index 0870fd9..cefc5f0 100644 --- a/src/data/gfx/convimg.yaml +++ b/src/data/gfx/convimg.yaml @@ -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 diff --git a/src/graphics/dynamic_sprites.cpp b/src/graphics/dynamic_sprites.cpp index 26f45bf..34b0bef 100644 --- a/src/graphics/dynamic_sprites.cpp +++ b/src/graphics/dynamic_sprites.cpp @@ -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); @@ -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, @@ -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, diff --git a/src/graphics/dynamic_sprites.h b/src/graphics/dynamic_sprites.h index efec491..a61f5e0 100644 --- a/src/graphics/dynamic_sprites.h +++ b/src/graphics/dynamic_sprites.h @@ -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]; @@ -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]; diff --git a/src/graphics/graphics.cpp b/src/graphics/graphics.cpp index 7261a2c..8338bc3 100644 --- a/src/graphics/graphics.cpp +++ b/src/graphics/graphics.cpp @@ -9,7 +9,6 @@ #include "gui.h" #include "../data/gfx/enemy_pal.h" #include "tiles.h" -#include "repalettize.h" bool needs_redraw; @@ -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]); } } @@ -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); diff --git a/src/objects/mine.cpp b/src/objects/mine.cpp index c7b2df4..ba2a99a 100644 --- a/src/objects/mine.cpp +++ b/src/objects/mine.cpp @@ -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) { diff --git a/src/objects/physicsbody.h b/src/objects/physicsbody.h index 7c51b1b..3976402 100644 --- a/src/objects/physicsbody.h +++ b/src/objects/physicsbody.h @@ -10,8 +10,6 @@ #include "../fwd.h" #include "../physics/physics.h" -#define MAX_OBJECTS 255 - class PhysicsBody { public: PhysicsBody(); diff --git a/src/objects/shell.cpp b/src/objects/shell.cpp index 565feba..105ad27 100644 --- a/src/objects/shell.cpp +++ b/src/objects/shell.cpp @@ -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; diff --git a/src/objects/tank.cpp b/src/objects/tank.cpp index 6b2e57c..53e373a 100644 --- a/src/objects/tank.cpp +++ b/src/objects/tank.cpp @@ -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; @@ -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; diff --git a/src/objects/tank.h b/src/objects/tank.h index e1dfdcf..d387e4f 100644 --- a/src/objects/tank.h +++ b/src/objects/tank.h @@ -4,6 +4,7 @@ #include "../fwd.h" #include +#include #include "../ai/ai_state.h" #include "../physics/collision.h" @@ -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 { @@ -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(); diff --git a/tank.blend b/tank.blend index afea771..9bee067 100644 Binary files a/tank.blend and b/tank.blend differ