Implement traps!

This commit is contained in:
Eevee (Evelyn Woods) 2020-09-01 01:36:47 -06:00
parent eb2dd7a4a4
commit 2ae053d87a

View File

@ -7,7 +7,7 @@ const TILE_TYPES = {
floor_letter: { floor_letter: {
load(me, template) { load(me, template) {
me.ascii_code = template.modifier; me.ascii_code = template.modifier;
} },
}, },
wall: { wall: {
blocks: true, blocks: true,
@ -20,12 +20,12 @@ const TILE_TYPES = {
blocks: true, blocks: true,
on_bump(me, level, other) { on_bump(me, level, other) {
me.become('wall'); me.become('wall');
} },
}, },
popwall: { popwall: {
on_depart(me, level, other) { on_depart(me, level, other) {
me.become('wall'); me.become('wall');
} },
}, },
thinwall_n: { thinwall_n: {
thin_walls: new Set(['north']), thin_walls: new Set(['north']),
@ -46,13 +46,13 @@ const TILE_TYPES = {
blocks: true, blocks: true,
on_bump(me, level, other) { on_bump(me, level, other) {
me.become('wall'); me.become('wall');
} },
}, },
fake_floor: { fake_floor: {
blocks: true, blocks: true,
on_bump(me, level, other) { on_bump(me, level, other) {
me.become('floor'); me.become('floor');
} },
}, },
// Swivel doors // Swivel doors
@ -77,7 +77,7 @@ const TILE_TYPES = {
if (other.type.has_inventory && other.take_item('key_red')) { if (other.type.has_inventory && other.take_item('key_red')) {
me.type = TILE_TYPES.floor; me.type = TILE_TYPES.floor;
} }
} },
}, },
door_blue: { door_blue: {
blocks: true, blocks: true,
@ -85,7 +85,7 @@ const TILE_TYPES = {
if (other.type.has_inventory && other.take_item('key_blue')) { if (other.type.has_inventory && other.take_item('key_blue')) {
me.type = TILE_TYPES.floor; me.type = TILE_TYPES.floor;
} }
} },
}, },
door_yellow: { door_yellow: {
blocks: true, blocks: true,
@ -93,7 +93,7 @@ const TILE_TYPES = {
if (other.type.has_inventory && other.take_item('key_yellow')) { if (other.type.has_inventory && other.take_item('key_yellow')) {
me.type = TILE_TYPES.floor; me.type = TILE_TYPES.floor;
} }
} },
}, },
door_green: { door_green: {
blocks: true, blocks: true,
@ -101,7 +101,7 @@ const TILE_TYPES = {
if (other.type.has_inventory && other.take_item('key_green')) { if (other.type.has_inventory && other.take_item('key_green')) {
me.type = TILE_TYPES.floor; me.type = TILE_TYPES.floor;
} }
} },
}, },
// Terrain // Terrain
@ -111,7 +111,7 @@ const TILE_TYPES = {
// TODO block melinda only without the hiking boots; can't use ignore because then she wouldn't step on it :S also ignore doesn't apply to blocks anyway. // TODO block melinda only without the hiking boots; can't use ignore because then she wouldn't step on it :S also ignore doesn't apply to blocks anyway.
on_arrive(me, level, other) { on_arrive(me, level, other) {
me.become('floor'); me.become('floor');
} },
}, },
gravel: { gravel: {
blocks_monsters: true, blocks_monsters: true,
@ -127,7 +127,7 @@ const TILE_TYPES = {
else { else {
other.destroy(); other.destroy();
} }
} },
}, },
water: { water: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
@ -143,14 +143,14 @@ const TILE_TYPES = {
else { else {
other.destroy(); other.destroy();
} }
} },
}, },
turtle: { turtle: {
}, },
ice: { ice: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
level.make_slide(other, 'ice'); level.make_slide(other, 'ice');
} },
}, },
ice_sw: { ice_sw: {
thin_walls: new Set(['south', 'west']), thin_walls: new Set(['south', 'west']),
@ -162,7 +162,7 @@ const TILE_TYPES = {
other.direction = 'north'; other.direction = 'north';
} }
level.make_slide(other, 'ice'); level.make_slide(other, 'ice');
} },
}, },
ice_nw: { ice_nw: {
thin_walls: new Set(['north', 'west']), thin_walls: new Set(['north', 'west']),
@ -174,7 +174,7 @@ const TILE_TYPES = {
other.direction = 'south'; other.direction = 'south';
} }
level.make_slide(other, 'ice'); level.make_slide(other, 'ice');
} },
}, },
ice_ne: { ice_ne: {
thin_walls: new Set(['north', 'east']), thin_walls: new Set(['north', 'east']),
@ -186,7 +186,7 @@ const TILE_TYPES = {
other.direction = 'south'; other.direction = 'south';
} }
level.make_slide(other, 'ice'); level.make_slide(other, 'ice');
} },
}, },
ice_se: { ice_se: {
thin_walls: new Set(['south', 'east']), thin_walls: new Set(['south', 'east']),
@ -198,31 +198,31 @@ const TILE_TYPES = {
other.direction = 'north'; other.direction = 'north';
} }
level.make_slide(other, 'ice'); level.make_slide(other, 'ice');
} },
}, },
force_floor_n: { force_floor_n: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
other.direction = 'north'; other.direction = 'north';
level.make_slide(other, 'force'); level.make_slide(other, 'force');
} },
}, },
force_floor_e: { force_floor_e: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
other.direction = 'east'; other.direction = 'east';
level.make_slide(other, 'force'); level.make_slide(other, 'force');
} },
}, },
force_floor_s: { force_floor_s: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
other.direction = 'south'; other.direction = 'south';
level.make_slide(other, 'force'); level.make_slide(other, 'force');
} },
}, },
force_floor_w: { force_floor_w: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
other.direction = 'west'; other.direction = 'west';
level.make_slide(other, 'force'); level.make_slide(other, 'force');
} },
}, },
force_floor_all: { force_floor_all: {
// TODO cc2 cycles these... // TODO cc2 cycles these...
@ -232,7 +232,7 @@ const TILE_TYPES = {
on_arrive(me, level, other) { on_arrive(me, level, other) {
me.destroy(); me.destroy();
other.destroy(); other.destroy();
} },
}, },
thief_tools: { thief_tools: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
@ -243,7 +243,7 @@ const TILE_TYPES = {
} }
} }
} }
} },
}, },
thief_keys: { thief_keys: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
@ -254,7 +254,7 @@ const TILE_TYPES = {
} }
} }
} }
} },
}, },
forbidden: { forbidden: {
}, },
@ -294,10 +294,14 @@ const TILE_TYPES = {
cell._add(new tile.constructor(tile.type, tile.x, tile.y, tile.direction)); cell._add(new tile.constructor(tile.type, tile.x, tile.y, tile.direction));
} }
} }
} },
}, },
trap: { trap: {
// TODO ??? on_arrive(me, level, other) {
if (! me.open) {
other.stuck = true;
}
},
}, },
teleport_blue: { teleport_blue: {
// TODO // TODO
@ -312,7 +316,7 @@ const TILE_TYPES = {
actor.direction = DIRECTIONS[actor.direction].opposite; actor.direction = DIRECTIONS[actor.direction].opposite;
} }
} }
} },
}, },
button_green: { button_green: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
@ -335,10 +339,35 @@ const TILE_TYPES = {
} }
} }
} }
} },
}, },
button_brown: { button_brown: {
// TODO how do i implement this. connects_to: 'trap',
connect_order: 'forward',
on_arrive(me, level, other) {
if (me.connection && ! me.connection.doomed) {
// TODO do gray buttons affect traps? if so this should use activate()
let trap = me.connection;
trap.open = true;
for (let tile of level.cells[trap.y][trap.x]) {
if (tile.stuck) {
tile.stuck = false;
}
}
}
},
on_depart(me, level, other) {
if (me.connection && ! me.connection.doomed) {
// TODO do gray buttons affect traps? if so this should use activate()
let trap = me.connection;
trap.open = false;
for (let tile of level.cells[trap.y][trap.x]) {
if (tile.is_actor) {
tile.stuck = false;
}
}
}
},
}, },
button_red: { button_red: {
connects_to: 'cloner', connects_to: 'cloner',
@ -347,7 +376,7 @@ const TILE_TYPES = {
if (me.connection && ! me.connection.doomed) { if (me.connection && ! me.connection.doomed) {
me.connection.type.activate(me.connection, level); me.connection.type.activate(me.connection, level);
} }
} },
}, },
// Critters // Critters
@ -507,7 +536,7 @@ const TILE_TYPES = {
level.collect_chip(); level.collect_chip();
me.destroy(); me.destroy();
} }
} },
}, },
chip_extra: { chip_extra: {
is_chip: true, is_chip: true,
@ -535,14 +564,14 @@ const TILE_TYPES = {
if (other.type.is_player && level.chips_remaining === 0) { if (other.type.is_player && level.chips_remaining === 0) {
me.type = TILE_TYPES.floor; me.type = TILE_TYPES.floor;
} }
} },
}, },
exit: { exit: {
on_arrive(me, level, other) { on_arrive(me, level, other) {
if (other.type.is_player) { if (other.type.is_player) {
level.win(); level.win();
} }
} },
}, },
}; };