/*
Flappy Box v0.7
Coded by Hady Hayman, Available as Public domain (CC0).
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. See link below for more info.
http://creativecommons.org/publicdomain/zero/1.0/
Special thanks to Thomas Palef for the tutorial, graphics and sound.
Also lewster32 and Dumtard for their great and fast help on the forums.
Best way to code a game is to start really simple and keep iterating.
v0.1 Old game added with new Phaser and some code tweaks.
v0.2 More coding to fix bugs.
v0.3 No bugs so far.
v0.4 Controls added, Tap to jump!
v0.5 Added sound plus fixed double-jumps only on mobiles.
v0.6 Fixed sound plus added pipes.
v0.7 Pipes are normally generated (no bugs) Better view on mobiles.
v0.8 Better gameplay, Score text works.
v0.9 Commented version and minified version available, Game can be paused by pressing P key on keyboard and resumed by pressing R (Doesn't work on mobiles).
v1.0 On-screen pause/resume. On-screen mute/unmute.
-Coming soon:
v1.1 Menu state with a Play button, Losing state with a retry and menu buttons.
v1.2 Fullscreen mobile scaling (Optional, might not be done.)
*/
/* Here we identify the game, 320 is the game's width,480 is the height, Phaser.AUTO tells phaser to check wether WebGL is supported or not
(If yes, It'll choose it, if not it'll render in the canvas.) and 'game_div' is the ID of the divider in .html file. While other functions are the ones that'll always run. */
var game = new Phaser.Game(320, 480, Phaser.AUTO, 'game_div');
// Here we identify our Score variable.
var score = -1;
// We identify our most important objects (As a global variable) that are going to be used in more than one state/function.
var box;
var pipe;
var gasp;
var choiceLabel;
var pause_label;
var muted = false;
var trueScore = 1;
// Then we start with states. First state is load_state which we'll preload all our assets in it.
var load_state = {
// Our first...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.