|
|
@ -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 { |
|
|
|
class SnekGame { |
|
|
|
constructor(settings, canvas, rules) { |
|
|
|
constructor(settings, canvas, rules) { |
|
|
@ -30,6 +30,8 @@ class SnekGame { |
|
|
|
case 'B': return PORTAL_B; |
|
|
|
case 'B': return PORTAL_B; |
|
|
|
case 'C': return PORTAL_C; |
|
|
|
case 'C': return PORTAL_C; |
|
|
|
case 'D': return PORTAL_D; |
|
|
|
case 'D': return PORTAL_D; |
|
|
|
|
|
|
|
case 'k': return KEY; |
|
|
|
|
|
|
|
case 'K': return DOOR; |
|
|
|
} |
|
|
|
} |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
} |
|
|
|
} |
|
|
@ -101,6 +103,12 @@ class SnekGame { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.portals={}; |
|
|
|
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
|
|
|
|
// add the snake to the world
|
|
|
@ -225,6 +233,8 @@ class SnekGame { |
|
|
|
const portalB=assets.get('portalB'); |
|
|
|
const portalB=assets.get('portalB'); |
|
|
|
const portalC=assets.get('portalC'); |
|
|
|
const portalC=assets.get('portalC'); |
|
|
|
const portalD=assets.get('portalD'); |
|
|
|
const portalD=assets.get('portalD'); |
|
|
|
|
|
|
|
const key=assets.get('key'); |
|
|
|
|
|
|
|
const door=assets.get('door'); |
|
|
|
const putTile=(x, y, tile) => this.ctx.drawImage( |
|
|
|
const putTile=(x, y, tile) => this.ctx.drawImage( |
|
|
|
tile, |
|
|
|
tile, |
|
|
|
offsetX+cellSize*x, |
|
|
|
offsetX+cellSize*x, |
|
|
@ -299,6 +309,13 @@ class SnekGame { |
|
|
|
case PORTAL_D_S: |
|
|
|
case PORTAL_D_S: |
|
|
|
putTileAnim(x, y, portalD); |
|
|
|
putTileAnim(x, y, portalD); |
|
|
|
break; |
|
|
|
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
|
|
|
|
// you hit, you die
|
|
|
|
case WALL: return this.die("thought walls were edible", "hit a wall"); |
|
|
|
case WALL: return this.die("thought walls were edible", "hit a wall"); |
|
|
|
case FIRE: return this.die("burned to a crisp", "hit fire"); |
|
|
|
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 SNAKE: |
|
|
|
case HOLE_S: |
|
|
|
case HOLE_S: |
|
|
|
case FLAMMABLE_S: |
|
|
|
case FLAMMABLE_S: |
|
|
@ -546,6 +566,11 @@ class SnekGame { |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
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
|
|
|
|
// you eat, you grow
|
|
|
|
case FOOD: |
|
|
|
case FOOD: |
|
|
|
// re-grow the snake partially (can't hit the tail, but it's there for all other intents and purposes
|
|
|
|
// re-grow the snake partially (can't hit the tail, but it's there for all other intents and purposes
|
|
|
|