Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hi #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

hi #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/Thumbs.db
Binary file not shown.
Binary file added assets/cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fall-crash.ogg
Binary file not shown.
Binary file added assets/flappy-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/flappy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/jump.ogg
Binary file not shown.
Binary file modified assets/point.ogg
Binary file not shown.
Binary file added assets/test.ogg
Binary file not shown.
102 changes: 98 additions & 4 deletions flappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,118 @@ 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");

}

/*
* 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() {

}

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");

}
122 changes: 122 additions & 0 deletions tutoringChallengeOneSnippet.txt
Original file line number Diff line number Diff line change
@@ -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");

}
Loading