Go Back
snake game mechanics
Getting Started
- make a new repl html, css, js project
- copy the lesson 5
index.html, script.js, and style.css code into the repl
- we are going to debug model, view, and control functionality.
- model view control is an excellent design for games. (review lesson 2 for details on MVC)
Debugging View()
- ctrl-f "function view"
- the view function clears the last frame, redraws the background, and redraws the snake
- the viewSnake function is broken, read the comments in it and fix the function.
- press the r key, what does it do?
Debugging Control()
- ctrl-f "function control"
- see the S key controls which work. make the W,A,and D keys work.
Debugging Model()
- ctrl f "function model". the model() function calls a function that moves the snake every frame
- read the comments in the move function, and fix the move function so that the tail of the snake recedes when
the head of the snake extends.
Wrapping Up
- publish the lesson as a website on github pages (see lesson 2 instructions)