JSFiddle - React, Tailwind, and code Playground
by Duyệt Lê Văn
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/phaser/1.1.5/phaser.min.js"></script>
<h1>LvDuit</h1>
<p>Nhấn spacebar để nhảy</p>
<div id="game_div"> </div>
<p>Xem bài viết để viết game này tại <a href="http://lvduit.blogspot.com/2014/03/huong-dan-viet-game-flappy-bird-bang.html">đây</a></p>
JavaScript
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
var game_state = {};
game_state.main = function() { };
game_state.main.prototype = {
preload: function() {
this.game.stage.backgroundColor = '#71c5cf';
this.game.load.image('bird', 'http://4.bp.blogspot.com/-ML1GnQDGOTw/UxGMQ5OAsgI/AAAAAAAAGXM/wFSO0MQv1hU/s1600/bird.png');
this.game.load.image('pipe', 'http://1.bp.blogspot.com/-A4kTPRPn1LU/UxGMQ6MHeMI/AAAAAAAAGXQ/gJOQ6TFo0Tw/s1600/pipe.png');
// Load jump sound
this.game.load.audio('jump', 'http://lessmilk.com/flappy_bird/02/assets/jump.wav');
},
create: function() {
var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
space_key.onDown.add(this.jump, this);
this.pipes = game.add.group();
this.pipes.createMultiple(20, 'pipe');
this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);
this.bird = this.game.add.sprite(100, 245, 'bird');
this.bird.body.gravity.y = 1000;
// Change the anchor point of the bird
this.bird.anchor.setTo(-0.2, 0.5);
this.score = 0;
var style = { font: "30px Arial", fill: "#ffffff" };
this.label_score = this.game.add.text(20, 20, "0", style);
// Add sounds to the game
this.jump_sound = this.game.add.audio('jump');
this.hit_sound = this.game.add.audio('hit');
},
update: function() {
if (this.bird.inWorld == false)
this.restart_game();
if (this.bird.angle < 20)
this.bird.angle += 1;
this.game.physics.overlap(this.bird, this.pipes, this.hit_pipe, null, this);
},
jump: function() {
// if the bird hit a pipe, no jump
if (this.bird.alive == false)
return;
this.bird.body.velocity.y = -350;
// Rotate the bird
this.game.add.tween(this.bird).to({angle:...