Created
June 28, 2020 07:46
-
-
Save flushpot1125/066387a6196c00b7b6c74fcc67e220cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Direction {UP,DOWN,RIGHT,LEFT}; | |
document.onkeydown =(e)=>{ | |
if(e.keyCode == 32){//SPACE | |
console.log("Game start!"); | |
startGame(); | |
}else if (e.keyCode == 87){ //UP | |
moveSnake(Direction.UP); | |
}else if (e.keyCode ==83){ //DOWN | |
moveSnake(Direction.DOWN); | |
}else if (e.keyCode ==68){ //RIGHT | |
moveSnake(Direction.RIGHT); | |
}else if (e.keyCode ==65){ //LEFT | |
moveSnake(Direction.LEFT); | |
} | |
} | |
function moveSnake(snakeStep:Direction){ | |
var x,y,z:number; | |
if(snakeStep ==Direction.UP){ | |
x=y=0, z=1; | |
}else if (snakeStep==Direction.DOWN){ | |
x=y=0, z=-1; | |
}else if (snakeStep==Direction.RIGHT){ | |
x=1,y=z=0; | |
}else if (snakeStep=Direction.LEFT){ | |
x=-1,y,z=0; | |
} | |
snake.translate( new Vector3(x,y,z),6,Space.WORLD); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment