xxxxxxxxxx
178
/*
Flyfly Bird "game"
Basically just flappy bird
Image link: https://vectorportal.com/vector/bird-color-silhouette/23407
*/
var birdImage
var birdY
var wallX1
var wallY1
var wallDist
var state
var counter = 0
var restartTimer = 300
var interval = 60 * 5
var score = 0
var x
/*
States
0 = Play
1 = hit wall
2 = too low
3 = too high
*/
function preload() {
birdImage = loadImage('BirdImage.png')
}
function setup() { //Canvas, background, bird location, initialize wall, state 0 (gameplay)
createCanvas(1400, 1000);
background("rgb(78,99,105)")
birdY = 0
randomizewall()
state = 0
x = 0
}
function draw() {
if(state === 0){
background("rgb(78,99,105)")
image(birdImage, 50,birdY, 200, 200)
flight()
wall()
textSize(20)
textStyle(BOLD)
textAlign(LEFT)
text("Score: "+score, 20, 35)
if(wallDist < -wallX1){
randomizewall()
score += 1
// wall()
} else {
wallDist -= 2
}
if(birdY < -199){
high()
}
if(birdY+180 > height){
low()
}
if((birdY<wallHeight || birdY>(wallHeight+180)) && wallDist<200)
hit()
} //Game time, all the moving parts, end conditions
if(state != 0){
// counter = 0
// restartTimer = 300
counter++;
// text(counter, 10,30)
if(counter > restartTimer){
// setup()
// draw()
background("rgb(78,99,105)")
textSize(80)
textStyle(BOLD)
textAlign(CENTER, CENTER)
text("Click the mouse to try again!", width/3, height/2, (width)/3)
text("Score: "+score, width/2, height/4)
if((counter>restartTimer) && mouseIsPressed){
counter = 0;
setup()
draw()
state = 0;
score = 0;
}
}
} //restart screens
}
// function GameState(){
// state += 1
// if()
// }
function flight(){
if(mouseIsPressed) {
birdY -= 10
} else {
birdY += 5
}
} //Simple Flight up/down
function randomizewall(){
wallX1 = random(250, 350)
wallHeight = random(50, 600)
wallDist = random(1500, 2000)
} //Set random states for the wall
function wall(){
rect(wallDist,0, wallX1,wallHeight)
rect(wallDist,wallHeight+350, wallX1,1000)
wallDist -=10
} //make wall move left
function hit(){
state = 1
textSize(80)
textStyle(BOLD)
textAlign(CENTER, CENTER)
text("You tried to fly through a wall!", width/3, height/2, (width)/3)
} //hit the wall
function low(){
state = 2
textSize(80)
textStyle(BOLD)
textAlign(CENTER, CENTER)
text("Oh no! You've crashed into the ground", width/3, height/2, (width)/3)
} //fly too low
function high(){
state = 3
textSize(80)
textStyle(BOLD)
textAlign(CENTER, CENTER)
text("Didn't You learn not to fly too close to the sun?", width/3, height/2, (width)/3)
} //fly too high
/*
IDEAS FOR GHOST TRAIL?
var num = 60;
var mx = [];
var my = [];
function setup() {
createCanvas(windowWidth, windowHeight);
noCursor();
}
function draw() {
var array_pos = frameCount % num;
mx[array_pos] = mouseX;
my[array_pos] = mouseY;
background(255);
noStroke();
fill(255, 0, 0, 127);
for (var i = 0; i < num; i++) {
var index = (array_pos + 1 + i) % num;
ellipse(mx[index], my[index], i, i);
}
}
*/