xxxxxxxxxx
168
var sun_moon, hair, head, body, hand1, hand2, leg1, leg2, ground, CannonGroup, gameOver;
var textVisible = false;
function setup() {
createCanvas(400, 400);
sun_moon = createSprite(350, 50, 50, 50);
ground = createSprite(200, 350, 400, 100);
head = createSprite(200, 110, 50, 50);
hair = createSprite(200, 90, 70, 20);
leg2 = createSprite(230, 300, 20, 100);
hand1 = createSprite(120, 170, 80, 20);
hand2 = createSprite(280, 170, 80, 20);
leg1 = createSprite(170, 300, 20, 100);
body = createSprite(200, 200, 80, 120);
CannonGroup = createGroup();
sun_moon.shapeColor = (252, 212, 64);
ground.shapeColor = "beige";
head.shapeColor = "red";
hair.shapeColor = "black";
leg2.shapeColor = "blue";
hand1.shapeColor = "fuchsia";
hand2.shapeColor = "fuchsia";
leg1.shapeColor = "blue";
body.shapeColor = "violet";
}
function draw() {
background("cyan");
hair.x = mouseX;
hair.y = mouseY - 100;
head.x = mouseX;
head.y = mouseY - 85;
body.x = mouseX;
body.y = mouseY;
hand1.x = mouseX - 80;
hand1.y = mouseY - 30;
hand2.x = mouseX + 80;
hand2.y = mouseY - 30;
leg1.x = mouseX - 30;
leg1.y = mouseY + 90;
leg2.x = mouseX + 30;
leg2.y = mouseY + 90;
if (mouseIsPressed) {
background(46, 68, 130);
head.shapeColor = "maroon";
hair.shapeColor = "black";
leg2.shapeColor = "navy";
hand1.shapeColor = "purple";
hand2.shapeColor = "purple";
leg1.shapeColor = "navy";
body.shapeColor = "yellow";
ground.shapeColor = (194, 178, 128);
sun_moon.shapeColor = (244, 241, 201);
} else {
sun_moon.shapeColor = "yellow";
head.shapeColor = "red";
hair.shapeColor = "black";
leg2.shapeColor = "blue";
hand1.shapeColor = "fuchsia";
hand2.shapeColor = "fuchsia";
leg1.shapeColor = "blue";
body.shapeColor = "violet";
ground.shapeColor = "beige";
}
spawnCannons();
drawSprites();
fill("black");
textSize(15);
if (mouseIsPressed) {
text("Lights Out", body.x - 34, body.y + 5);
} else {
text("Click Me", body.x - 30, body.y + 5);
}
}
function spawnCannons() {
var cannon;
cannon = createSprite(440, 200, 30, 30);
if (frameCount % 30 === 0) {
cannon.velocityX = -15;
cannon.y = random(15, 385);
cannon.shapeColor = "orange";
cannon.lifetime = 140;
CannonGroup.add(cannon);
}
if(CannonGroup.isTouching(head) && head.visible === true && hair.visible === true){
head.visible = false;
hair.visible = false;
CannonGroup.destroyEach();
cannon = createSprite(440, 200, 30, 30);
}
if(CannonGroup.isTouching(hand1 || hand2) && hand1.visible === true && hand2.visible === true){
hand1.visible = false;
hand2.visible = false;
CannonGroup.destroyEach();
cannon = createSprite(440, 200, 30, 30);
}
if(CannonGroup.isTouching(body) && body.visible === true){
body.visible = false;
CannonGroup.destroyEach();
cannon = createSprite(440, 200, 30, 30);
}
if(CannonGroup.isTouching(leg1 || leg2) && leg1.visible === true && leg2.visible === true){
leg1.visible = false;
leg2.visible = false;
CannonGroup.destroyEach();
cannon = createSprite(440, 200, 30, 30);
}
if(head.visible === false && leg2.visible === false && body.visible === false && hand2.visible === false){
textVisible = true;
}
if(textVisible === true){
fill("black");
textSize(30);
text("YOU LOSE",120,190);
CannonGroup.destroyEach();
}
}
function mouseReleased(){
if(textVisible === false){
CannonGroup.setVelocityXEach(-15);
head.visible = true;
leg1.visible = true;
body.visible = true ;
hand1.visible = true;
leg2.visible = true;
hair.visible = true ;
hand2.visible = true;
}
}
function keyPressed(){
textVisible = false;
}