Skip to content

flippy burger #5

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
scores.csv
.idea
.idea
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ app.get("/", function(request, response){
response.sendFile(path.join(__dirname, "pages/index.html"));
});

app.post('/score', function(request, response){
});
//app.post('/score', function(request, response){
//
//});

var server = app.listen(8080, function() {
var server = app.listen((process.env.PORT || 8080), function() {
var host = server.address().address;
var port = server.address().port;

Expand Down
3 changes: 3 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: darkblue;
}
32 changes: 32 additions & 0 deletions assets/style1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
h1 {
color: #74B4E8;
font-size: 50px;
font-style: oblique;
font-family: monospace;
}


.score {
color: silver;
font-size: 30px;

}

.score2 {
color: rosybrown;
font-size: 30px;

}

.gold {
color: gold;
font-size: 30px;
}
#gameLink {
text-align: center;
border: 1px solid white;
}

body {
background-color: darkcyan;
}
125 changes: 125 additions & 0 deletions js/flappy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* Created by v3513 on 11/08/2015.
*/
// the functions associated with preload, create and update.
var actions = { preload: preload, create: create, update: update };
// the Game object used by the phaser.io library
var game = new Phaser.Game(790, 400, Phaser.AUTO, "game", actions);
// Global score variable initialised to 0.
var score = 0;
// Global variable to hold the text displaying the score.
var labelScore;
// Global player variable declared but not initialised.
var player;
// Global pipes variable initialised to the empty array.
var pipes = [];
// the interval (in seconds) at which new pipe columns are spawned
var pipeInterval = 1.75;

// Loads all resources for the game and gives them names.
jQuery("#greeting-form").on("submit", function(event_details) {
var greeting = "Hello ";
var name = jQuery("#fullName").val();
var greeting_message = greeting + name;
jQuery("#greeting-form").hide();
jQuery("#greeting").append("<p>" + greeting_message + "</p>");
event_details.preventDefault();

});


function preload() {
// make image file available to game and associate with alias playerImg
game.load.image("playerIMG","../assets/burger2.gif");
// make sound file available to game and associate with alias score
game.load.audio("score", "../assets/point.ogg");
// make image file available to game and associate with alias pipe
game.load.image("pipe","../assets/pipe.png");
game.load.image("background", "../assets/frenchfriesbackground.jpg");
}

// Initialises the game. This function is only called once.
function create() {
// set the background colour of the scene
game.stage.setBackgroundColor("#F3D3A3");
game.add.sprite(0,0, "background");
// add welcome text

// add score text
labelScore = game.add.text(20, 0, "0",
{font: "30px Arial", fill: "#FFFFFF"});
// initialise the player and associate it with playerImg

var burger = player = game.add.sprite(80, 200, "playerIMG");
burger.scale.setTo(0.05, 0.05);
// Start the ARCADE physics engine.
// ARCADE is the most basic physics engine in Phaser.
game.physics.startSystem(Phaser.Physics.ARCADE);
// enable physics for the player sprite
game.physics.arcade.enable(player);
// set the player's gravity
player.body.gravity.y = 500;
// associate spacebar with jump function
game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(playerJump);
// time loop for game to update
game.time.events.loop(pipeInterval * Phaser.Timer.SECOND, generatePipe);
}

// This function updates the scene. It is called for every new frame.
function update() {
// Call gameOver function when player overlaps with any pipe

game.physics.arcade
.overlap(player,
pipes,
gameOver);

}

// Adds a pipe part to the pipes array
function addPipeBlock(x, y) {
// make a new pipe block
var block = game.add.sprite(x,y,"pipe");
// insert it in the pipe array
pipes.push(block);
// enable physics engine for the block
game.physics.arcade.enable(block);
// set the block's horizontal velocity to a negative value
// (negative x value for velocity means movement will be towards left)
block.body.velocity.x = -200;
}

// Generate moving pipe
function generatePipe() {
// Generate random integer between 1 and 5. This is the location of the
// start point of the gap.
var gapStart = game.rnd.integerInRange(1, 5);
// Loop 8 times (8 is the height of the canvas).
for (var count = 0; count < 8; count++) {
// If the value of count is not equal to the gap start point
// or end point, add the pipe image.
if(count != gapStart && count != gapStart+1){
addPipeBlock(750, count * 50);
}
}
// Increment the score each time a new pipe is generated.
changeScore();
}

function playerJump() {
// the more negative the value the higher it jumps
player.body.velocity.y = -200;
}

// Function to change the score
function changeScore() {
//increments global score variable by 1
score++;
// updates the score label
labelScore.setText(score.toString());
}

function gameOver() {
// stop the game (update() function no longer called)
game.destroy();
}
184 changes: 164 additions & 20 deletions js/flappy.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,176 @@
// 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);

/*
* Loads all resources for the game and gives them names.
/**
* Created by v3513 on 11/08/2015.
*/
var actions = { preload: preload, create: create, update: update };

var game = new Phaser.Game(790, 400, Phaser.AUTO, "game", actions);

var score = 0;

var labelScore;

var player;

var pipes = [];

var gapSize = 150;
var gapMargin = 50;
var blockHeight = 50;
var width = 790;
var height = 400;
var pipeEndHeight = 25;
var pipeEndExtraWidth = 10;



jQuery("#greeting-form").on("submit", function(event_details) {
var greeting = "Hello ";
var name = jQuery("#fullName").val();
var greeting_message = greeting + name;
jQuery("#greeting-form").hide();
jQuery("#greeting").append("<p>" + greeting_message + "</p>");
event_details.preventDefault();
});


function preload() {

game.load.image("playerIMG","../assets/burger2.gif");

game.load.audio("score", "../assets/point.ogg");

game.load.image("pipe","../assets/ketchupPipe.png");
game.load.image("background", "../assets/frenchfriesbackground.jpg");
game.load.image("pipeend", "../assets/pipe-end.png");
}

/*
* Initialises the game. This function is only called once.
*/

function create() {
// set the background colour of the scene

game.stage.setBackgroundColor("#F3D3A3");
game.add.sprite(0,0, "background");



labelScore = game.add.text(20, 0, "0",
{font: "30px Arial", fill: "#FFFFFF"});


var burger = player = game.add.sprite(80, 200, "playerIMG");
burger.scale.setTo(0.05, 0.05);


game.physics.startSystem(Phaser.Physics.ARCADE);

game.physics.arcade.enable(player);

player.body.gravity.y = 500;

game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(playerJump);

var pipeInterval = 1.75;
game.time.events.loop(pipeInterval * Phaser.Timer.SECOND, generatePipe);
player.anchor.setTo(0.5, 0.5);
}

/*
* This function updates the scene. It is called for every new frame.
*/

function update() {


game.physics.arcade
.overlap(player,
pipes,
gameOver);


if(player.y < 0 || player.y > 400){
gameOver();
}

player.rotation += 0.2;
}



function addPipeBlockD(x, y) {
var xyKetchup = 0.05;
var blockD = game.add.sprite(x,y,"pipe");

blockD.scale.setTo(-xyKetchup,-xyKetchup);

pipes.push(blockD);

game.physics.arcade.enable(blockD);

blockD.body.velocity.x = -200;
}

function addPipeBlockU(x, y) {
var xyKetchup = 0.05;

var blockU = game.add.sprite(x,y,"pipe");

blockU.scale.setTo(xyKetchup,xyKetchup);
pipes.push(blockU);

game.physics.arcade.enable(blockU);

blockU.body.velocity.x = -200;
}

function generatePipe() {
var gapStart = game.rnd.integerInRange(gapMargin, height - gapSize - gapMargin);

//addPipeEnd(width-(pipeEndExtraWidth/2), gapStart);
for(var y=gapStart-pipeEndHeight; y>0 ; y-=blockHeight) {
addPipeBlockD(width,y - blockHeight);
}

//addPipeEnd(width-(pipeEndExtraWidth/2), gapStart+gapSize-pipeEndHeight);
for(var y=gapStart+gapSize+pipeEndHeight; y<height; y+=blockHeight) {
addPipeBlockU(width,y);
}

//for(var y=gapStart; y > 0 ; y -= blockHeight){
// addPipeBlock(width,y - blockHeight);
//}
//
//for(var y = gapStart + gapSize; y < height; y += blockHeight) {
// addPipeBlock(width, y);
//}

changeScore();
}

function playerJump() {

player.body.velocity.y = -200;
}


function changeScore() {
//increments global score variable by 1
score++;
// updates the score label
labelScore.setText(score.toString());
}

function gameOver() {
// stop the game (update() function no longer called)
// game.destroy();
// game.paused = true;
game.state.restart();
$("#greeting").show();
score = 0;
}

function addPipeEnd(x,y) {
var block = game.add.sprite(x,y,"pipeend");
// insert it in the pipe array
pipes.push(block);
// enable physics engine for the block
game.physics.arcade.enable(block);
// set the block's horizontal velocity to a negative value
// (negative x value for velocity means movement will be towards left)
block.body.velocity.x = -200;
}
2 changes: 2 additions & 0 deletions node_modules/.bin/csv-reshuffle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/csv-reshuffle.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading