Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
<title>Browser Games</title>
</head>
<body>
<h1>Browser Games</h1>
<h1>Briy's Browser Games</h1>

<p>A collection of games to play in a web browser.</p>

<hr>

<nav>
<ul>
<li><a>LINK TO FIRST GAME</a></li>
<h4>Click the link below to play my Flappy Bird game.</h4>
<li><a>/Users/Briy_/LGProjects/browser-games/flappy-index.html</a></li>
<li><a>LINK TO SECOND GAME</a></li>
<li>...</li>
</ul>
</nav>
<script src='flappy'
</body>
</html>
11 changes: 11 additions & 0 deletions public/flappy-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Get YOur Flap On</title>
</head>
<body>
<script type='text/javascript' src='js/flappy-phaser.min.js'></script>
<script type='text/javascript' src='js/flappy-main.js'></script>
</body>
</html>
Binary file added public/img/bird.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 public/img/coin.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 public/img/pipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions public/js/flappy-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//initialize phaser framework and create board
var flappy = new Phaser.Game(400, 499)
//creates the main state for the game
var mainState = {
preload: function() {
flappy.load.image('bird', 'img/bird.png')
flappy.load.image('pipe', 'img/pipe.png')
flappy.load.audio('jump', 'sounds/jump.wav')
// flappy.load.spritesheet('coin', 'coin.png', 22, 22)
},
create: function() {
var spaceBar = flappy.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)
//makes bird able to fall
spaceBar.onDown.add(this.jump, this)
flappy.stage.backgroundColor = '#B22222'
//sets game physics
flappy.physics.startSystem(Phaser.Physics.ARCADE)
//start arcade physics
flappy.physics.startSystem(Phaser.Physics.Arcade)
//displays the bird at x/y starting points
this.bird = flappy.add.sprite(100, 245, 'bird')
//add movement to bird
flappy.physics.arcade.enable(this.bird)
//adds physics to all game objects
flappy.world.enableBody = true
//create empty group
this.pipes = flappy.add.group()
this.bird.body.gravity.y = 1000
this.timer = flappy.time.events.loop(1500, this.addRowOfPipes, this)
this.score = 0
this.labelScore = flappy.add.text(20, 20, '0', {
font: '30px Arial', fill: '#FFD700'
})
// this.coins = this.flappy.add.group()
// data.coins.forEach(this.coin, this);
//move anchor left and downward
this.bird.anchor.setTo(-0.2, 0.5)
this.jumpSound = flappy.add.audio('jump')
},
// coin: function (coin) {
// let money = this.coins.create(coin.x, coin.y, 'coin')
// money.anchor.set(0.5, 0.5)
//
// money.animations.add('rotate', [0, 1, 2, 1], 6, true); // 6fps, looped
// money.animations.play('rotate');
// },
addOnePipe: function(x,y) {
//create pipe
var pipe = flappy.add.sprite(x,y, 'pipe')
//add pipe to group
this.pipes.add(pipe)
flappy.physics.arcade.enable(pipe)
pipe.body.velocity.x = -200
pipe.checkWorldBounds = true
pipe.outOfBoundsKill = true
},
addRowOfPipes: function() {
var hole = Math.floor(Math.random() * 6) + 1
for (var i = 0; i < 8; i++)
if(i != hole && i != hole + 1 && i != hole + 2)
this.addOnePipe(400, i * 60 + 1)
//increase score when pass pipes
this.score += 1
this.labelScore.text = this.score
},
hitPipe: function() {
//bird hit pipe restart game
if (this.bird.alive == false)
return;
this.bird.alive = false
flappy.time.events.remove(this.timer)
this.pipes.forEach(function(p){
p.body.velocity.x = 0
}, this)
},
update: function() {
//when the bird goes off the screen the game will reset
if(this.bird.y < 0 || this.bird.y > 490)
this.restartGame()
//restart game on collision
flappy.physics.arcade.overlap(this.bird, this.pipes, this.hitPipe, null, this)
//rotates bird
if (this.bird.angle < 20)
this.bird.angle += 1
},
jump: function() {
var animation = flappy.add.tween(this.bird).to({angle: -20}, 100).start
//stops dead bird from jumping
if (this.bird.alive === false)
return;
//adds vertical velocity to bird
this.bird.body.velocity.y = -350
this.jumpSound.play()
},
restartGame: function() {
//start game over
flappy.state.start('main')
}
}
//add the mainState and call it
flappy.state.add('main', mainState)
//makes mainState start the game
flappy.state.start('main')
27 changes: 27 additions & 0 deletions public/js/flappy-phaser.min.js

Large diffs are not rendered by default.

Binary file added public/sounds/jump.wav
Binary file not shown.