xxxxxxxxxx
134
var x, y;
var shot;
var speed;
var speed2;
let img;
let img2;
let img3;
let img4;
let gamestatus = "homescreen";
let timer = 60;
let backgroundMusic, gunShot
function preload(){
duckImg = loadImage('duck.png')
deadDuck = loadImage('deadDuck.png')
backGround = loadImage('background.png')
gunFlash = loadImage('gunFlash.png')
menu = loadImage('menu.png')
backgroundMusic = loadSound('Intro.mp3')
gunShot = loadSound('Gunshot.mp3')
}
function setup() {
createCanvas(600, 400);
x = random(5, 390);
y = 400;
speed = random(4, 8);
speed2 = random(-1,1);
score=0;
shot = false;
backgroundSound();
}
function backgroundSound(){
backgroundMusic.play();
backgroundMusic.loop();
backgroundMusic.setVolume(0.3);
userStartAudio();
}
function draw() {
if(gamestatus=='homescreen'){
background(menu);
textSize(15);
text("Click anywhere to start!",100,300)
}
if(gamestatus == "running")
{
image(backGround, 0, 0, 600, 400);
fill(0, 0, 0);
textSize(30);
text("Time Left:" + timer, 25, 380)
if (frameCount % 60 == 0 && timer > 0) {
timer --;
}
if (timer == 0) {
window.location.reload();
}
if (shot==false){
duck(duckImg);
}
//text
push();
textSize(30);
fill(0,0,0);
text("Score: 000" + score, 420, 380);
pop();
if (dist(x, y, mouseX, mouseY) < 40) {
if (mouseIsPressed) {
shot = true;
}
}
y = y - speed;
x = x + speed2;
if (y < random(-10, -1000)) {
y = 420;
x = random(5, 590);
speed2 = random(-1, 1) ;
}
if (shot == true) {
speed = -7;
speed2 = 0
push();
noStroke();
fill(220);
duck(deadDuck);
pop();
if (y > 440) {
shot = false;
x = random(5, 580);
speed = random(4,12);
speed2 = random(-7,7);
score += 1;
}
}
if (mouseIsPressed) {
image(gunFlash, mouseX-75, mouseY-80,200,200)
target(mouseX,mouseY);
}
target(mouseX, mouseY);
}
}
function target(i, o) {
push();
stroke(2);
fill(0, 0, 0, 0);
ellipse(i, o, 15);
ellipse(i, o, 50);
stroke(255, 0, 0);
line(i, o + 8, i, o + 30);
line(i, o - 8, i, o - 30);
line(i + 8, o, i + 30, o);
line(i - 8, o, i - 30, o);
pop();
}
function duck(q) {
noStroke();
fill(100, 200, 100)
image(q,x-50,y-50,100,100);
}
function mousePressed(){
if(gamestatus=="homescreen"){
gamestatus="running";
}
}