Snake.y = canvas.height / 2 + snake.size / 2 įor (let i = snake.x + (5 * snake.size) i >= snake.x i -= snake.size), // update x and y depending on direction and speedĪll of these are unaware of each other. Snake.x = canvas.width / 2 + snake.size / 2 Let canvas = document.getElementById("game_field") Snake.js represents the snake object and its behavior import game from './game' I've tried to split the code to store each of these objects in a separate module and import all of these in the main application file, so I have the main main.js file, snake.js file, game.js and food.js. The game involves a game object, snake object and food object. The game is a classic snake game - user controls the snake with arrow keys, when snake collides with food it grows, when the snake collides with screen border or itself it dies and the game's over. The codebase is not big and it seems to be a pretty nice exercise to me. I've decided to try to split its code to modules. Recently I've been practicing with canvas and rewriting one of the popular snake game realizations. I'm trying to reach good understanding of how to build scalable modular application structure.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |