Teleporation works !
This commit is contained in:
		
							
								
								
									
										13
									
								
								script.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								script.js
									
									
									
									
									
								
							@@ -216,7 +216,7 @@ async function startGame(gameID) {
 | 
			
		||||
    if(level.hasOwnProperty("teleportation"))
 | 
			
		||||
        level.teleportation.forEach((f) => {
 | 
			
		||||
            map[f[0]-1][f[1]-1] = TELEPORTATION
 | 
			
		||||
            teleportationCells.push(JSON.stringify([f[0]-1,f[1]-1]));
 | 
			
		||||
            teleportationCells.push([f[0]-1,f[1]-1]);
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -283,6 +283,15 @@ async function startGame(gameID) {
 | 
			
		||||
                    score++;
 | 
			
		||||
                    break;
 | 
			
		||||
                
 | 
			
		||||
                case TELEPORTATION:
 | 
			
		||||
 | 
			
		||||
                    // Teleport the snake to the other cell
 | 
			
		||||
                    const possibleDestinations = teleportationCells.filter((v) => v[0] != newHead[0] && v[1] != newHead[1]);
 | 
			
		||||
                    const chosenDestination = possibleDestinations[randInt(0, possibleDestinations.length)];
 | 
			
		||||
                    newHead[0] = chosenDestination[0]
 | 
			
		||||
                    newHead[1] = chosenDestination[1]
 | 
			
		||||
                    break;
 | 
			
		||||
                
 | 
			
		||||
                case ICE_SNAKE:
 | 
			
		||||
                case SNAKE:
 | 
			
		||||
                case WALL:
 | 
			
		||||
@@ -301,7 +310,7 @@ async function startGame(gameID) {
 | 
			
		||||
                map[oldPos[0]][oldPos[1]] = map[oldPos[0]][oldPos[1]] == ICE_SNAKE ? ICE : EMPTY
 | 
			
		||||
 | 
			
		||||
                // If the cell was a teleportation cell, then revert it back to the right state
 | 
			
		||||
                if(teleportationCells.includes(JSON.stringify(oldPos)))
 | 
			
		||||
                if(teleportationCells.find((e) => e[0] === oldPos[0] && e[1] === oldPos[1]) != undefined)
 | 
			
		||||
                    map[oldPos[0]][oldPos[1]] = TELEPORTATION
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user