CodeBase - Flappy Bird
Return to the CodeBase listing
Category: Complete Applications
Version: 1.0
Information
Uploaded: 18th Apr 2014 13:34
Modified: 1st Jan 1970 01:00
Author: Anonymous Coder
Summary
Flappy Bird is the awesomest game in the whole world play at your own risk highly addictive!!!
Full Description
/**<br /> <br /> * Changelog:<br /> <br /> * - Added game over screen<br /> <br /> * - Flappy bird can now fly up above the screen but will still die to obstacles<br /> <br /> * - Flappy bird can no longer go underground<br /> <br /> * - Added alternate control for "flapping". Which would be the space key.<br /> <br /> * - Flappy bird now flaps a whole pixel lower.<br /> <br /> * <br /> <br /> * TODO: Save your best score<br /> <br /> * TODO: Add scores page<br /> <br /> * <br /> <br /> **/<br /> <br /> <br /> <br /> <br /> var keys = [];<br /> <br /> <br /> <br /> <br /> var count = 0;<br /> <br /> var tick = 0;<br /> <br /> <br /> <br /> <br /> var score = 0;<br /> <br /> <br /> <br /> <br /> var deathTicks = 0;<br /> <br /> <br /> <br /> <br /> var buttons = [];<br /> <br /> var gameState = 0; //0 = main-menu, 1 = game, (2 = game over)<br /> <br /> <br /> <br /> <br /> var objects = [];<br /> <br /> <br /> <br /> <br /> var started = false;<br /> <br /> <br /> <br /> <br /> var keyPressed = function() {<br /> <br /> keys[keyCode] = true;<br /> <br /> };<br /> <br /> var keyReleased = function() {<br /> <br /> keys[keyCode] = false;<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var addButton = function(id, state, x, y, width, height, text) {<br /> <br /> var button = {};<br /> <br /> <br /> <br /> button.id = id;<br /> <br /> button.state = state;<br /> <br /> button.x = x;<br /> <br /> button.y = y;<br /> <br /> button.width = width;<br /> <br /> button.height = height;<br /> <br /> button.text = text;<br /> <br /> button.pressed = false;<br /> <br /> <br /> <br /> buttons.push(button);<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var FlappyBird = function() {<br /> <br /> this.x = 100;<br /> <br /> this.y = 150;<br /> <br /> <br /> <br /> this.descentSpeed = 10;<br /> <br /> <br /> <br /> this.height = 0;<br /> <br /> this.heightIncrement = 0.25;<br /> <br /> <br /> <br /> this.dead = false;<br /> <br /> <br /> <br /> this.draw = function() {<br /> <br /> pushMatrix(); {<br /> <br /> var x = this.x + 16;<br /> <br /> var y = this.y + 12;<br /> <br /> <br /> <br /> var angle = max(-20, (this.descentSpeed - 10) * 4.1);<br /> <br /> if(angle <= 0) {<br /> <br /> <br /> <br /> }<br /> <br /> <br /> <br /> translate(x, y);<br /> <br /> rotate(angle);<br /> <br /> scale(0.80);<br /> <br /> translate(-x, -y);<br /> <br /> <br /> <br /> translate(this.x, this.y);<br /> <br /> this.drawSprite();<br /> <br /> } popMatrix();<br /> <br /> };<br /> <br /> <br /> <br /> this.drawSprite = function() {<br /> <br /> noStroke();<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> rect(2, 8, 10, 8);<br /> <br /> rect(8, 4, 4, 2);<br /> <br /> rect(12, 2, 6, 2);<br /> <br /> rect(16, 2, 10, 10);<br /> <br /> rect(26, 4, 4, 10);<br /> <br /> <br /> <br /> fill(23, 23, 23);<br /> <br /> rect(0, 8, 2, 2);<br /> <br /> rect(0, 10, 2, 2);<br /> <br /> rect(0, 12, 2, 2);<br /> <br /> rect(2, 6, 2, 2);<br /> <br /> rect(2, 14, 2, 2);<br /> <br /> rect(4, 6, 2, 2);<br /> <br /> rect(4, 16, 2, 2);<br /> <br /> rect(4, 18, 2, 2);<br /> <br /> rect(6, 4, 2, 2);<br /> <br /> rect(6, 6, 2, 2);<br /> <br /> rect(6, 16, 2, 2);<br /> <br /> rect(6, 20, 2, 2);<br /> <br /> rect(8, 2, 2, 2);<br /> <br /> rect(8, 6, 2, 2);<br /> <br /> rect(8, 16, 2, 2);<br /> <br /> rect(8, 20, 2, 2);<br /> <br /> rect(10, 2, 2, 2);<br /> <br /> rect(10, 8, 2, 2);<br /> <br /> rect(10, 14, 2, 2);<br /> <br /> rect(10, 22, 2, 2);<br /> <br /> rect(12, 0, 2, 2);<br /> <br /> rect(12, 10, 2, 2);<br /> <br /> rect(12, 12, 2, 2);<br /> <br /> rect(12, 22, 2, 2);<br /> <br /> rect(14, 0, 2, 2);<br /> <br /> rect(14, 22, 2, 2);<br /> <br /> rect(16, 0, 2, 2);<br /> <br /> rect(16, 4, 2, 2);<br /> <br /> rect(16, 6, 2, 2);<br /> <br /> rect(16, 8, 2, 2);<br /> <br /> rect(16, 16, 2, 2);<br /> <br /> rect(16, 22, 2, 2);<br /> <br /> rect(18, 0, 2, 2);<br /> <br /> rect(18, 2, 2, 2);<br /> <br /> rect(18, 10, 2, 2);<br /> <br /> rect(18, 14, 2, 2);<br /> <br /> rect(18, 18, 2, 2);<br /> <br /> rect(18, 22, 2, 2);<br /> <br /> rect(20, 0, 2, 2);<br /> <br /> rect(20, 12, 2, 2);<br /> <br /> rect(20, 16, 2, 2);<br /> <br /> rect(20, 20, 2, 2);<br /> <br /> rect(22, 0, 2, 2);<br /> <br /> rect(22, 12, 2, 2);<br /> <br /> rect(22, 16, 2, 2);<br /> <br /> rect(22, 20, 2, 2);<br /> <br /> rect(24, 0, 2, 2);<br /> <br /> rect(24, 12, 2, 2);<br /> <br /> rect(24, 16, 2, 2);<br /> <br /> rect(24, 20, 2, 2);<br /> <br /> rect(26, 2, 2, 2);<br /> <br /> rect(26, 6, 2, 2);<br /> <br /> rect(26, 8, 2, 2);<br /> <br /> rect(26, 12, 2, 2);<br /> <br /> rect(26, 16, 2, 2);<br /> <br /> rect(26, 20, 2, 2);<br /> <br /> rect(28, 4, 2, 2);<br /> <br /> rect(28, 12, 2, 2);<br /> <br /> rect(28, 16, 2, 2);<br /> <br /> rect(28, 20, 2, 2);<br /> <br /> rect(30, 6, 2, 2);<br /> <br /> rect(30, 8, 2, 2);<br /> <br /> rect(30, 10, 2, 2);<br /> <br /> rect(30, 12, 2, 2);<br /> <br /> rect(30, 16, 2, 2);<br /> <br /> rect(30, 20, 2, 2);<br /> <br /> rect(32, 12, 2, 2);<br /> <br /> rect(32, 16, 2, 2);<br /> <br /> rect(32, 18, 2, 2);<br /> <br /> rect(34, 14, 2, 2);<br /> <br /> <br /> <br /> fill(247, 255, 0);<br /> <br /> rect(2, 12, 2, 2);<br /> <br /> rect(4, 14, 2, 2);<br /> <br /> rect(6, 14, 2, 2);<br /> <br /> rect(8, 14, 2, 2);<br /> <br /> rect(10, 6, 2, 2);<br /> <br /> rect(10, 12, 2, 2);<br /> <br /> rect(12, 4, 2, 2);<br /> <br /> rect(12, 6, 2, 2);<br /> <br /> rect(12, 8, 2, 2);<br /> <br /> rect(12, 14, 2, 2);<br /> <br /> rect(14, 4, 2, 12);<br /> <br /> rect(16, 10, 2, 6);<br /> <br /> rect(18, 12, 2, 2);<br /> <br /> <br /> <br /> fill(244, 202, 22);<br /> <br /> rect(6, 18, 2, 2);<br /> <br /> rect(8, 18, 2, 2);<br /> <br /> rect(10, 16, 6, 6);<br /> <br /> rect(16, 18, 2, 4);<br /> <br /> rect(18, 20, 2, 2);<br /> <br /> <br /> <br /> fill(214, 43, 43);<br /> <br /> rect(18, 16, 2, 2);<br /> <br /> rect(20, 14, 14, 2);<br /> <br /> rect(20, 18, 12, 2);<br /> <br /> };<br /> <br /> <br /> <br /> this.update = function() {<br /> <br /> if(gameState === 1 && started) {<br /> <br /> this.controls();<br /> <br /> <br /> <br /> this.y += this.descentSpeed;<br /> <br /> <br /> <br /> this.descentSpeed += 1.25;<br /> <br /> } else if(gameState === 1) {<br /> <br /> this.y += this.height;<br /> <br /> <br /> <br /> this.height += this.heightIncrement;<br /> <br /> if(abs(this.height) >= 1.25) {<br /> <br /> this.heightIncrement *= -1;<br /> <br /> }<br /> <br /> }<br /> <br /> <br /> <br /> if(this.dead) {<br /> <br /> this.descentSpeed = min(32, this.descentSpeed + 2.0);<br /> <br /> <br /> <br /> this.y += 12;<br /> <br /> <br /> <br /> deathTicks++;<br /> <br /> <br /> <br /> if(this.y >= 332) {<br /> <br /> this.y = 332;<br /> <br /> }<br /> <br /> <br /> <br /> if(deathTicks === 15) {<br /> <br /> addButton(0, 2, 135, 310, 130, 38, "PLAY AGAIN");<br /> <br /> }<br /> <br /> }<br /> <br /> };<br /> <br /> <br /> <br /> this.controls = function() {<br /> <br /> if((mouseIsPressed || keys[32]) && !this.dead) {<br /> <br /> this.descentSpeed = -7;<br /> <br /> }<br /> <br /> };<br /> <br /> };<br /> <br /> var FlappiestBird = new FlappyBird();<br /> <br /> <br /> <br /> <br /> var initProgram = function() {<br /> <br /> buttons = [];<br /> <br /> <br /> <br /> addButton(0, 0, 50, 290, 130, 38, "START");<br /> <br /> addButton(1, 0, 220, 290, 130, 38, "SCORES");<br /> <br /> <br /> <br /> score = 0;<br /> <br /> deathTicks = 0;<br /> <br /> <br /> <br /> count = 0;<br /> <br /> tick = 0;<br /> <br /> <br /> <br /> gameState = 0;<br /> <br /> objects = [];<br /> <br /> started = false;<br /> <br /> <br /> <br /> FlappiestBird = new FlappyBird();<br /> <br /> };<br /> <br /> initProgram();<br /> <br /> <br /> <br /> <br /> var buttonPressed = function(button) {<br /> <br /> switch(button.state) {<br /> <br /> case 0:<br /> <br /> switch(button.id) {<br /> <br /> case 0:<br /> <br /> gameState = 1;<br /> <br /> score = 0;<br /> <br /> started = false;<br /> <br /> break;<br /> <br /> default:<br /> <br /> break;<br /> <br /> }<br /> <br /> break;<br /> <br /> case 2:<br /> <br /> switch(button.id) {<br /> <br /> case 0:<br /> <br /> initProgram();<br /> <br /> break;<br /> <br /> default:<br /> <br /> break;<br /> <br /> }<br /> <br /> break;<br /> <br /> default:<br /> <br /> break;<br /> <br /> }<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var addObject = function() {<br /> <br /> var lastY = random(20) + 150;<br /> <br /> <br /> <br /> if(objects.length > 0) {<br /> <br /> var lastObject = objects[objects.length - 1];<br /> <br /> lastY = lastObject.y;<br /> <br /> }<br /> <br /> <br /> <br /> var object = {};<br /> <br /> <br /> <br /> object.y = max(90, min(260, lastY + random(200) - 100));<br /> <br /> object.x = 450;<br /> <br /> <br /> <br /> objects.push(object);<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var drawPixelatedEllipse = function(x, y, width, height, colour) {<br /> <br /> fill(colour);<br /> <br /> ellipse(x, y, width, height);<br /> <br /> <br /> <br /> noStroke();<br /> <br /> fill(red(colour) + 10, green(colour) + 10, blue(colour) + 10);<br /> <br /> for(var i = 0; i <= 360; i += 7) {<br /> <br /> var xx = x + cos(i) * (width / 2);<br /> <br /> var yy = y + sin(i) * (height / 2);<br /> <br /> <br /> <br /> rect(xx - 3, yy - 3, 6, 6);<br /> <br /> }<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var mousePressed = function() {<br /> <br /> if(gameState === 1) {<br /> <br /> if(!started) {<br /> <br /> started = true;<br /> <br /> }<br /> <br /> }<br /> <br /> <br /> <br /> for(var i = 0; i < buttons.length; i++) {<br /> <br /> var button = buttons[i];<br /> <br /> <br /> <br /> if(button.state === gameState) {<br /> <br /> if(mouseX >= button.x - 1 && mouseX <= button.x + button.width + 1 && <br /> <br /> mouseY >= button.y - 1 && mouseY <= button.y + button.height + 1) {<br /> <br /> buttonPressed(button);<br /> <br /> }<br /> <br /> }<br /> <br /> }<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var die = function() {<br /> <br /> FlappiestBird.dead = true;<br /> <br /> gameState = 2;<br /> <br /> deathTicks = 0;<br /> <br /> };<br /> <br /> <br /> <br /> <br /> var intersects = function(r1, r2) {<br /> <br /> return !(r2.left >= r1.right || <br /> <br /> r2.right <= r1.left || <br /> <br /> r2.top >= r1.bottom ||<br /> <br /> r2.bottom <= r1.top);<br /> <br /> };<br /> <br /> <br /> <br /> <br /> draw = function() {<br /> <br /> background(91, 199, 199);<br /> <br /> <br /> <br /> if(gameState !== 2) {<br /> <br /> count += 3;<br /> <br /> if(count >= 15) {<br /> <br /> count = 0;<br /> <br /> }<br /> <br /> }<br /> <br /> <br /> <br /> pushMatrix();<br /> <br /> <br /> <br /> translate(200, 200);<br /> <br /> scale((deathTicks > 0 && deathTicks <= 10)? 1.01 : 1.0);<br /> <br /> translate(-200, -200);<br /> <br /> <br /> <br /> if(deathTicks > 0 && deathTicks <= 10) {<br /> <br /> translate(random(4) - 2, random(4) - 2);<br /> <br /> }<br /> <br /> //Draw background<br /> <br /> noStroke();<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> drawPixelatedEllipse(20, 320, 80, 80, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(70, 340, 80, 80, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(115, 325, 80, 75, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(160, 330, 50, 60, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(200, 320, 60, 60, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(240, 325, 60, 80, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(270, 335, 60, 80, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(310, 330, 60, 60, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(350, 325, 50, 60, color(255, 255, 255));<br /> <br /> drawPixelatedEllipse(390, 320, 70, 80, color(255, 255, 255));<br /> <br /> <br /> <br /> drawPixelatedEllipse(112, 370, 76, 76, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(251, 378, 83, 90, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(0, 367, 74, 89, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(350, 368, 73, 60, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(140, 376, 72, 71, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(434, 353, 70, 85, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(207, 380, 77, 86, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(320, 373, 73, 84, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(82, 372, 75, 73, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(221, 380, 77, 84, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(388, 375, 77, 72, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(273, 380, 90, 75, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(404, 388, 88, 88, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(176, 378, 85, 79, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(86, 368, 81, 83, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(293, 378, 88, 90, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(52, 376, 84, 84, color(29, 196, 79));<br /> <br /> drawPixelatedEllipse(24, 376, 74, 81, color(29, 196, 79));<br /> <br /> <br /> <br /> if(gameState === 1 || gameState === 2) {<br /> <br /> if(!FlappiestBird.dead) {<br /> <br /> if(FlappiestBird.y >= 320) {<br /> <br /> die();<br /> <br /> }<br /> <br /> }<br /> <br /> var playerAABB = {};<br /> <br /> <br /> <br /> playerAABB.left = FlappiestBird.x;<br /> <br /> playerAABB.right = FlappiestBird.x + 34;<br /> <br /> playerAABB.top = FlappiestBird.y;<br /> <br /> playerAABB.bottom = FlappiestBird.y + 24;<br /> <br /> <br /> <br /> //Draw obstacles<br /> <br /> var index = objects.length;<br /> <br /> while(index--) {<br /> <br /> var object = objects[index];<br /> <br /> <br /> <br /> object.x -= FlappiestBird.dead? 0 : 3;<br /> <br /> <br /> <br /> var topAABB = {};<br /> <br /> <br /> <br /> topAABB.left = object.x - 5;<br /> <br /> topAABB.right = object.x + 45;<br /> <br /> topAABB.top = -5000;<br /> <br /> topAABB.bottom = object.y - 55;<br /> <br /> <br /> <br /> var bottomAABB = {};<br /> <br /> <br /> <br /> bottomAABB.left = object.x - 5;<br /> <br /> bottomAABB.right = object.x + 45;<br /> <br /> bottomAABB.top = object.y + 38;<br /> <br /> bottomAABB.bottom = 300;<br /> <br /> <br /> <br /> if(abs(object.x - FlappiestBird.x) <= 1) {<br /> <br /> score++;<br /> <br /> }<br /> <br /> <br /> <br /> if(intersects(playerAABB, topAABB) || intersects(playerAABB, bottomAABB)) {<br /> <br /> die();<br /> <br /> }<br /> <br /> <br /> <br /> pushMatrix(); {<br /> <br /> translate(0, -10);<br /> <br /> <br /> <br /> strokeWeight(2);<br /> <br /> stroke(0, 0, 0);<br /> <br /> <br /> <br /> fill(56, 207, 39);<br /> <br /> <br /> <br /> rect(object.x, -2, 40, object.y - 50);<br /> <br /> rect(object.x - 5, object.y - 70, 50, 25);<br /> <br /> <br /> <br /> noStroke();<br /> <br /> <br /> <br /> fill(255, 255, 255, 100);<br /> <br /> <br /> <br /> rect(object.x, 0, 11, object.y - 71);<br /> <br /> rect(object.x - 4, object.y - 66, 11, 20);<br /> <br /> rect(object.x + 9, object.y - 66, 2, 20);<br /> <br /> rect(object.x + 13, 0, 2, object.y - 71);<br /> <br /> <br /> <br /> fill(255, 255, 255, 150);<br /> <br /> <br /> <br /> rect(object.x + 2.5, 0, 3, object.y - 71);<br /> <br /> rect(object.x - 1.5, object.y - 66, 3, 20);<br /> <br /> <br /> <br /> fill(0, 0, 0, 100);<br /> <br /> <br /> <br /> rect(object.x + 40, 0, -5, object.y - 71);<br /> <br /> rect(object.x + 33, 0, -2, object.y - 71);<br /> <br /> rect(object.x - 4, object.y - 70, 50, 3);<br /> <br /> rect(object.x + 39, object.y - 67, 5, 22);<br /> <br /> rect(object.x + 35, object.y - 67, 2, 22);<br /> <br /> <br /> <br /> fill(0, 0, 0, 50);<br /> <br /> rect(object.x - 4, object.y - 67, 39, 1);<br /> <br /> rect(object.x + 37, object.y - 67, 3, 1);<br /> <br /> } popMatrix();<br /> <br /> <br /> <br /> pushMatrix(); {<br /> <br /> translate(0, 10);<br /> <br /> <br /> <br /> strokeWeight(2);<br /> <br /> stroke(0, 0, 0);<br /> <br /> <br /> <br /> fill(56, 207, 39);<br /> <br /> rect(object.x, object.y + 50, 40, 400);<br /> <br /> rect(object.x - 5, object.y + 30, 50, 25);<br /> <br /> <br /> <br /> noStroke();<br /> <br /> fill(255, 255, 255, 100);<br /> <br /> rect(object.x, object.y + 56, 11, 300);<br /> <br /> rect(object.x + 13, object.y + 56, 2, 300);<br /> <br /> rect(object.x - 4, object.y + 31, 11, 20);<br /> <br /> rect(object.x + 9, object.y + 31, 2, 20);<br /> <br /> <br /> <br /> fill(255, 255, 255, 150);<br /> <br /> rect(object.x + 2.5, object.y + 56, 3, 300);<br /> <br /> rect(object.x - 1.5, object.y + 31, 3, 20);<br /> <br /> <br /> <br /> fill(0, 0, 0, 100);<br /> <br /> rect(object.x + 40, object.y + 56, -5, 300);<br /> <br /> rect(object.x + 33, object.y + 56, -2, 300);<br /> <br /> rect(object.x - 4, object.y + 52, 50, 3);<br /> <br /> rect(object.x + 39, object.y + 30, 5, 22);<br /> <br /> rect(object.x + 35, object.y + 30, 2, 22);<br /> <br /> <br /> <br /> fill(0, 0, 0, 50);<br /> <br /> rect(object.x - 4, object.y + 51, 39, 1);<br /> <br /> rect(object.x + 37, object.y + 51, 3, 1);<br /> <br /> } popMatrix();<br /> <br /> <br /> <br /> if(object.x <= -50) {<br /> <br /> objects.splice(index, 1);<br /> <br /> }<br /> <br /> }<br /> <br /> }<br /> <br /> noStroke();<br /> <br /> <br /> <br /> <br /> <br /> <br /> fill(250, 215, 73);<br /> <br /> rect(0, 360, 400, 40);<br /> <br /> fill(84, 222, 0);<br /> <br /> rect(0, 350, 400, 12);<br /> <br /> fill(255, 255, 255, 200);<br /> <br /> rect(0, 350, 400, 2);<br /> <br /> fill(0, 0, 0);<br /> <br /> rect(0, 349, 400, 1);<br /> <br /> <br /> <br /> fill(0, 0, 0, 40);<br /> <br /> rect(0, 360, 400, 3);<br /> <br /> rect(0, 361, 400, 3);<br /> <br /> rect(0, 362, 400, 3);<br /> <br /> <br /> <br /> fill(124, 242, 0);<br /> <br /> for(var i = 0; i < 30; i++) {<br /> <br /> var x = i * 15 - count;<br /> <br /> quad(x, 352, x + 7, 352, x, 360, x - 7, 360);<br /> <br /> }<br /> <br /> <br /> <br /> tick++;<br /> <br /> if(this.gameState !== 0) {<br /> <br /> FlappiestBird.update();<br /> <br /> FlappiestBird.draw();<br /> <br /> }<br /> <br /> <br /> <br /> popMatrix();<br /> <br /> <br /> <br /> if(gameState === 1) {<br /> <br /> if(started) {<br /> <br /> if(tick % 50 === 0) {<br /> <br /> addObject();<br /> <br /> }<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> text(score, 200, 130);<br /> <br /> } else {<br /> <br /> fill(255, 0, 0);<br /> <br /> strokeWeight(2);<br /> <br /> stroke(255, 255, 255);<br /> <br /> <br /> <br /> beginShape();<br /> <br /> vertex(205, 227);<br /> <br /> vertex(213, 220);<br /> <br /> vertex(237, 220);<br /> <br /> vertex(237, 234);<br /> <br /> vertex(213, 234);<br /> <br /> vertex(205, 227);<br /> <br /> endShape();<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> textFont(createFont("Monospace", 10), 12);<br /> <br /> text("TAP", 223, 227);<br /> <br /> <br /> <br /> noStroke();<br /> <br /> <br /> <br /> pushMatrix(); {<br /> <br /> translate(-10, 28);<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> rect(202, 200, 2, 28);<br /> <br /> rect(200, 218, 2, 8);<br /> <br /> rect(198, 212, 2, 12);<br /> <br /> rect(200, 212, 16, 16);<br /> <br /> rect(206, 208, 6, 4);<br /> <br /> <br /> <br /> fill(0, 0, 0);<br /> <br /> rect(200, 200, 2, 18);<br /> <br /> rect(204, 200, 2, 14);<br /> <br /> rect(202, 198, 2, 2);<br /> <br /> rect(198, 210, 2, 2);<br /> <br /> rect(196, 212, 2, 12);<br /> <br /> rect(198, 224, 2, 2);<br /> <br /> rect(200, 226, 2, 2);<br /> <br /> rect(202, 228, 12, 2);<br /> <br /> rect(206, 206, 2, 2);<br /> <br /> rect(208, 208, 2, 6);<br /> <br /> rect(210, 208, 2, 2);<br /> <br /> rect(212, 210, 4, 2);<br /> <br /> rect(212, 212, 2, 4);<br /> <br /> rect(216, 212, 2, 12);<br /> <br /> rect(214, 224, 2, 4);<br /> <br /> } popMatrix();<br /> <br /> <br /> <br /> stroke(0, 0, 0);<br /> <br /> strokeWeight(1.5);<br /> <br /> <br /> <br /> line(189, 225, 183, 216);<br /> <br /> line(193, 223, 193, 213);<br /> <br /> line(197, 225, 203, 216);<br /> <br /> }<br /> <br /> }<br /> <br /> <br /> <br /> //Draw buttons<br /> <br /> for(var i = 0; i < buttons.length; i++) {<br /> <br /> var button = buttons[i];<br /> <br /> <br /> <br /> if(button.state === gameState) {<br /> <br /> if(mouseX >= button.x - 1 && mouseX <= button.x + button.width + 1 && <br /> <br /> mouseY >= button.y - 1 && mouseY <= button.y + button.height + 1) {<br /> <br /> button.pressed = true;<br /> <br /> } else {<br /> <br /> button.pressed = false;<br /> <br /> }<br /> <br /> <br /> <br /> //Draw<br /> <br /> stroke(112, 73, 14);<br /> <br /> strokeWeight(2);<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> rect(button.x, button.y + (button.pressed? 2 : 0), button.width, button.height);<br /> <br /> <br /> <br /> noStroke();<br /> <br /> fill(209, 101, 30);<br /> <br /> rect(button.x + 3, button.y + 3 + (button.pressed? 2 : 0), button.width - 6, button.height - 6);<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> textAlign(CENTER, CENTER);<br /> <br /> textFont("Monospace", 16);<br /> <br /> text(button.text, button.x + button.width / 2, button.y + button.height / 2 + (button.pressed? 2 : 0));<br /> <br /> <br /> <br /> fill(112, 73, 14);<br /> <br /> rect(button.x - 1, button.y + button.height + 1, button.width + 2, 2);<br /> <br /> }<br /> <br /> }<br /> <br /> <br /> <br /> if(gameState === 2) {<br /> <br /> if(deathTicks === 2) {<br /> <br /> noStroke();<br /> <br /> fill(255, 255, 255);<br /> <br /> rect(0, 0, 400, 400);<br /> <br /> }<br /> <br /> if(FlappiestBird.y >= 325 && deathTicks >= 15) {<br /> <br /> strokeWeight(2);<br /> <br /> stroke(0, 0, 0);<br /> <br /> <br /> <br /> fill(222, 213, 146);<br /> <br /> rect(75, 150, 250, 150);<br /> <br /> <br /> <br /> stroke(207, 172, 91);<br /> <br /> fill(222, 216, 151);<br /> <br /> rect(80, 155, 240, 140);<br /> <br /> <br /> <br /> stroke(217, 197, 126);<br /> <br /> rect(81, 156, 238, 138);<br /> <br /> <br /> <br /> fill(242, 232, 172);<br /> <br /> rect(76, 152, 248, 0.1);<br /> <br /> <br /> <br /> fill(196, 153, 72);<br /> <br /> textSize(15);<br /> <br /> <br /> <br /> textAlign(RIGHT, CENTER);<br /> <br /> text("SCORE", 305, 175);<br /> <br /> text("BEST", 305, 225);<br /> <br /> <br /> <br /> fill(255, 255, 255);<br /> <br /> textSize(20);<br /> <br /> <br /> <br /> text(score, 305, 200);<br /> <br /> text(score, 305, 250);<br /> <br /> }<br /> <br /> }<br /> <br /> };
Comments
No comments yet.