Difference between revisions of "Today"
From CodeStuff
| Line 6: | Line 6: | ||
*[[Keycodes]] | *[[Keycodes]] | ||
*[[Functions]] | *[[Functions]] | ||
| + | *[[Loops]] | ||
*[[Aiming]] | *[[Aiming]] | ||
| Line 18: | Line 19: | ||
<edcode>var c = {x:320, y:240, lastx:320, lasty:240, power:0.1, penSize:4}; | <edcode>var c = {x:320, y:240, lastx:320, lasty:240, power:0.1, penSize:4}; | ||
| − | var mary = {x:200, y:240}; | + | var gameAge=0; |
| − | var frank = {x:380, y:240}; | + | var stillAlive=true; |
| − | var bob = {x:580, y:100}; | + | |
| + | var mary = {x:200, y:240, speed:0.35,colour:"blue"}; | ||
| + | var frank = {x:380, y:240, speed:0.2,colour:"cyan"}; | ||
| + | var bob = {x:580, y:100, speed: 0.25,colour:"lightgreen"}; | ||
var chasers = [mary,frank,bob]; | var chasers = [mary,frank,bob]; | ||
| − | function drawSpot(x,y) { | + | chasers.add({x:100,y:100}); |
| + | |||
| + | function addChaser(x,y,speed=0.3,colour="yellow") { | ||
| + | chasers.add({x,y,speed,colour}); | ||
| + | } | ||
| + | |||
| + | addChaser(200,100); | ||
| + | addChaser(300,100,0.5); | ||
| + | |||
| + | function drawSpot(colour,x,y) { | ||
setColour("red"); | setColour("red"); | ||
fillCircle(x,y,10); | fillCircle(x,y,10); | ||
| − | setColour( | + | setColour(colour); |
| − | fillCircle(x,y, | + | fillCircle(x,y,8); |
} | } | ||
function moveTowards(seeker,target) { | function moveTowards(seeker,target) { | ||
if (seeker.y < target.y) { | if (seeker.y < target.y) { | ||
| − | seeker.y+= | + | seeker.y+=seeker.speed; |
} | } | ||
if (seeker.y > target.y) { | if (seeker.y > target.y) { | ||
| − | seeker.y-= | + | seeker.y-=seeker.speed; |
} | } | ||
if (seeker.x <target.x) { | if (seeker.x <target.x) { | ||
| − | seeker.x+= | + | seeker.x+=seeker.speed; |
} | } | ||
if (seeker.x > target.x) { | if (seeker.x > target.x) { | ||
| − | seeker.x-= | + | seeker.x-=seeker.speed; |
} | } | ||
| Line 96: | Line 109: | ||
} | } | ||
| − | //move | + | //move chasers towards c |
| − | + | for (var meep of chasers) { | |
| − | + | moveTowards(meep,c); | |
| − | + | } | |
| − | + | ||
| − | + | ||
| − | + | ||
clear(); | clear(); | ||
| Line 108: | Line 119: | ||
fillCircle(c.x,c.y,c.penSize); | fillCircle(c.x,c.y,c.penSize); | ||
| − | + | for (var q of chasers) { | |
| − | + | drawSpot(q.colour,q.x,q.y); | |
| − | + | } | |
| − | + | ||
setColour("black"); | setColour("black"); | ||
| − | print(" | + | print("the game age is "+gameAge); |
| + | print(gameAge % 100); | ||
} | } | ||
| + | |||
run(move); | run(move); | ||
| + | |||
</edcode> | </edcode> | ||
Revision as of 23:26, 3 July 2017
Useful things to refer to.
The API page has a list of some of the functions you can use such as