小鸟飞呀飞

欢迎来到程序小院

小鸟飞呀飞

玩法:鼠标控制小鸟飞翔的方向,点击鼠标左键上升,不要让小鸟掉落,从管道中经过,快去飞呀飞哦^^。

开始游戏icon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/204

html

  <canvas width="288" height="505"></canvas>

css

canvas {margin: 0 auto;
}

js

var game = new Phaser.Game(288, 505, Phaser.CANVAS, 'game');game.States = {};game.States.boot = function() {this.preload = function() {if(typeof(GAME) !== "undefined") {this.load.baseURL = GAME + "/";}if(!game.device.desktop){this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;this.scale.forcePortrait = true;this.scale.refresh();}game.load.image('loading', 'assets/preloader.gif');};this.create = function() {game.state.start('preload');};
};game.States.preload = function() {this.preload = function() {var preloadSprite = game.add.sprite(34, game.height/2, 'loading');game.load.setPreloadSprite(preloadSprite);game.load.image('background', 'assets/background.png');game.load.image('ground', 'assets/ground.png');game.load.image('title', 'assets/title.png');game.load.spritesheet('bird', 'assets/bird.png', 34, 24, 3);game.load.image('btn', 'assets/start-button.png');game.load.spritesheet('pipe', 'assets/pipes.png', 54, 320, 2);game.load.bitmapFont('flappy_font', 'assets/fonts/flappyfont/flappyfont.png', 'assets/fonts/flappyfont/flappyfont.fnt');game.load.audio('fly_sound', 'assets/flap.wav');game.load.audio('score_sound', 'assets/score.wav');game.load.audio('hit_pipe_sound', 'assets/pipe-hit.wav');game.load.audio('hit_ground_sound', 'assets/ouch.wav');game.load.image('ready_text', 'assets/get-ready.png');game.load.image('play_tip', 'assets/instructions.png');game.load.image('game_over', 'assets/gameover.png');game.load.image('score_board', 'assets/scoreboard.png');};this.create = function() {game.state.start('menu');};
};game.States.menu = function() {this.create = function() {var bg = game.add.tileSprite(0, 0, game.width, game.height, 'background');var ground = game.add.tileSprite(0, game.height-112, game.width, 112, 'ground');bg.autoScroll(-10 ,0);ground.autoScroll(-100 ,0);var titleGroup = game.add.group();titleGroup.create(0, 0, 'title');var bird = titleGroup.create(190, 10, 'bird');bird.animations.add('fly');bird.animations.play('fly', 12, true);titleGroup.x = 35;titleGroup.y = 100;game.add.tween(titleGroup).to({y: 120}, 1000, null, true, 0, Number.MAX_VALUE, true);var btn = game.add.button(game.width/2, game.height/2, 'btn', function() {game.state.start('play');});btn.anchor.setTo(0.5, 0.5);};
};game.States.play = function() {this.create = function() {this.bg = game.add.tileSprite(0, 0, game.width, game.height, 'background');this.pipeGroup = game.add.group();this.pipeGroup.enableBody = true;this.ground = game.add.tileSprite(0, game.height-112, game.width, 112, 'ground');this.bird = game.add.sprite(50, 150, 'bird');this.bird.animations.add('fly');this.bird.animations.play('fly', 12, true);this.bird.anchor.setTo(0.5, 0.5);game.physics.enable(this.bird, Phaser.Physics.ARCADE);this.bird.body.gravity.y = 0;game.physics.enable(this.ground, Phaser.Physics.ARCADE);this.ground.body.immovable = true;this.soundFly = game.add.sound('fly_sound');this.soundScore = game.add.sound('score_sound');this.soundHitPipe = game.add.sound('hit_pipe_sound');this.soundHitGround = game.add.sound('hit_ground_sound');this.scoreText = game.add.bitmapText(game.world.centerX - 20, 30, 'flappy_font', '0', 36);this.readyText = game.add.image(game.width/2, 40, 'ready_text');this.playTip = game.add.image(game.width/2, 300, 'play_tip');this.readyText.anchor.setTo(0.5, 0);this.playTip.anchor.setTo(0.5, 0);this.hasStarted = false;game.time.events.loop(900, this.generatePipes, this);game.time.events.stop(false);game.input.onDown.addOnce(this.startGame, this);};this.update = function() {if(!this.hasStarted) return;game.physics.arcade.collide(this.bird, this.ground, this.hitGround, null, this);game.physics.arcade.overlap(this.bird, this.pipeGroup, this.hitPipe, null, this);if(!this.bird.inWorld) this.hitCeil();if(this.bird.angle < 90) this.bird.angle += 2.5;this.pipeGroup.forEachExists(this.checkScore, this);};this.generatePipes = function() {var gap = 150;var difficulty = 100; // difficulty越大越简单var position = 50 + Math.floor((505 - 112 - difficulty - gap) * Math.random());var topPipeY = position - 320;var bottomPipeY = position + gap;if(this.resetPipe(topPipeY, bottomPipeY)) return;var topPipe = game.add.sprite(game.width, topPipeY, 'pipe', 0, this.pipeGroup);var bottomPipe = game.add.sprite(game.width, bottomPipeY, 'pipe', 1, this.pipeGroup);this.pipeGroup.setAll('checkWorldBounds', true);this.pipeGroup.setAll('outOfBoundsKill', true);this.pipeGroup.setAll('body.velocity.x', -this.gameSpeed);};this.startGame = function() {this.gameSpeed = 200;this.gameIsOver = false;this.hasHitGround = false;this.hasStarted = true;this.score = 0;this.bg.autoScroll(-(this.gameSpeed/10), 0);this.ground.autoScroll(-this.gameSpeed, 0);this.bird.body.gravity.y = 1150;this.readyText.destroy();this.playTip.destroy();game.input.onDown.add(this.fly, this);game.time.events.start();};this.stopGame = function() {this.bg.stopScroll();this.ground.stopScroll();this.pipeGroup.forEachExists(function(pipe) {pipe.body.velocity.x = 0;}, this);this.bird.animations.stop('fly', 0);game.input.onDown.remove(this.fly, this);game.time.events.stop(true);};this.fly = function() {this.bird.body.velocity.y = -350;game.add.tween(this.bird).to({angle: -30}, 100, null, true, 0, 0, false);this.soundFly.play();};this.hitCeil = function() {this.soundHitPipe.play();this.gameOver();};this.hitPipe = function() {if(this.gameIsOver) return;this.soundHitPipe.play();this.gameOver();};this.hitGround = function() {if(this.hasHitGround) return;this.hasHitGround = true;this.soundHitGround.play();this.gameOver(true);};this.gameOver = function(show_text) {this.gameIsOver = true;this.stopGame();if(show_text) this.showGameOverText();};this.showGameOverText = function() {this.scoreText.destroy();game.bestScore = game.bestScore || 0;if(this.score > game.bestScore) game.bestScore = this.score;this.gameOverGroup = game.add.group();var gameOverText = this.gameOverGroup.create(game.width/2, 0, 'game_over');var scoreboard = this.gameOverGroup.create(game.width/2, 70, 'score_board');var currentScoreText = game.add.bitmapText(game.width/2 + 60, 105, 'flappy_font', this.score+'', 20, this.gameOverGroup);var bestScoreText = game.add.bitmapText(game.width/2 + 60, 153, 'flappy_font', game.bestScore+'', 20, this.gameOverGroup);var replayBtn = game.add.button(game.width/2, 210, 'btn', function() {game.state.start('play');}, this, null, null, null, null, this.gameOverGroup);gameOverText.anchor.setTo(0.5, 0);scoreboard.anchor.setTo(0.5, 0);replayBtn.anchor.setTo(0.5, 0);this.gameOverGroup.y = 30;};this.resetPipe = function(topPipeY, bottomPipeY) {var i = 0;this.pipeGroup.forEachDead(function(pipe) {if(pipe.y <= 0) {pipe.reset(game.width, topPipeY);pipe.hasScored = false;} else {pipe.reset(game.width, bottomPipeY);}pipe.body.velocity.x = -this.gameSpeed;i++;}, this);return i == 2;};this.checkScore = function(pipe) {if(!pipe.hasScored && pipe.y <= 0 && pipe.x <= this.bird.x - 17 - 54) {pipe.hasScored = true;this.scoreText.text = ++this.score;this.soundScore.play();return true; }return false;};
};game.state.add('boot', game.States.boot);
game.state.add('preload', game.States.preload);
game.state.add('menu', game.States.menu);
game.state.add('play', game.States.play);game.state.start('boot');

源码icon-default.png?t=N7T8https://www.ormcc.com/

需要源码请关注添加好友哦^ ^

转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/150717.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

工业4.0时代,烤漆房控制柜如何远程监控?

烤漆房控制柜远程监控方案 一、现状 烤漆房是汽车、机械、家具等工业领域广泛应用的设备&#xff0c;主要用于产品的表面涂装。传统的烤漆房控制柜采用本地控制方式&#xff0c;操作人员在现场进行参数设置和设备控制。这种控制方式需要操作人员需要具备一定的专业知识&#x…

2023-2024华为ICT大赛-计算赛道-广东省省赛初赛-高职组-部分赛题分析【2023.11.18】

2023-2024华为ICT大赛 计算赛道 广东省 省赛 初赛 高职组 部分赛题 分析【2023.11.18】 文章目录 单选题tpcds模式中存在表customer&#xff0c;不能成功删除tpcds模式是&#xff08; &#xff09;以下哪个函数将圆转换成矩形&#xff08; &#xff09;下列哪个选项表示依赖该D…

MAC下MNMP应用程序mysql配置文件my.cnf放在哪里?

最近在测试远古的一段代码,有一段数据库报错代码 [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column otp.A.id which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_…

新版Testwell CTC++带来哪些新变化?

Testwell CTC在版本10中引入了新的工具ctcreport来直接从符号和数据文件生成HTML报告。详细的特性描述可以在测试井CTC帮助中找到。在本文档中&#xff0c;描述了与前一代报告相比的改进和变化。 Adaptable Layout可调整布局 您可以选择一个适合于项目结构的布局。布局决定了报…

Qt中的tr函数

2023年11月17日&#xff0c;周五上午 今天在学习Qt时&#xff0c;看到这样一行代码&#xff1a; setWindowTitle(tr("线程")); 于是我产生了几个疑问&#xff1a; 1、什么是tr函数&#xff1f; 2、为什么要写成setWindowTitle(tr("线程"))&#xff0c;…

three.js实现管道漫游

先看效果&#xff1a; <template><div><el-container><el-main><div class"box-card-left"><div id"threejs" style"border: 1px solid red"></div><div class"box-right"><pre s…

xaml自动格式化:各个属性分行放置

快捷键&#xff1a;CtrlKD 设置自己需要的属性&#xff1a;工具->选项->文本编辑器->XAML->Formatting 效果如下&#xff1a;

深度学习YOLO图像视频足球和人体检测 - python opencv 计算机竞赛

文章目录 0 前言1 课题背景2 实现效果3 卷积神经网络4 Yolov5算法5 数据集6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 深度学习YOLO图像视频足球和人体检测 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c;学长非…

【用unity实现100个游戏之16】Unity程序化生成随机2D地牢游戏1(附项目源码)

文章目录 先看看最终效果前言随机游走算法使用随机游走算法添加地板瓦片1. 新增TilemapVisualizer&#xff0c;用于可视化地图2. 瓦片素材 不运行执行程序化生成地牢方法1. 先简单重构代码2. 新增Editor脚本RandomDungeonGeneratorEditor 将参数保存到可编辑脚本对象&#xff0…

【前端】yarn install

yarn install yarn install 用于安装项目的所有依赖。 当你刚刚签出项目的代码时&#xff0c;或者当项目中的其他开发者添加了你需要选择的新依赖时&#xff0c;最常使用此方法。 如果你习惯使用 npm&#xff0c;你可能希望使用 --save 或 --save-dev。 这些已被 yarn add 和 …

Java-final

【1】修饰变量&#xff1b; 1.public class Test { 2. //这是一个main方法&#xff0c;是程序的入口&#xff1a; 3. public static void main(String[] args) { 4. //第1种情况&#xff1a; 5. //final修饰一个变量&#xff0c;变量的值不可以改变&#…

ios + vue3 Teleport + inset 兼容性问题

目录 1&#xff0c;问题表现2&#xff0c;解决步骤1&#xff0c;teleport 的问题2&#xff0c;inset 的问题3&#xff0c;teleport 的问题之二 1&#xff0c;问题表现 使用 vue3 的 Teleport 实现的 dialog 弹窗&#xff0c;但是在 ios app 中嵌套的 h5 中无法打开。 直接在io…

【考研数学】正交变换后如果不是标准型怎么办?| 关于二次型标准化的一些思考

文章目录 引言一、回顾二次型的定义是什么&#xff1f;什么叫标准二次型&#xff1f;怎么化为标准型&#xff1f; 二、思考写在最后 引言 前阵子做了下 20 年真题&#xff0c;问题大大的&#xff0c;现在订正到矩阵的第一个大题&#xff0c;是关于二次型正交变换的。和常规不同…

当代职场人做分析,当然要用大数据分析工具

不管是从效率、分析的可用性以及灵活性来看&#xff0c;用大数据分析工具都还板上钉钉的。毕竟大数据分析工具集齐了大数据时代数据分析工具应具备的特点优势。 1、对接ERP&#xff0c;立得100BI报表 点击对接金蝶、用友ERP后&#xff0c;BI系统立即即可取数分析&#xff0c;…

JS基础

javascript基础语言与其他语言大差不差&#xff0c;看代码理解即可。复习笔记 变量与数据类型 变量名要见名知意 变量名可以是字母、下划线、$&#xff0c;还有数字&#xff1b; 但是不能以数字开头小写字母开头&#xff0c; 多个单词&#xff0c;第二个单词首字母大写&#…

控制实体小车cartographer建图

cartographer建图 跑通官方例程 下载官方bag https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag运行bag roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:${HOME}/workspace/carto_ws…

Swift-day 2

1、数据绑定&#xff0c;改变标题 State private var zoomed: Bool false 属性包装器包装的变量self.title 单向绑定 self.$textInput 双向绑定 传的是数据结构 self.title self.textInput 赋值是String self._titletitle //绑定类型加下划线2、数据绑定&#xff0c;传递结构…

webrtc 生成unpack_aecdump工具

1.下载webrtc代码 2.terminal 进入src目录下 3.构建目录&#xff1a; terminal执行&#xff1a;gn gen out/Release --argsis_component_buildfalse 4.构建可执行文件&#xff1a; terminal执行&#xff1a;ninja -C out/Release/ unpack_aecdump &#xff08;有可能报错…

数据仓库_模型设计_学习目录

前言&#xff1a; 1、问什么要写这篇博客&#xff1f; 随着自己在数仓岗位工作的年限增加&#xff0c;对数仓的理解和认知也在发生着变化 所有用这篇博客来记录工作中用到的知识点与经验 2、这篇博客主要记录了那些内容&#xff1f; 主要会记录一些数仓建设方法论和工作技巧 目…

Paging3的使用踩坑记录

一、Paging3介绍 Paging3是jetpack推出的一个分页加载库&#xff0c;用于方便开发者实现分页加载功能&#xff0c;支持显示加载状态&#xff0c;重试机制&#xff0c;支持协程与RxJava结合使用&#xff0c;相对于传统的分页加载方案&#xff0c;我们不需要关注recyclerview的滑…