Go Back

snake game mechanics



    Getting Started
  1. make a new repl html, css, js project
  2. copy the lesson 5 index.html, script.js, and style.css code into the repl
  3. we are going to debug model, view, and control functionality.
  4. model view control is an excellent design for games. (review lesson 2 for details on MVC)
    Debugging View()
  1. ctrl-f "function view"
  2. the view function clears the last frame, redraws the background, and redraws the snake
  3. the viewSnake function is broken, read the comments in it and fix the function.
  4. press the r key, what does it do?
    Debugging Control()
  1. ctrl-f "function control"
  2. see the S key controls which work. make the W,A,and D keys work.
    Debugging Model()
  1. ctrl f "function model". the model() function calls a function that moves the snake every frame
  2. 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
  1. publish the lesson as a website on github pages (see lesson 2 instructions)