Flappy Bird
在网上学习了下“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的更多相关文章
- canvas 制作flappy bird(像素小鸟)全流程
flappy bird制作全流程: 一.前言 像素小鸟这个简单的游戏于2014年在网络上爆红,游戏上线一段时间内appleStore上的下载量一度达到5000万次,风靡一时, 近年来移动web的普及为 ...
- 自己动手写游戏:Flappy Bird
START:最近闲来无事,看了看一下<C#开发Flappy Bird游戏>的教程,自己也试着做了一下,实现了一个超级简单版(十分简陋)的Flappy Bird,使用的语言是C#,技术采用了 ...
- C语言版flappy bird黑白框游戏
在此记录下本人在大一暑假,2014.6~8这段时间复习C语言,随手编的一个模仿之前很火热的小游戏----flappy bird.代码bug基本被我找光了,如果有哪位兄弟找到其他的就帮我留言下吧,谢谢了 ...
- 闲扯游戏编程之html5篇--山寨版《flappy bird》源码
新年新气象,最近事情不多,继续闲暇学习记点随笔,欢迎拍砖.之前的〈简单游戏学编程语言python篇〉写的比较幼稚和粗糙,且告一段落.开启新的一篇关于javascript+html5的从零开始的学习.仍 ...
- 【Unity3D基础教程】给初学者看的Unity教程(四):通过制作Flappy Bird了解Native 2D中的RigidBody2D和Collider2D
作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 引子 在第一篇文章[Unity3D基础教程] ...
- 65行 JavaScript 代码实现 Flappy Bird 游戏
飞扬的小鸟(Flappy Bird)无疑是2014年全世界最受关注的一款游戏.这款游戏是一位来自越南河内的独立游戏开发者阮哈东开发,形式简易但难度极高的休闲游戏,很容易让人上瘾. 这里给大家分享一篇这 ...
- 用Phaser来制作一个html5游戏——flappy bird (二)
在上一篇教程中我们完成了boot.preload.menu这三个state的制作,下面我们就要进入本游戏最核心的一个state的制作了.play这个state的代码比较多,我不会一一进行说明,只会把一 ...
- 用Phaser来制作一个html5游戏——flappy bird (一)
Phaser是一个简单易用且功能强大的html5游戏框架,利用它可以很轻松的开发出一个html5游戏.在这篇文章中我就教大家如何用Phaser来制作一个前段时间很火爆的游戏:Flappy Bird,希 ...
- [android]亲自破解Flappy Bird(去广告+永生)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3544785.html 听说最近Flappy Bird很火,但 ...
- 用Phaser实现Flappy Bird 游戏
How to Make a Flappy Bird in HTML5 With Phaser - Part 1 Flappy Bird is a nice little game with easy ...
随机推荐
- 《Python3网络爬虫开发实战》
推荐:★ ★ ★ ★ ★ 第1章 开发环境配置 第2章 网页基础知识 第3章 网络爬虫基础 第4章 基本库的使用 第5章 解析库的使用 第6章 数据存储 第7章 Ajax数据爬取 第8章 动态渲染页面 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验四:按键模块③ — 单击与双击
实验四:按键模块③ - 单击与双击 实验三我们创建了"点击"还有"长点击"等有效按键的多功能按键模块.在此,实验四同样也是创建多功能按键模块,不过却有不同的有效 ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- 使用 vm 加载文件中的数据到变量里面
.json 不能写注释, 还需要严格的双引号 或者使用 .json5 // test.db [ // name {name: 1} ] // test.js const fs = require('f ...
- ELK(Elasticsearch6.0以上版本head插件安装)
参考:https://www.cnblogs.com/Onlywjy/p/Elasticsearch.html Elasticsearch6.0不能使用命令直接安装head插件 修改配置文件/etc/ ...
- Jexus 安装asp.net mvc EF 项目引发的错误总
1.Linux 中的文件路径问题(配置文件路径),必须使用左斜杆 “/” 2.MVC 看 View/Web.config 下的配置文件中版本不对报错,如下: Could not locate Razo ...
- 程序报错java.lang.OutOfMemoryError: PermGen space
参考文档: http://www.cnblogs.com/xwdreamer/archive/2011/11/21/2296930.html http://www.cnblogs.com/ceshi2 ...
- 一、SQL定义变量
http://blog.csdn.net/changwei07080/article/details/7561602 在SQL我们使用declare定义局部变量,同时可以使用set和select 对变 ...
- CCPC-Wannafly Winter Camp Day4 Div1 - 最小边覆盖 - [线段树]
题目链接:https://zhixincode.com/contest/18/problem/C?problem_id=261 样例输入 1 4 21 23 4 样例输出 1 Yes 样例输入 2 4 ...
- MySql数据库笔试题总结
数据库面试题94577265 1,设有关系EMP(ENO,ENAME,SALARY,DNO),其中各属性的含义依次为职工号.姓名.工资和所在部门号,以及关系DEPT(DNO,DNAME,MANAGER ...