xxxxxxxxxx
99
var x=50 //position of bird in x
var grav=-2 //gravity
var y=200 // position of bird in y
var p1y=225 //pipe 1 y
var p1x=230// pipe 1 x
var ph=35// pipe height
var pw=130 // pipe width
var pw1=130
var p2y=225 // pipe 2 y
var p2x=0 //pipe 2 x
var p3y=450// pipe 3 y
var p3x=0//pipe 3 x
var p4y=450//pipe 4 y
var p4x=230//pipe 4 x.
var Cd=40// circle diamter
var hit = false// collision detection
var score=0
var scroll=0
var pipeMove = 0
var pipeMove1 = 0
var timer = 0
function preload() {
img = loadImage("bird.png")
img1 = loadImage("pipe1.png")
img2 = loadImage("pipe2.png")
img4 = loadImage('backround.png');
soundFormats('mp3');
Theme = loadSound('Theme.mp3')
}
function setup() {
createCanvas(450, 400);
Theme.play();
Theme.setVolume(0.5);
if (hit==true) {
Theme.pause();
}
}
function draw() {
y=200
timer=timer+1
if (timer==180) {
score=score+1
timer=0
}
pipeMove = pipeMove - 1
pipeMove1 = pipeMove1 - 1
scroll = scroll - 1
if (scroll == -550) {
scroll = 0
}
y=y-grav
image(img4,0+scroll,0)
image(img4,550+scroll,0)
image (img,x-22,y-22,Cd,Cd)
if (keyIsPressed) {
y=y-7
}
if (x==550) {
x=0
y=200
}
if (y==350) {
noLoop()
}
if (y==0) {
noLoop()
}
if (pipeMove <= -300) {
pipeMove = 220
pw= random(130,100)
}
if (pipeMove1 <= -470) {
pipeMove1 = 60
pw1= random(130,100)
}
image (img1, p1y+pipeMove,p1x, ph, pw)
image (img2, p1y+pipeMove,p2x,ph,pw)
image (img2, p3y+pipeMove1, p3x, ph, pw1)
image (img1, p3y+pipeMove1, p4x, ph, pw1)
hit = (collideRectCircle(p1y+pipeMove,p1x,ph,pw,x,y,Cd) || collideRectCircle(p2y+pipeMove,p2x,ph,pw,x,y,Cd) || collideRectCircle(p3y+pipeMove1,p3x,ph,pw,x,y,Cd) || (p4y+pipeMove1,p4x,ph,pw,x,y,Cd));
if (hit==true) {
noLoop()
}
//y=200
text (score, 250, 45)
textSize (40)
fill(255)
}