xxxxxxxxxx
168
var redballoon, red, background1, backgroundimage;
var greenballoon, green;
var blueballoon, blue;
var pinkballoon, pink;
var bow, bow1, arrow, arrow1, temparrow, x;
var balloon, rand, score;
var redg, greeng, pinkg, blueg, arrowg;
function preload() {
//load your images here
backgroundimage = loadImage("background0.png");
red = loadImage("red_balloon0.png");
green = loadImage("green_balloon0.png");
blue = loadImage("blue_balloon0.png");
pink = loadImage("pink_balloon0.png");
bow1 = loadImage("bow0.png");
arrow1 = loadImage("arrow0.png");
}
function setup() {
createCanvas(400, 400);
//add code here
background1 = createSprite(0, 0, 400, 400)
background1.addImage(backgroundimage);
background1.scale = 2;
background1.velocityX = -3
bow = createSprite(350, 200, 20, 20);
bow.addImage(bow1);
redg = new Group();
pinkg = new Group();
greeng = new Group();
blueg = new Group();
arrowg = new Group();
score = 0
}
function draw() {
if (background1.x <= 0) {
background1.x = background1.width / 2
}
// console.log(rand);
rand = Math.round(random(1, 4));
bow.y = mouseY;
if (frameCount % 80 === 0) {
if (rand === 1) {
sredballoon();
redballoon.y = random(10, 380)
redballoon.velocityX = 6;
} else if (rand === 2) {
sgreenballoon();
greenballoon.y = random(10, 380)
greenballoon.velocityX = 6;
} else if (rand === 3) {
sblueballoon();
blueballoon.y = random(10, 380)
blueballoon.velocityX = 6;
} else if (rand === 4) {
spinkballoon()
pinkballoon.y = random(10, 380)
pinkballoon.velocityX = 6;
}
}
if (keyDown("space")) {
createarrow();
arrowg.setVelocityxEach = -6;
arrow.velocityX = -6;
}
if (redg.isTouching(arrowg)) {
score = score + 3
redg.destroyEach();
arrowg.destroyEach();
}
if (blueg.isTouching(arrowg)) {
score = score + 4
blueg.destroyEach();
arrowg.destroyEach();
}
if (greeng.isTouching(arrowg)) {
score = score + 2
greeng.destroyEach();
arrowg.destroyEach();
}
if (pinkg.isTouching(arrowg)) {
score = score + 1
pinkg.destroyEach();
arrowg.destroyEach();
}
console.log(score);
drawSprites();
text("score:" + score, 200, 20);
}
function createarrow() {
arrow = createSprite(350, bow.y, 20, 20)
arrow.addImage(arrow1);
arrow.scale = 0.3;
arrow.velocityx = -6;
arrow.lifetime = 60
arrowg.add(arrow);
}
function sredballoon() {
redballoon = createSprite(50, 100, 20, 50)
redballoon.addImage(red);
redballoon.scale = 0.1
redballoon.lifetime = 60;
redballoon.debug = true;
redballoon.setCollider('circle', 0, 0, 100)
redg.add(redballoon);
}
function sgreenballoon() {
greenballoon = createSprite(50, 100, 20, 50)
greenballoon.addImage(green);
greenballoon.scale = 0.1
greenballoon.lifetime = 60;
greenballoon.debug = true;
greenballoon.setCollider('circle', 0, 0, 200)
greeng.add(greenballoon);
}
function sblueballoon() {
blueballoon = createSprite(50, 100, 20, 50);
blueballoon.addImage(blue);
blueballoon.scale = 0.1
blueballoon.lifetime = 60;
blueballoon.debug = true;
blueballoon.setCollider('circle', 0, 0, 100)
blueg.add(blueballoon);
}
function spinkballoon() {
pinkballoon = createSprite(50, 100, 20, 50);
pinkballoon.addImage(pink);
pinkballoon.scale = 1.5
pinkballoon.lifetime = 60;
pinkballoon.debug = true;
pinkballoon.setCollider('circle', 0, 0, 25)
pinkg.add(pinkballoon);
}