Professional Documents
Culture Documents
----------------------------
function enter()
background('Scene1');
cursor(ARROW);
function loop()
clear();
drawIntroScreen();
function mouseClicked()
if (startGame)
showScene( "Game" );
function drawIntroScreen()
{
stroke(1);
fill("yellow");
noStroke();
fill("black");
textSize(24);
textAlign(CENTER);
textSize(12);
noFill();
stroke(1);
startGame = true;
Game
var balls;
var ballsDropped;
var ballsCaught;
function initGame()
balls = [];
ballsDropped = 0;
ballsCaught = 0;
addBall(balls);
function enter()
{
background('Scene2');
noCursor();
textSize(12);
textAlign(LEFT);
initGame();
function loop()
clear();
displayBalls(balls);
updateBalls(balls);
displayNeedle();
displayStats();
function displayNeedle()
stroke(1);
noFill();
function displayGlobalBalls()
displayBalls(balls);
function catchBall(ball)
ballsCaught++;
initBall(ball);
function displayBalls(arBalls)
displayBall( arBalls[i] );
}
function displayBall(ball)
fill(ball.color);
stroke(1);
noFill();
catchBall(ball);
function displayStats()
fill("black");
noStroke();
}
function updateBalls(arBalls)
updateBall( arBalls[i] );
function updateBall(ball)
ballsDropped++;
initBall(ball);
}
}
function addBall(arBalls)
initBall(ball);
arBalls.push(ball);
function initBall(ball)
ball.y = 10;
Game over
function enter()
background('Scene');
cursor(ARROW);
}
function loop()
clear();
fill("black");
noStroke();
textAlign(CENTER);
textSize(12);
function mouseClicked()
showScene( "Intro" );
}
MOVABLE CAR
var dx = 0;
var dy = 0;
function enter()
// Draw nose
// Draw mouth
function loop()
clear();
moveSelected();
displayShapes();
displayInstructions()
function moveSelected()
{
move = move && mouseIsPressed && selected != -1;
if (move)
else
move = mouseIsPressed;
if (selected != -1)
dx = mouseX - shapes[selected].x;
dy = mouseY - shapes[selected].y;
function displayShapes()
var o = shapes[i];
stroke(i == selected ? "red" : "black");
strokeWeight(1);
fill(o.color);
if (o.type == "rect")
function findShape(x, y)
var o = shapes[i];
if (o.type == "circle")
return i
}
return i;
return -1;
shapes.push({
type : "rect",
x : x,
y : y,
width : width,
height : height,
});
{
shapes.push({
type : "circle",
x : x,
y : y,
radius : radius,
});
function displayInstructions()
fill(0);
noStroke();