added keys and doors (closes #5) with temp assets

Nathan DECHER 5 years ago
parent a27b8fcd9e
commit c90bfd5103
  1. 2
      Makefile
  2. BIN
      assets/door.png
  3. BIN
      assets/key.png
  4. 2
      assets/levelList.json
  5. 13
      levels/puzzle2.json
  6. 4
      src/js/assets.js
  7. 27
      src/js/snek.js

@ -8,7 +8,7 @@ PORTAL_B_ANIM = $(foreach angle, $(shell seq 0 6 359), build/portal-b$(angle).pn
PORTAL_C_ANIM = $(foreach angle, $(shell seq 0 6 359), build/portal-c$(angle).png)
PORTAL_D_ANIM = $(foreach angle, $(shell seq 0 6 359), build/portal-d$(angle).png)
IMAGES = $(foreach name, apple wall oil, public/assets/$(name)32.png)
IMAGES = $(foreach name, apple wall oil key door, public/assets/$(name)32.png)
TILESETS = $(foreach name, hole, public/assets/$(name)-ts.png)
ANIMATIONS = $(foreach name, fire peach-decay peach-rainbow portal-a portal-b portal-c portal-d, public/assets/$(name)-anim.png)
JSON = $(foreach name, snake levelList config metaConfig, public/assets/$(name).json)

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

@ -58,7 +58,7 @@
"levelFilename": "puzzle<n>.json",
"levelDisplay": "Level <n>",
"levels": [
1
1, 2
],
"nextLevel": true
}

@ -0,0 +1,13 @@
{
"world": [
"k wA wf",
" w wB",
" w ww",
" fw ",
" w ",
" K f"
],
"snake": [
[0, 5]
]
}

@ -12,6 +12,8 @@ const assetSpecs=[
{ name: 'portalB', filename: 'portal-b-anim.png', type: 'image' },
{ name: 'portalC', filename: 'portal-c-anim.png', type: 'image' },
{ name: 'portalD', filename: 'portal-d-anim.png', type: 'image' },
{ name: 'key', filename: 'key32.png', type: 'image' },
{ name: 'door', filename: 'door32.png', type: 'image' },
{ name: 'snake', filename: 'snake.json', type: 'json' },
{ name: 'levelList', filename: 'levelList.json', type: 'json' },
{ name: 'config', filename: 'config.json', type: 'json' },
@ -19,7 +21,7 @@ const assetSpecs=[
];
const tasks=[
{ from: 'hole', type: 'tileset', steps: 3, tiles: ['base', 'ul', 'dr', 'dl', 'ur', 'l', 'r', 'd', 'u'] },
{ from: 'hole', type: 'tileset', steps: 1, tiles: ['base', 'ul', 'dr', 'dl', 'ur', 'l', 'r', 'd', 'u'] },
{ from: 'fire', type: 'animation', steps: 3 },
{ from: 'portalA', type: 'animation', steps: 3 },
{ from: 'portalB', type: 'animation', steps: 3 },

@ -1,4 +1,4 @@
const [EMPTY, FOOD, SUPER_FOOD, DECAY_FOOD, WALL, FIRE, FLAMMABLE, FLAMMABLE_S, HOLE, HOLE_S, PORTAL_A, PORTAL_A_S, PORTAL_B, PORTAL_B_S, PORTAL_C, PORTAL_C_S, PORTAL_D, PORTAL_D_S, SNAKE]=Array(255).keys();
const [EMPTY, FOOD, SUPER_FOOD, DECAY_FOOD, WALL, FIRE, FLAMMABLE, FLAMMABLE_S, HOLE, HOLE_S, PORTAL_A, PORTAL_A_S, PORTAL_B, PORTAL_B_S, PORTAL_C, PORTAL_C_S, PORTAL_D, PORTAL_D_S, KEY, DOOR, SNAKE]=Array(255).keys();
class SnekGame {
constructor(settings, canvas, rules) {
@ -30,6 +30,8 @@ class SnekGame {
case 'B': return PORTAL_B;
case 'C': return PORTAL_C;
case 'D': return PORTAL_D;
case 'k': return KEY;
case 'K': return DOOR;
}
})();
}
@ -101,6 +103,12 @@ class SnekGame {
} else {
this.portals={};
}
// add the keys
if(settings.keys) settings.keys.forEach(([x, y]) => this.world[x][y]=KEY);
// add the doors
if(settings.doors) settings.doors.forEach(([x, y]) => this.world[x][y]=DOOR);
}
// add the snake to the world
@ -225,6 +233,8 @@ class SnekGame {
const portalB=assets.get('portalB');
const portalC=assets.get('portalC');
const portalD=assets.get('portalD');
const key=assets.get('key');
const door=assets.get('door');
const putTile=(x, y, tile) => this.ctx.drawImage(
tile,
offsetX+cellSize*x,
@ -299,6 +309,13 @@ class SnekGame {
case PORTAL_D_S:
putTileAnim(x, y, portalD);
break;
case KEY:
putTile(x, y, key);
break;
case DOOR:
putTile(x, y, door);
break;
}
}
}
@ -512,6 +529,9 @@ class SnekGame {
// you hit, you die
case WALL: return this.die("thought walls were edible", "hit a wall");
case FIRE: return this.die("burned to a crisp", "hit fire");
case DOOR: return this.die("forgot to OPEN the door", "hit a door");
// congratilations, you played yourself!
case SNAKE:
case HOLE_S:
case FLAMMABLE_S:
@ -546,6 +566,11 @@ class SnekGame {
);
break;
// you eat, you destroy all doors
case KEY:
this.getTilesOfType(DOOR).forEach(([x, y]) => this.world[x][y]=EMPTY);
break;
// you eat, you grow
case FOOD:
// re-grow the snake partially (can't hit the tail, but it's there for all other intents and purposes

Loading…
Cancel
Save