在网上学习了下“65行 JavaScript 代码实现 Flappy Bird 游戏”(http://blog.jobbole.com/61842/),main.js 如下:

// Initialize Phaser, and creates a 400x490px game
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');

// Creates a new 'main' state that wil contain the game
var main_state = {

preload:function() {

this.game.stage.backgroundColor = '#71c5cf';
this.game.load.image('bird','assets/bird.png');
this.game.load.image('pipe','assets/pipe.png');
},

create:function() {

this.bird = this.game.add.sprite(100,245,'bird');
this.bird.body.gravity.y = 1000;

this.pipes = game.add.group();
this.pipes.createMultiple(20,'pipe');

var space_key =
this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
space_key.onDown.add(this.jump,this);

this.timer = this.game.time.events.loop(1500,this.add_row_of_pipes,this);

this.score = 0;
var style = { font:"30px Arial",fill:"#ffffff"};
this.label_score = this.game.add.text(20,20,"0",style);

},

update: function() {

if(this.bird.inWorld == false)
this.restart_game();

this.game.physics.overlap(this.bird,this.pipes,this.restart_game,null,this);
},

jump:function(){
this.bird.body.velocity.y = -350;
},

restart_game:function(){
this.game.time.events.remove(this.timer);

this.game.state.start('main');

},

add_one_pipe:function(x,y){
var pipe = this.pipes.getFirstDead();
pipe.reset(x,y);
pipe.body.velocity.x = -200;
pipe.outOfBoundsKill = true;
},

add_row_of_pipes:function(){

var hole = Math.floor(Math.random()*5)+ 1;

for(var i = 0; i < 8; i++)
if(i != hole && i != hole + 1)

this.add_one_pipe(400,i*60+10);

this.score += 1;
this.label_score.content = this.score;

},
};

game.state.add('main', main_state);
game.state.start('main');

学着网上的代码写,感觉这个小游戏实现起来看起来也挺简单挺有意思的,javascript代码编辑起来,用的Editplus,以至于background写成backgroud查了好久,最后用了winMerge才查出来。工欲善其事,必先利其器。

Flappy Bird的更多相关文章

  1. canvas 制作flappy bird(像素小鸟)全流程

    flappy bird制作全流程: 一.前言 像素小鸟这个简单的游戏于2014年在网络上爆红,游戏上线一段时间内appleStore上的下载量一度达到5000万次,风靡一时, 近年来移动web的普及为 ...

  2. 自己动手写游戏:Flappy Bird

    START:最近闲来无事,看了看一下<C#开发Flappy Bird游戏>的教程,自己也试着做了一下,实现了一个超级简单版(十分简陋)的Flappy Bird,使用的语言是C#,技术采用了 ...

  3. C语言版flappy bird黑白框游戏

    在此记录下本人在大一暑假,2014.6~8这段时间复习C语言,随手编的一个模仿之前很火热的小游戏----flappy bird.代码bug基本被我找光了,如果有哪位兄弟找到其他的就帮我留言下吧,谢谢了 ...

  4. 闲扯游戏编程之html5篇--山寨版《flappy bird》源码

    新年新气象,最近事情不多,继续闲暇学习记点随笔,欢迎拍砖.之前的〈简单游戏学编程语言python篇〉写的比较幼稚和粗糙,且告一段落.开启新的一篇关于javascript+html5的从零开始的学习.仍 ...

  5. 【Unity3D基础教程】给初学者看的Unity教程(四):通过制作Flappy Bird了解Native 2D中的RigidBody2D和Collider2D

    作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 引子 在第一篇文章[Unity3D基础教程] ...

  6. 65行 JavaScript 代码实现 Flappy Bird 游戏

    飞扬的小鸟(Flappy Bird)无疑是2014年全世界最受关注的一款游戏.这款游戏是一位来自越南河内的独立游戏开发者阮哈东开发,形式简易但难度极高的休闲游戏,很容易让人上瘾. 这里给大家分享一篇这 ...

  7. 用Phaser来制作一个html5游戏——flappy bird (二)

    在上一篇教程中我们完成了boot.preload.menu这三个state的制作,下面我们就要进入本游戏最核心的一个state的制作了.play这个state的代码比较多,我不会一一进行说明,只会把一 ...

  8. 用Phaser来制作一个html5游戏——flappy bird (一)

    Phaser是一个简单易用且功能强大的html5游戏框架,利用它可以很轻松的开发出一个html5游戏.在这篇文章中我就教大家如何用Phaser来制作一个前段时间很火爆的游戏:Flappy Bird,希 ...

  9. [android]亲自破解Flappy Bird(去广告+永生)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3544785.html  听说最近Flappy Bird很火,但 ...

  10. 用Phaser实现Flappy Bird 游戏

    How to Make a Flappy Bird in HTML5 With Phaser - Part 1 Flappy Bird is a nice little game with easy ...

随机推荐

  1. IDEA自动编译设置

    ctrl+alt+s: ctrl+shift+alt+/:

  2. php-fpm开机自动启动脚本其实源码包里边就有

    网上有各种版本的php-fpm开机自动启动脚本, 其实你编译后源目录已经生成自动脚本.不用做任何修改即用.cp {php-5.5.x-source-dir}/sapi/fpm/init.d.php-f ...

  3. Redis JdkSerializationRedisSerializer,stringRedisSerializer,ProtoBuf 体积,性能简单比较.

    /** * User: laizhenwei * Date: 2018-04-10 Time: 14:17 * Description: */ @RunWith(SpringRunner.class) ...

  4. [原]Jenkins(九)---jenkins分别发布多个项目到多个远程主机

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...

  5. jenkins实战(二):构建自由风格的maven项目

    本系列打算全面介绍jenkins的常规使用,这是第二篇,之前的文章在: jenkins实战(一):war安装及插件安装 一.新建项目 1.新建项目 此处我们打算新建自由风格项目,见下图. 值得注意的是 ...

  6. sometimes we should use "disable fork" instead of "disable block_name"

    A disable named block statement stops the execution of all blocks with that same name in all threads ...

  7. IDEA中将WEB-INF\lib下的Jar包添加到项目中

    打开Project Structure[可以使用快捷键:Ctrl+Alt+Shift+S]左侧选中Modules,在Dependecies中,点击右侧“+”号,选择JARS or directorie ...

  8. Android所有Demo资源汇总,太全了(申明:来源于网络)

    Android所有Demo资源汇总,太全了(申明:来源于网络) 地址:http://bbs.csdn.net/topics/391928947

  9. got positional argument after named arguments.原因

  10. process 多进程写法 multiprocessing

    from multiprocessing import Process def   f1(n):#普通 print(f1) if __name__ == '__main__': lst = [] fo ...