Add teleportation object
This commit is contained in:
parent
87b80d30d8
commit
f9aa6a469b
@ -1,12 +1,15 @@
|
||||
{
|
||||
"minDelay": 100,
|
||||
"acceleration": 1,
|
||||
"dimensions": [40, 40],
|
||||
|
||||
"delay": 200,
|
||||
"acceleration": 1,
|
||||
"minDelay": 100,
|
||||
|
||||
"walls": [
|
||||
[5,5], [5,6], [5,7], [5,8], [40, 35], [38, 35], [23, 35]
|
||||
],
|
||||
"randWallFreq": 5000,
|
||||
|
||||
"food": [
|
||||
[10,10],
|
||||
[11,10],
|
||||
@ -16,6 +19,7 @@
|
||||
[20, 23],
|
||||
[20, 21]
|
||||
],
|
||||
"randFoodFreq": 2000,
|
||||
|
||||
"ice": [
|
||||
[15,15],
|
||||
@ -32,7 +36,12 @@
|
||||
[17,18]
|
||||
],
|
||||
|
||||
"randFoodFreq": 2000,
|
||||
"teleportation": [
|
||||
[35, 5],
|
||||
[5, 35]
|
||||
],
|
||||
|
||||
|
||||
"snake": [
|
||||
[4,2], [4,1], [3,1], [2,1]
|
||||
],
|
||||
|
16
script.js
16
script.js
@ -15,6 +15,7 @@ const WALL = i++;
|
||||
const FOOD = i++;
|
||||
const ICE = i++;
|
||||
const ICE_SNAKE = i++; // If the snake is on the ice
|
||||
const TELEPORTATION = i++;
|
||||
delete i;
|
||||
|
||||
/**
|
||||
@ -194,18 +195,28 @@ async function startGame(gameID) {
|
||||
}
|
||||
|
||||
/// ... then with cells content
|
||||
// Walls
|
||||
level.walls.forEach((w) => {
|
||||
map[w[0]-1][w[1]-1] = WALL
|
||||
})
|
||||
|
||||
// Food
|
||||
level.food.forEach((f) => {
|
||||
map[f[0]-1][f[1]-1] = FOOD
|
||||
})
|
||||
|
||||
// Ice
|
||||
if(level.hasOwnProperty("ice"))
|
||||
level.ice.forEach((f) => {
|
||||
map[f[0]-1][f[1]-1] = ICE
|
||||
})
|
||||
|
||||
// Teleportation
|
||||
if(level.hasOwnProperty("teleportation"))
|
||||
level.teleportation.forEach((f) => {
|
||||
map[f[0]-1][f[1]-1] = TELEPORTATION
|
||||
})
|
||||
|
||||
|
||||
level.snake.forEach((s) => {
|
||||
map[s[0]-1][s[1]-1] = SNAKE
|
||||
@ -328,6 +339,11 @@ async function startGame(gameID) {
|
||||
case FOOD:
|
||||
ctx.drawImage(imgApple, x*cell_width, y*cell_height, cell_width, cell_height);
|
||||
break;
|
||||
|
||||
case TELEPORTATION:
|
||||
ctx.fillStyle = "gray";
|
||||
ctx.fillRect(x*cell_width, y*cell_height, cell_width, cell_height)
|
||||
break;
|
||||
|
||||
case ICE:
|
||||
case ICE_SNAKE:
|
||||
|
Loading…
Reference in New Issue
Block a user