Skip to content

Commit

Permalink
Wind/Current tiles animation
Browse files Browse the repository at this point in the history
  • Loading branch information
andwn committed Feb 19, 2018
1 parent 01ace50 commit d435f0b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 31 deletions.
4 changes: 4 additions & 0 deletions res/resources.res
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ TILESET TS_HudMax "sprite/hudmax.png" 0
# Breakable Block Tile
TILESET TS_Break "sprite/breakable.png" 0

# Wind/Current Tiles
TILESET TS_WindH "wind_h.png" 0
TILESET TS_WindV "wind_v.png" 0

# Island Effect
PALETTE PAL_XX "xxBack.png"
TILESET TS_XXBack "xxBack.png" 0
Expand Down
Binary file added res/wind_h.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/wind_v.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 20 additions & 18 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,40 @@ void camera_update() {
if(morphingColumn) {
int16_t x = sub_to_tile(x_next) + (morphingColumn == 1 ? 30 : -30);
int16_t y = sub_to_tile(y_next) - 16 /*+ morphingRow*/;
if(x >= 0 && x < stageWidth * 2) {
for(uint8_t i = 32; i--; ) {
if(y >= stageHeight * 2) break;
if(x >= 0 && x < stageWidth << 1) {
for(uint16_t i = 32; i--; ) {
if(y >= stageHeight << 1) break;
if(y >= 0) {
// Fuck math tbh
uint8_t b = stage_get_block(x/2, y/2);
uint16_t t = (b%16) * 2 + (b/16) * 64;
uint8_t ta = stage_get_block_type(x/2, y/2);
mapcol[y%32] = TILE_ATTR_FULL(ta == 0x43 ? PAL1 : PAL2, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)*32));
uint16_t b = stage_get_block(x>>1, y>>1);
uint16_t t = ((b&15) << 1) + ((b>>4) << 6);
uint16_t ta = stage_get_block_type(x>>1, y>>1);
uint16_t pal = (ta == 0x43 || ta & 0x80) ? PAL1 : PAL2;
mapcol[y&31] = TILE_ATTR_FULL(pal, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)<<5));
}
y++;
}
DMA_queueDma(DMA_VRAM, (uint32_t)mapcol, VDP_PLAN_A + (x%64)*2, 32, 128);
DMA_queueDma(DMA_VRAM, (uint32_t) mapcol, VDP_PLAN_A + ((x & 63) << 1), 32, 128);
}
}
if(morphingRow) {
int16_t y = sub_to_tile(y_next) + (morphingRow == 1 ? 15 : -15);
int16_t x = sub_to_tile(x_next) - 32 /*+ morphingColumn*/;
if(y >= 0 && y < stageHeight * 2) {
for(uint8_t i = 64; i--; ) {
if(x >= stageWidth * 2) break;
if(y >= 0 && y < stageHeight << 1) {
for(uint16_t i = 64; i--; ) {
if(x >= stageWidth << 1) break;
if(x >= 0) {
uint8_t b = stage_get_block(x/2, y/2);
uint16_t t = (b%16) * 2 + (b/16) * 64;
uint8_t ta = stage_get_block_type(x/2, y/2);
maprow[x%64] = TILE_ATTR_FULL(ta == 0x43 ? PAL1 : PAL2, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)*32));
uint16_t b = stage_get_block(x>>1, y>>1);
uint16_t t = ((b&15) << 1) + ((b>>4) << 6);
uint16_t ta = stage_get_block_type(x>>1, y>>1);
uint16_t pal = (ta == 0x43 || ta & 0x80) ? PAL1 : PAL2;
maprow[x&63] = TILE_ATTR_FULL(pal, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)<<5));
}
x++;
}
DMA_queueDma(DMA_VRAM, (uint32_t)maprow, VDP_PLAN_A + (y%32)*64*2, 64, 2);
DMA_queueDma(DMA_VRAM, (uint32_t) maprow, VDP_PLAN_A + ((y & 31) << 7), 64, 2);
}
}
}
Expand Down
51 changes: 38 additions & 13 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,33 +429,58 @@ void stage_update() {
VDP_setVerticalScroll(PLAN_A, sub_to_pixel(camera.y) - SCREEN_HALF_H);
}
if(currentsCount) { // Waterway currents
currentsTimer++;
currentsTimer = (currentsTimer + 1) & 0x1F;
uint8_t t = currentsTimer & 3;
if(t < currentsCount) {
//VDP_setEnable(FALSE);
// I'll do this later
//VDP_setEnable(TRUE);
uint16_t from_index = 0;
uint8_t *from_ts = NULL;
uint16_t to_index = TILE_TSINDEX + ((currents[t].index & 15) << 1) + ((currents[t].index >> 4) << 6);
switch(currents[t].dir) {
case 0: // Left
from_ts = (uint8_t*) TS_WindH.tiles;
from_index += (currentsTimer >> 1) & ~1;
break;
case 1: // Up
from_ts = (uint8_t*) TS_WindV.tiles;
from_index += (currentsTimer >> 1) & ~1;
break;
case 2: // Right
from_ts = (uint8_t*) TS_WindH.tiles;
from_index += 14 - ((currentsTimer >> 1) & ~1);
break;
case 3: // Down
from_ts = (uint8_t*) TS_WindV.tiles;
from_index += 14 - ((currentsTimer >> 1) & ~1);
break;
default: return;
}
// Replace the tile in the tileset
DMA_doDma(DMA_VRAM, (uint32_t) (from_ts + (from_index << 5)), to_index << 5, 32, 2);
from_index += 16;
to_index += 32;
DMA_doDma(DMA_VRAM, (uint32_t) (from_ts + (from_index << 5)), to_index << 5, 32, 2);
}
}
}

void stage_draw_screen() {
uint16_t maprow[64];
int16_t y = sub_to_tile(camera.y) - 16;
for(uint8_t i = 32; i--; ) {
for(uint16_t i = 32; i--; ) {
if(vblank) aftervsync(); // So we don't lag the music
vblank = 0;

if(y >= 0 && y < stageHeight * 2) {
if(y >= 0 && y < stageHeight << 1) {
int16_t x = sub_to_tile(camera.x) - 32;
for(uint8_t j = 64; j--; ) {
if(x >= stageWidth * 2) break;
for(uint16_t j = 64; j--; ) {
if(x >= stageWidth << 1) break;
if(x >= 0) {
uint8_t b = stage_get_block(x/2, y/2);
uint16_t t = (b%16) * 2 + (b/16) * 64;
uint8_t ta = stage_get_block_type(x/2, y/2);
maprow[x%64] = TILE_ATTR_FULL(ta == 0x43 ? PAL1 : PAL2, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)*32));
uint16_t b = stage_get_block(x>>1, y>>1);
uint16_t t = ((b&15) << 1) + ((b>>4) << 6);
uint16_t ta = stage_get_block_type(x>>1, y>>1);
uint16_t pal = (ta == 0x43 || ta & 0x80) ? PAL1 : PAL2;
maprow[x&63] = TILE_ATTR_FULL(pal, (ta&0x40) > 0,
0, 0, TILE_TSINDEX + t + (x&1) + ((y&1)<<5));
}
x++;
}
Expand Down

0 comments on commit d435f0b

Please sign in to comment.