Difference between revisions of "Today"

From CodeStuff
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 19: 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 gameOver = { image : loadImage("http://fingswotidun.com/images/GameOver.png"),
 +
                x:0, y: -10000,
 +
                endx: 0, endy: 150};
 +
               
 
var gameAge=0;
 
var gameAge=0;
 
var stillAlive=true;
 
var stillAlive=true;
Line 35: Line 39:
  
 
addChaser(200,100);
 
addChaser(200,100);
addChaser(300,100,0.5);
+
addChaser(300,400,0.5);
 +
addChaser(400,400,0.45,"magenta");
  
 
function drawSpot(colour,x,y) {
 
function drawSpot(colour,x,y) {
Line 63: Line 68:
 
}
 
}
  
function move() {     
+
function play() {     
 
   var dx = c.x-c.lastx;
 
   var dx = c.x-c.lastx;
 
   var dy = c.y-c.lasty;
 
   var dy = c.y-c.lasty;
Line 112: Line 117:
 
   for (var meep of chasers) {
 
   for (var meep of chasers) {
 
     moveTowards(meep,c);
 
     moveTowards(meep,c);
 +
   
 +
    if ( distance(meep,c) < 8) {
 +
      stillAlive=false;
 +
    }
 
   }
 
   }
 +
 +
  if ( (gameAge %300) === 0) {
 +
    var newX = Math.random() * 640;
 +
    var newY = Math.random() * 480;
 +
   
 +
    addChaser(newX,newY,0.45+ gameAge/3000,"magenta");
 +
  }
 +
}
 +
 +
function draw() {
  
 
   clear();
 
   clear();
Line 125: Line 144:
 
   setColour("black");
 
   setColour("black");
 
   print("the game age is "+gameAge);
 
   print("the game age is "+gameAge);
   print(gameAge % 100);
+
   print(gameAge % 300);
 +
 
 +
  drawImage(gameOver.image,gameOver.x,gameOver.y);
 
}
 
}
  
 +
function move() {
 +
  gameAge+=1;
 +
  if (stillAlive) {
 +
    play(); 
 +
  } else {
 +
 +
  }
 +
 
 +
  if (keyIsDown(32)) {
 +
  stillAlive=false;
 +
  }
 +
  draw();
 +
}
  
 
run(move);
 
run(move);

Latest revision as of 22:51, 6 July 2017

Useful things to refer to.

The API page has a list of some of the functions you can use such as