diff --git a/assets/Thumbs.db b/assets/Thumbs.db new file mode 100644 index 0000000..081c622 Binary files /dev/null and b/assets/Thumbs.db differ diff --git a/assets/cursor.png b/assets/cursor.png new file mode 100644 index 0000000..65ec54b Binary files /dev/null and b/assets/cursor.png differ diff --git a/assets/fall-crash.ogg b/assets/fall-crash.ogg new file mode 100644 index 0000000..3e02454 Binary files /dev/null and b/assets/fall-crash.ogg differ diff --git a/assets/flappy-2.png b/assets/flappy-2.png new file mode 100644 index 0000000..ed98e05 Binary files /dev/null and b/assets/flappy-2.png differ diff --git a/assets/flappy.png b/assets/flappy.png index 9bb85df..af75ccc 100644 Binary files a/assets/flappy.png and b/assets/flappy.png differ diff --git a/assets/images.jpg b/assets/images.jpg new file mode 100644 index 0000000..320a61e Binary files /dev/null and b/assets/images.jpg differ diff --git a/assets/images2.png b/assets/images2.png new file mode 100644 index 0000000..f5457f2 Binary files /dev/null and b/assets/images2.png differ diff --git a/assets/images3.jpg b/assets/images3.jpg new file mode 100644 index 0000000..815e00d Binary files /dev/null and b/assets/images3.jpg differ diff --git a/assets/jump.ogg b/assets/jump.ogg new file mode 100644 index 0000000..be1ec3a Binary files /dev/null and b/assets/jump.ogg differ diff --git a/assets/point.ogg b/assets/point.ogg index efb2d99..a21d2a2 100644 Binary files a/assets/point.ogg and b/assets/point.ogg differ diff --git a/assets/test.ogg b/assets/test.ogg new file mode 100644 index 0000000..6b9418c Binary files /dev/null and b/assets/test.ogg differ diff --git a/flappy.js b/flappy.js index c5fce5e..c65d15c 100644 --- a/flappy.js +++ b/flappy.js @@ -9,11 +9,28 @@ var stateActions = { preload: preload, create: create, update: update }; // - actions on the game state (or null for nothing) var game = new Phaser.Game(790, 400, Phaser.AUTO, 'game', stateActions); +var scoreP1 = 0; +var scoreP2 = 0; +var label_scoreP1; +var label_scoreP2; +var player; +var pipes; + +var pipeInterval = 3; + + + /* * Loads all resources for the game and gives them names. */ function preload() { - + game.load.image("imgPlayer", "assets/flappy.png"); + game.load.image("mouseCursorImg", "assets/cursor.png"); + game.load.audio("spaceOgg", "assets/point.ogg"); + game.load.image("pipe", "assets/pipe.png"); + game.load.audio("jump", "assets/jump.ogg"); + game.load.audio("crash", "assets/fall-crash.ogg"); + game.load.image("imgPlayer2", "assets/player-2.png"); } @@ -21,12 +38,89 @@ function preload() { * Initialises the game. This function is only called once. */ function create() { - // set the background colour of the scene + // set the background colour of the scene (with hexadecimal) + game.stage.setBackgroundColor("#E7FF00"); + game.physics.startSystem(Phaser.Physics.ARCADE); + player = game.add.sprite(395, 200, "imgPlayer"); + game.physics.arcade.enable(player); + game.time.events.loop(pipeInterval * Phaser.Timer.SECOND, createPipe); + player.body.gravity.y = 300; + + game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(jump); + label_scoreP1 = game.add.text(700, 50, "0"); + label_scoreP2 = game.add.text(90, 50, "0"); + pipes = game.add.group(); + createPipe(); + } /* * This function updates the scene. It is called for every new frame. */ function update() { - -} \ No newline at end of file + + game.physics.arcade.overlap(player, pipes, game_over); + +} + +function jump(event) { + + if (player.body.velocity.y != 100) { + player.body.velocity.y = -165; + } + game.sound.play("jump"); + +} + +function changeScore() { + + score = score + 1; + label_score.setText(score.toString()); + game.sound.play("spaceOgg"); + +} + + +function addPipeBlock(x, y) { + var block = pipes.create(x, y, "pipe"); + game.physics.arcade.enable(block); + block.body.velocity.x = -200; + + +} + +function createPipe() { + + var randNum = game.rnd.integerInRange(1, 7); + var chance = game.rnd.integerInRange(1, 2); + for (var count = 0; count < 8; count++) { + + if (chance === 1) { + if (count != randNum) { + addPipeBlock(780, count * 50); + } + } else { + if (randNum != 7) { + if (count != randNum && count != randNum + 1) { + addPipeBlock(780, count * 50); + } + } else { + if (count != randNum && count != randNum - 1) { + addPipeBlock(780, count * 50); + } + } + } + + } + + changeScore(); + +} + +function game_over() { + + player.velocity.y = 100; + pipes.velocity.x = 0; + game.sound.play("crash"); + +} diff --git a/tutoringChallengeOneSnippet.txt b/tutoringChallengeOneSnippet.txt new file mode 100644 index 0000000..193d63e --- /dev/null +++ b/tutoringChallengeOneSnippet.txt @@ -0,0 +1,122 @@ +// the Game object used by the phaser.io library +var stateActions = { preload: preload, create: create, update: update }; + +// Phaser parameters: +// - game width +// - game height +// - renderer (go for Phaser.AUTO) +// - element where the game will be drawn ('game') +// - actions on the game state (or null for nothing) +var game = new Phaser.Game(790, 400, Phaser.AUTO, 'game', stateActions); +var score = 0; +var label_score; +var player; +var pipes; + +var pipeInterval = 3; + + + +/* + * Loads all resources for the game and gives them names. + */ +function preload() { + game.load.image("imgPlayer", "assets/flappy.png"); + game.load.image("mouseCursorImg", "assets/cursor.png"); + game.load.audio("spaceOgg", "assets/point.ogg"); + game.load.image("pipe", "assets/pipe.png"); + game.load.audio("jump", "assets/jump.ogg"); + game.load.audio("crash", "assets/fall-crash.ogg"); + game.load.image("imgPlayer2", "assets/player-2.png"); + +} + +/* + * Initialises the game. This function is only called once. + */ +function create() { + // set the background colour of the scene (with hexadecimal) + game.stage.setBackgroundColor("#E7FF00"); + game.physics.startSystem(Phaser.Physics.ARCADE); + player = game.add.sprite(395, 200, "imgPlayer"); + game.physics.arcade.enable(player); + game.time.events.loop(pipeInterval * Phaser.Timer.SECOND, createPipe); + player.body.gravity.y = 300; + + game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(jump); + label_score = game.add.text(700, 50, "0"); + pipes = game.add.group(); + createPipe(); + +} + +/* + * This function updates the scene. It is called for every new frame. + */ +function update() { + + game.physics.arcade.overlap(player, pipes, game_over); + +} + +function jump(event) { + + if (player.body.velocity.y != 100) { + player.body.velocity.y = -165; + } + game.sound.play("jump"); + +} + +function changeScore() { + + score = score + 1; + label_score.setText(score.toString()); + game.sound.play("spaceOgg"); + +} + + +function addPipeBlock(x, y) { + var block = pipes.create(x, y, "pipe"); + game.physics.arcade.enable(block); + block.body.velocity.x = -200; + + +} + +function createPipe() { + + var randNum = game.rnd.integerInRange(1, 7); + var chance = game.rnd.integerInRange(1, 2); + for (var count = 0; count < 8; count++) { + + if (chance === 1) { + if (count != randNum) { + addPipeBlock(780, count * 50); + } + } else { + if (randNum != 7) { + if (count != randNum && count != randNum + 1) { + addPipeBlock(780, count * 50); + } + } else { + if (count != randNum && count != randNum - 1) { + addPipeBlock(780, count * 50); + } + } + } + + } + + changeScore(); + +} + +function game_over() { + + player.velocity.y = 100; + pipes.velocity.x = 0; + game.sound.play("crash"); + +} diff --git a/tutoringChallengeTwoSnippet.txt b/tutoringChallengeTwoSnippet.txt new file mode 100644 index 0000000..ae9a506 --- /dev/null +++ b/tutoringChallengeTwoSnippet.txt @@ -0,0 +1,163 @@ +// the Game object used by the phaser.io library +var stateActions = { preload: preload, create: create, update: update }; + +// Phaser parameters: +// - game width +// - game height +// - renderer (go for Phaser.AUTO) +// - element where the game will be drawn ('game') +// - actions on the game state (or null for nothing) +var game = new Phaser.Game(790, 400, Phaser.AUTO, 'game', stateActions); + +var scoreP1 = 0; +var scoreP2 = 0; +var label_scoreP1; +var label_scoreP2; +var player; +var pipes; + +var pipeInterval = 3; + + + +/* + * Loads all resources for the game and gives them names. + */ +function preload() { + game.load.image("imgPlayer", "assets/flappy.png"); + game.load.image("mouseCursorImg", "assets/cursor.png"); + game.load.audio("spaceOgg", "assets/point.ogg"); + game.load.image("pipe", "assets/pipe.png"); + game.load.audio("jump", "assets/jump.ogg"); + game.load.audio("crash", "assets/fall-crash.ogg"); + game.load.image("imgPlayer2", "assets/player-2.png"); + +} + +/* + * Initialises the game. This function is only called once. + */ +function create() { + // set the background colour of the scene (with hexadecimal) + game.stage.setBackgroundColor("#E7FF00"); + game.physics.startSystem(Phaser.Physics.ARCADE); + player = game.add.sprite(395, 200, "imgPlayer"); + player2 = game.add.sprite(395, 230, "imgPlayer2"); + game.physics.arcade.enable(player); + game.physics.arcade.enable(player2); + game.time.events.loop(pipeInterval * Phaser.Timer.SECOND, createPipe); + player.body.gravity.y = 300; + player2.body.gravity.y = 300; + + game.input.onDown.add(p2Jump); + game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(p1Jump); + label_scoreP1 = game.add.text(700, 50, "0"); + label_scoreP2 = game.add.text(90, 50, "0"); + pipes = game.add.group(); + createPipe(); + + if (player.velocity.y === 100 && player2.velocity.y === 100) { + pipes.velocity.x = 0; + } + +} + +/* + * This function updates the scene. It is called for every new frame. + */ +function update() { + + game.physics.arcade.overlap(player, pipes, game_overP1); + game.physics.arcade.overlap(player2, pipes, game_overP2); + +} + +function p1Jump(event) { + + if (player.velocity.y != 100) { + player.velocity.y = -165; + } + game.sound.play("jump"); + +} + +function p2Jump(event) { + + if (player2.velocity.y != 100) { + player2.velocity.y = -165; + } + game.sound.play("jump"); + +} + +function changeScoreP1() { + + scoreP1 = scoreP1 + 1; + label_scoreP1.setText(scoreP1.toString()); + game.sound.play("spaceOgg"); + +} + +function changeScoreP2() { + + scoreP2 = scoreP2 + 1; + label_scoreP2.setText(scoreP2.toString()); + game.sound.play("spaceOgg"); + +} + +function addPipeBlock(x, y) { + var block = pipes.create(x, y, "pipe"); + game.physics.arcade.enable(block); + block.velocity.x = -200; + + +} + +function createPipe() { + + var randNum = game.rnd.integerInRange(1, 7); + var chance = game.rnd.integerInRange(1, 2); + for (var count = 0; count < 8; count++) { + + if (chance === 1) { + if (count != randNum) { + addPipeBlock(780, count * 50); + } + } else { + if (randNum != 7) { + if (count != randNum && count != randNum + 1) { + addPipeBlock(780, count * 50); + } + } else { + if (count != randNum && count != randNum - 1) { + addPipeBlock(780, count * 50); + } + } + } + + } + + if (player.velocity.y != 100) { + changeScoreP1(); + } + + if (player2.velocity.y != 100) { + changeScoreP2(); + } + +} + +function game_overP1() { + + player.velocity.y = 100; + game.sound.play("crash"); + +} + +function game_overP2() { + + player2.velocity.y = 100; + game.sound.play("crash"); + +}