Difference between revisions of "Critter"
From CodeStuff
| Line 22: | Line 22: | ||
clear(); | clear(); | ||
fillCircle(critter.x,critter.y,5); | fillCircle(critter.x,critter.y,5); | ||
| − | } | + | } |
run(move,draw); | run(move,draw); | ||
| Line 92: | Line 92: | ||
clear(); | clear(); | ||
fillCircle(critter.x,critter.y,5); | fillCircle(critter.x,critter.y,5); | ||
| − | } | + | } |
run(move,draw); | run(move,draw); | ||
| Line 198: | Line 198: | ||
function drawCritter(critter) { | function drawCritter(critter) { | ||
fillCircle(critter.x,critter.y,5); | fillCircle(critter.x,critter.y,5); | ||
| − | } | + | } |
function move() { | function move() { | ||
Revision as of 21:10, 29 May 2014
- Start with a simple critter.
- Make a variable called critter with x and y parts.
- Draw a dot to show it.
- Make the critter move
- make a move function to change the critter x and y.
- Make a draw function to clear the screen and draw the critter at the new position.
- make a wrap-around world
- set a world width and a world height
- if the critter is past the left edge (x<0) move it to the right edge
- if the critter is past the right edge (x>worldWidth) move it to the left edge
- if the critter is past the top edge (y<0) move it to the bottom edge
- if the critter is past the bottom edge (y>worldHeight) move it to the top edge
- give the critter some direction
- add dx and dy parts to the critter
- instead of adding fixed amounts to the critter position each time add the dx and dy values
- change the dx and dy values a little bit each time it moves.
- Make more critters
- We'll make several critters with individual names
- make a function to move a single critter
- make a function to draw a single critter
- use the functions to draw each critter in turn.
- put the critters in a list.
- instead of moving and drawing critters by name, make a list of critters
- make a variable called allCritters to hold a list of critters
- use allCritters.each() to call the move and draw functions for every critter