Utilise les touches directionnelles pour diriger Carré Orange, appuie sur la barre d'espace pour ajouter instantanément 3 nouveaux carrés blancs.
xxxxxxxxxx
var wallTop, wallBottom, wallLeft, wallRight;
var WALL_THICKNESS = 100;
var sprite2;
var sprite3;
var sprite4;
// Sprite dirigé
var sprite;
var spriteImg;
var backgroundImg
function preload () {
backgroundImg = loadImage('motif.png')
spriteImg = loadImage('ernest.png');
}
function setup() {
createCanvas(600, 600);
wallTop = createSprite(width/2, -WALL_THICKNESS/2, width+WALL_THICKNESS*2, WALL_THICKNESS);
wallTop.immovable = true;
wallBottom = createSprite(width/2, height+WALL_THICKNESS/2, width+WALL_THICKNESS*2, WALL_THICKNESS);
wallBottom.immovable = true;
wallLeft = createSprite(-WALL_THICKNESS/2, height/2, WALL_THICKNESS, height);
wallLeft.immovable = true;
wallRight = createSprite(width+WALL_THICKNESS/2, height/2, WALL_THICKNESS, height);
wallRight.immovable = true;
sprite = createSprite(width/2, height/2, 40, 40);
sprite.shapeColor = color(244,97,33);
sprite.velocity.y = 4;
sprite2 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite2.shapeColor = color(255);
sprite2.velocity.y = random(8);
sprite2.velocity.x = random(8);
sprite2.position.x = random(0, 600);
sprite2.position.y = random(0, 600);
sprite3 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite3.shapeColor = color(255);
sprite3.velocity.y = random(8);
sprite3.velocity.x = random(8);
sprite3.position.x = random(0, 600);
sprite3.position.y = random(0, 600);
sprite4 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite4.shapeColor = color(255);
sprite4.velocity.y = random(8);
sprite4.velocity.x = random(8);
sprite4.position.x = random(0, 600);
sprite4.position.y = random(0, 600);
}
function draw() {
image(backgroundImg,0,0);
textSize(40);
fill(249,120,63);
text("EVITE LES CARRES BLANCS", 30,35);
strokeWeight(20)
textSize(40);
text("OU CHANGE TOI EN SINGE",35,590);
fill (249,120,63);
//rite.position.x = mouseX;
//rite.position.y = mouseY;
sprite.bounce(wallTop);
sprite.bounce(wallLeft);
sprite.bounce(wallRight);
sprite.bounce(wallBottom);
sprite2.bounce(wallTop);
sprite2.bounce(wallLeft);
sprite2.bounce(wallRight);
sprite2.bounce(wallBottom);
sprite3.bounce(wallTop);
sprite3.bounce(wallLeft);
sprite3.bounce(wallRight);
sprite3.bounce(wallBottom);
sprite4.bounce(wallTop);
sprite4.bounce(wallLeft);
sprite4.bounce(wallRight);
sprite4.bounce(wallBottom);
if (sprite2.overlap(sprite)) {
sprite.addImage(spriteImg);
}
if (sprite3.overlap(sprite)) {
sprite.addImage(spriteImg);
}
if (sprite4.overlap(sprite)) {
sprite.addImage(spriteImg);
}
drawSprites();
}
function keyPressed() {
if (keyCode == RIGHT_ARROW) {
sprite.setSpeed(10, 0);
}
else if (keyCode == DOWN_ARROW) {
sprite.setSpeed(10, 90);
}
else if (keyCode == LEFT_ARROW) {
sprite.setSpeed(10, 180);
}
else if (keyCode == UP_ARROW) {
sprite.setSpeed(10, 270);
}
if (key == ' ') {
sprite2 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite2.shapeColor = color(236,232,69);
sprite2.velocity.y = random(8);
sprite2.velocity.x = random(8);
sprite2.position.x = random(0, 600);
sprite2.position.y = random(0, 600);
sprite3 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite3.shapeColor = color(229,236,35);
sprite3.velocity.y = random(8);
sprite3.velocity.x = random(8);
sprite3.position.x = random(0, 600);
sprite3.position.y = random(0, 600);
sprite4 = createSprite(width/2, height/2, random(30, 50), random(30, 50));
sprite4.shapeColor = color(240,229,41);
sprite4.velocity.y = random(8);
sprite4.velocity.x = random(8);
sprite4.position.x = random(0, 600);
sprite4.position.y = random(0, 600);
}
return false;
}