Implement drawing and correctly pushing directional blocks

This commit is contained in:
Eevee (Evelyn Woods) 2020-10-28 00:17:41 -06:00
parent dedaa45d07
commit 060dfdc7d7
3 changed files with 38 additions and 7 deletions

View File

@ -78,9 +78,10 @@ export class Tile {
return false; return false;
} }
can_push(tile) { can_push(tile, direction) {
return ( return (
this.type.pushes && this.type.pushes[tile.type.name] && this.type.pushes && this.type.pushes[tile.type.name] &&
(! tile.type.allows_push || tile.type.allows_push(tile, direction)) &&
! tile.stuck); ! tile.stuck);
} }
@ -150,7 +151,7 @@ export class Cell extends Array {
blocks_entering(actor, direction, level, ignore_pushables = false) { blocks_entering(actor, direction, level, ignore_pushables = false) {
for (let tile of this) { for (let tile of this) {
if (tile.blocks(actor, direction, level) && if (tile.blocks(actor, direction, level) &&
! (ignore_pushables && actor.can_push(tile))) ! (ignore_pushables && actor.can_push(tile, direction)))
{ {
return true; return true;
} }
@ -729,7 +730,7 @@ export class Level {
if (tile.type.on_bump) { if (tile.type.on_bump) {
tile.type.on_bump(tile, this, actor); tile.type.on_bump(tile, this, actor);
} }
if (could_push && actor.can_push(tile)) { if (could_push && actor.can_push(tile, dir2)) {
// Block slapping: you can shove a block by walking past it sideways // Block slapping: you can shove a block by walking past it sideways
// TODO i think cc2 uses the push pose and possibly even turns you here? // TODO i think cc2 uses the push pose and possibly even turns you here?
this.attempt_step(tile, dir2); this.attempt_step(tile, dir2);
@ -824,7 +825,7 @@ export class Level {
let blocked_by_pushable = false; let blocked_by_pushable = false;
for (let tile of goal_cell) { for (let tile of goal_cell) {
if (tile.blocks(actor, direction, this)) { if (tile.blocks(actor, direction, this)) {
if (actor.can_push(tile)) { if (actor.can_push(tile, direction)) {
blocked_by_pushable = true; blocked_by_pushable = true;
} }
else { else {
@ -855,7 +856,7 @@ export class Level {
if (! blocked && blocked_by_pushable) { if (! blocked && blocked_by_pushable) {
// This time make a copy, since we're modifying the contents of the cell // This time make a copy, since we're modifying the contents of the cell
for (let tile of Array.from(goal_cell)) { for (let tile of Array.from(goal_cell)) {
if (actor.can_push(tile)) { if (actor.can_push(tile, direction)) {
if (! this.attempt_step(tile, direction) && if (! this.attempt_step(tile, direction) &&
tile.slide_mode !== null && tile.movement_cooldown !== 0) tile.slide_mode !== null && tile.movement_cooldown !== 0)
{ {

View File

@ -99,8 +99,10 @@ export const CC2_TILESET_LAYOUT = {
popdown_floor: [12, 5], popdown_floor: [12, 5],
popdown_floor_visible: [13, 5], popdown_floor_visible: [13, 5],
no_sign: [14, 5], no_sign: [14, 5],
// TODO arrows overlay at [3, 10] directional_block: {
directional_block: [15, 5], base: [15, 5],
arrows: [3, 10],
},
flippers: [0, 6], flippers: [0, 6],
fire_boots: [1, 6], fire_boots: [1, 6],
@ -711,6 +713,10 @@ export class Tileset {
} }
} }
} }
else if (drawspec.arrows) {
// Directional blocks have a specific overlay, but draw the base first
coords = drawspec.base;
}
else if (drawspec.animate_width) { else if (drawspec.animate_width) {
// Force floors animate their... cutout, I guess? // Force floors animate their... cutout, I guess?
let [x, y] = drawspec.base; let [x, y] = drawspec.base;
@ -826,6 +832,23 @@ export class Tileset {
} }
} }
// Directional blocks have arrows drawn on top
if (drawspec.arrows && tile && tile.arrows) {
let [x, y] = drawspec.arrows;
if (tile.arrows.has('north')) {
blit(x, y, 0, 0, 1, 0.25);
}
if (tile.arrows.has('east')) {
blit(x + 0.75, y, 0.75, 0, 0.25, 1);
}
if (tile.arrows.has('south')) {
blit(x, y + 0.75, 0, 0.75, 1, 0.25);
}
if (tile.arrows.has('west')) {
blit(x, y, 0, 0, 0.25, 1);
}
}
// Special behavior for special objects // Special behavior for special objects
// TODO? hardcode this less? // TODO? hardcode this less?
if (name === 'floor_letter') { if (name === 'floor_letter') {

View File

@ -384,6 +384,10 @@ const TILE_TYPES = {
level.transmute_tile(other, 'splash'); level.transmute_tile(other, 'splash');
level.transmute_tile(me, 'dirt'); level.transmute_tile(me, 'dirt');
} }
else if (other.type.name === 'directional_block') {
level.transmute_tile(other, 'splash');
level.transmute_tile(me, 'floor');
}
else if (other.type.name === 'ice_block') { else if (other.type.name === 'ice_block') {
level.transmute_tile(other, 'splash'); level.transmute_tile(other, 'splash');
level.transmute_tile(me, 'ice'); level.transmute_tile(me, 'ice');
@ -591,6 +595,9 @@ const TILE_TYPES = {
is_block: true, is_block: true,
can_reveal_walls: true, can_reveal_walls: true,
movement_speed: 4, movement_speed: 4,
allows_push(me, direction) {
return me.arrows && me.arrows.has(direction);
},
pushes: { pushes: {
dirt_block: true, dirt_block: true,
ice_block: true, ice_block: true,