往上走^^

news2024/9/29 13:28:49

欢迎来到程序小院

往上走

玩法:转动的圆球,点击固定到上方的圆中即可往上走一步,转动超过上面圆即游戏结束,
往上走一步加1分,快去往上走吧^^。

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

html

  <canvas width="640" height="960"></canvas>

css

canvas {
  display: block; 
  touch-action: none; 
  user-select: none; 
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 
  width: 367px; 
  height: 550px; 
  margin-left: 357px; 
  margin-top: 0px; 
  cursor: inherit;
  }

js

var ballDistance = 120;
var rotationSpeed = 4;
var angleRange = [25, 155];
var visibleTargets = 7;
var bgColovar game;
var ballDistance = 120;
var rotationSpeed = 4;
var angleRange = [25, 155];
var visibleTargets = 7;
var bgColors = [0x62bd18, 0xffbb00, 0xff5300, 0xd21034, 0xff475c, 0x8f16b2];
window.onload = function() {
     game = new Phaser.Game(640, 960, Phaser.CANVAS, "");
     game.state.add("PlayGame", playGame);
     game.state.start("PlayGame");
}
playGame.prototype = {
     preload: function(){
          game.load.image("ball", "assets/ball.png");
          game.load.image("target", "assets/target.png");
          game.load.image("arm", "assets/arm.png");
          game.scale.pageAlignHorizontally = true;
          game.scale.pageAlignVertically = true;
          game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
     },
     create: function(){
          this.savedData = localStorage.getItem("circlepath")==null?{score:0}:
          JSON.parse(localStorage.getItem("circlepath"));
          var style = {
               font: "bold 32px Arial",
               fill: "#ffffff"
          };
          var text = game.add.text(0, game.height - 64, "Best score: "+
          this.savedData.score.toString(), style);
          this.destroy = false;
          this.saveRotationSpeed = rotationSpeed;
          this.tintColor = bgColors[game.rnd.between(0, bgColors.length - 1)];
          do{
               this.tintColor2 = bgColors[game.rnd.between(0, bgColors.length - 1)];
          } while(this.tintColor == this.tintColor2)
          game.stage.backgroundColor = this.tintColor;
          this.targetArray = [];
          this.steps = 0;
          this.rotatingDirection = game.rnd.between(0, 1);
          this.gameGroup = game.add.group();
          this.targetGroup = game.add.group();
          this.ballGroup = game.add.group();
          this.gameGroup.add(this.targetGroup);
          this.gameGroup.add(this.ballGroup);
          this.arm = game.add.sprite(game.width / 2, game.height / 4 * 2.7, "arm");
          this.arm.anchor.set(0, 0.5);
          this.arm.tint = this.tintColor2;
          this.ballGroup.add(this.arm);
          this.balls = [
               game.add.sprite(game.width / 2, game.height / 4 * 2.7, "ball"),
               game.add.sprite(game.width / 2, game.height / 2, "ball")
          ]
          this.balls[0].anchor.set(0.5);
          this.balls[0].tint = this.tintColor2;
          this.balls[1].anchor.set(0.5);
          this.balls[1].tint = this.tintColor2;
          this.ballGroup.add(this.balls[0]);
          this.ballGroup.add(this.balls[1]);
          this.rotationAngle = 0;
          this.rotatingBall = 1;
          var target = game.add.sprite(0, 0, "target");
          target.anchor.set(0.5);
          target.x = this.balls[0].x;
          target.y = this.balls[0].y;
          this.targetGroup.add(target);
          this.targetArray.push(target);
          game.input.onDown.add(this.changeBall, this);
          for(var i = 0; i < visibleTargets; i++){
               this.addTarget();
          }

     },
     update: function(){
          var distanceFromTarget = this.balls[this.rotatingBall].position.distance(
          this.targetArray[1].position);
          if(distanceFromTarget > 90 && this.destroy && this.steps > visibleTargets){
               this.gameOver();
          }
          if(distanceFromTarget < 40 && !this.destroy){
               this.destroy = true;
          }
          this.rotationAngle = (this.rotationAngle + this.saveRotationSpeed * (
          this.rotatingDirection * 2 - 1)) % 360;
          this.arm.angle = this.rotationAngle + 90;
          this.balls[this.rotatingBall].x = this.balls[1 - this.rotatingBall].x - 
          ballDistance * Math.sin(Phaser.Math.degToRad(this.rotationAngle));
          this.balls[this.rotatingBall].y = this.balls[1 - this.rotatingBall].y + 
          ballDistance * Math.cos(Phaser.Math.degToRad(this.rotationAngle));
          var distanceX = this.balls[1 - this.rotatingBall].worldPosition.x - 
          game.width / 2;
          var distanceY = this.balls[1 - this.rotatingBall].worldPosition.y - 
          game.height / 4 * 2.7;
          this.gameGroup.x = Phaser.Math.linearInterpolation([this.gameGroup.x, 
          this.gameGroup.x - distanceX], 0.05);
          this.gameGroup.y = Phaser.Math.linearInterpolation([this.gameGroup.y, 
          this.gameGroup.y - distanceY], 0.05);
     },
     changeBall:function(){
          this.destroy = false;
          var distanceFromTarget = this.balls[this.rotatingBall].position.distance(
          this.targetArray[1].position);
          if(distanceFromTarget < 20){
               this.rotatingDirection = game.rnd.between(0, 1);
               var detroyTween = game.add.tween(this.targetArray[0]).to({
                    alpha: 0
               }, 500, Phaser.Easing.Cubic.In, true);
               detroyTween.onComplete.add(function(e){
                    e.destroy();
               })
               this.targetArray.shift();
               this.arm.position = this.balls[this.rotatingBall].position;
               this.rotatingBall = 1 - this.rotatingBall;
               this.rotationAngle = this.balls[1 - this.rotatingBall].position.angle(
               this.balls[this.rotatingBall].position, true) - 90;
               this.arm.angle = this.rotationAngle + 90;
               for(var i = 0; i < this.targetArray.length; i++){
                    this.targetArray[i].alpha += 1 / 7;
               }
               this.addTarget();
          }
          else{
               this.gameOver();
          }
     },
     addTarget: function(){
          this.steps++;
          startX = this.targetArray[this.targetArray.length - 1].x;
          startY = this.targetArray[this.targetArray.length - 1].y;
          var target = game.add.sprite(0, 0, "target");
          var randomAngle = game.rnd.between(angleRange[0] + 90, angleRange[1] + 90);
          target.anchor.set(0.5);
          target.x = startX + ballDistance * Math.sin(Phaser.Math.degToRad(randomAngle));
          target.y = startY + ballDistance * Math.cos(Phaser.Math.degToRad(randomAngle));
          target.alpha = 1 - this.targetArray.length * (1 / 7);
          var style = {
               font: "bold 32px Arial",
               fill: "#" + this.tintColor.toString(16),
               align: "center"
          };
          var text = game.add.text(0, 0, this.steps.toString(), style);
          text.anchor.set(0.5);
          target.addChild(text);
          this.targetGroup.add(target);
          this.targetArray.push(target);
     },
     gameOver: function(){
          localStorage.setItem("circlepath",JSON.stringify({
               score: Math.max(this.savedData.score, this.steps - visibleTargets)
          }));
          game.input.onDown.remove(this.changeBall, this);
          this.saveRotationSpeed = 0;
          this.arm.destroy();
          var gameOverTween = game.add.tween(this.balls[1 - this.rotatingBall]).to({
               alpha: 0
          }, 1000, Phaser.Easing.Cubic.Out, true);
          gameOverTween.onComplete.add(function(){
               game.state.start("PlayGame");
          },this)
     }
}rs = [0x62bd18, 0xffbb00, 0xff5300, 0xd21034, 0xff475c, 0x8f16b2];

window.onload = function() { 
 game = new Phaser.Game(640, 960, Phaser.CANVAS, "");
     game.state.add("PlayGame", playGame);
     game.state.start("PlayGame");
}

源码

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

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

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

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

相关文章

【CCF BDCI 2023】多模态多方对话场景下的发言人识别 Baseline 0.71 Slover 部分

【CCF BDCI 2023】多模态多方对话场景下的发言人识别 Baseline 0.71 Slover 部分 概述Solver 在多模态发言人识别中的作用Solver 在多模态发言人识别中的重要性Solver 的工作原理 二次规划二次规划的基本形式二次规划的特点二次规划在多模态发言中的应用 (我的理解) 代码详解数…

单端反激(离散系统仿真)

单端反激&#xff08;离散系统仿真&#xff09; 指令电压为0,电机微速旋转,补足指令电压。 把仿真变成离散的。 最大步长设置方法&#xff1a;如果是对于相控形式的电路&#xff0c;我觉得设置1e-4秒大概就够了&#xff0c;如果是对于斩波形式的电路&#xff0c;设置1e-6或者…

oracle数据恢复—Oracle报错“system01.dbf需要更多的恢复来保持一致性”的数据恢复案例

oracle数据库恢复环境&故障&#xff1a; 一台Windows server操作系统的服务器上部署Oracle数据库。 服务器意外断电导致oracle数据库报错&#xff0c;报错信息&#xff1a;“system01.dbf需要更多的恢复来保持一致性”。由于该oracle数据库并没有备份&#xff0c;仅有一些断…

JS数组与它的42个方法

前言 数组在js中作为一个非常重要的类型之一&#xff0c;在我们对数据处理&#xff0c;存储数据&#xff0c;条件渲染的时候经常会用到&#xff0c;所以随着ES的不断更新&#xff0c;数组的方法也是越来越多&#xff0c;也让我们使用数组对数据操作的时候&#xff0c;越来越简…

WPF实现更加灵活绑定复杂Command(使用Microsoft XAML Behaviors 库)

1、安装NuGet 2、在XAML的命名空间引入&#xff1a; xmlns:i"http://schemas.microsoft.com/xaml/behaviors" 3、使用&#xff1a; <Canvas Background"Aqua"><Rectangle Stroke"Red" Width"{Binding RectModel.RectangleWidth}…

Java数据结构篇——实现顺序表的增删查改

文章目录 1.线性表2. 顺序表2.1 顺序表结构2.2 实现顺序表接口2.3 打印顺序表2.2 实现新增元素2.3 实现查找元素2.3 获取pos位置的值2.4 删除元素2.5 获取顺序表的长度2.6 清空顺序表 3.代码在这 1.线性表 定义&#xff1a;线性表是 n 个具有相同特性的数据元素的有序序列。线…

07.CSS常用样式

CSS常用样式 1.颜色样式 颜色名 介绍 直接使用颜色对应的英文单词&#xff0c;编写比较简单 具体颜色名参考 MDN 官方文档 例子 p {color:red; }缺点 颜色名这种方式&#xff0c;表达的颜色比较单一&#xff0c;所以用的并不多 rgb或rgba 介绍 使用 红、黄、蓝 这三…

【文末送书】以企业架构为中心的SABOE数字化转型五环法

欢迎关注博主 Mindtechnist 或加入【智能科技社区】一起学习和分享Linux、C、C、Python、Matlab&#xff0c;机器人运动控制、多机器人协作&#xff0c;智能优化算法&#xff0c;滤波估计、多传感器信息融合&#xff0c;机器学习&#xff0c;人工智能等相关领域的知识和技术。关…

JVM对象创建与内存分配机制分析

对象的创建 对象创建的主要流程: 1.类加载检查 虚拟机遇到一条new指令时&#xff0c;首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用&#xff0c;并且检查这个符号引用代表的类是否已被加载、解析和初始化过。如果没有&#xff0c;那必须先执行相应的类加…

动手学习深度学习-现代循环神经网络

门控循环单元(GRU) 重置门和更新门 重置门&#xff08;Reset Gate&#xff09;和更新门&#xff08;Update Gate&#xff09;是循环神经网络&#xff08;Recurrent Neural Network, RNN&#xff09;的变体之一&#xff0c;门控循环单元&#xff08;Gated Recurrent Unit, GRU&…

qiankun中子系统变化透传到主系统调用主系统方法

1、首先在主系统中qiankun启动前把变动的参数初始化 2、初始化之后就可以通过全局状态通信把参数透传为全局 3、在微应用子系统main.js的qiankun的mount中获取到全局设备参数属性并是设置为子系统全局 4、在微应用子系统中需要去调主系统方法时就在那个地方改变透传过来的参数 …

Rust语言基础语法使用

1.安装开发工具: RustRover JetBrains: Essential tools for software developers and teams 下载: RustRover: Rust IDE by JetBrains 下载成功后安装并启动RustRover 安装中文语言包插件 重启RustRover生效

Java毕业设计—vue+SpringBoot图书借阅管理系统

图书管理系统 1. 开发目的 实现图书的智能化、信息化和简单化&#xff1b;实现图书信息的增加、删除、修改、查找、借阅、还书、收藏的显示操作及实时数据库的提交和更改和对普通用户的增、删、改、查&#xff1b;提高图书管理员工作信息报送及反馈的工作效率&#xff0c;减轻…

【文末送书】拥抱人工智能

欢迎关注博主 Mindtechnist 或加入【智能科技社区】一起学习和分享Linux、C、C、Python、Matlab&#xff0c;机器人运动控制、多机器人协作&#xff0c;智能优化算法&#xff0c;滤波估计、多传感器信息融合&#xff0c;机器学习&#xff0c;人工智能等相关领域的知识和技术。关…

vcpkg下载及安装

文章目录 vcpkg是什么vcpkg的优势Windows环境下的下载及安装1.下载 Linux环境下的下载及安装常用命令介绍1.1.1 设置默认安装的平台1.1.2可选步骤&#xff0c;将vcpkg与Visual Studio配合使用&#xff08;需要管理员权限&#xff09;1.1.3 软件包升级1.1.4 查找安装软件包1.1.5…

linux下time与dd命令结合测试存储器速度

在Linux中&#xff0c;"time"和"dd"命令是两个独立的命令&#xff0c;它们可以结合使用来测量"dd"命令执行的时间。 下面是它们的简要说明&#xff1a; time命令&#xff1a; "time"命令用于测量命令执行的时间和资源使用情况。它可以…

数据库传奇:MySQL创世之父的两千金My、Maria

《数据库传奇&#xff1a;MySQL创世之父的两千金My、Maria》 一、前言 MySQL是一款备受欢迎的关系型数据库管理系统&#xff08;RDBMS&#xff09;&#xff0c;最初由瑞典公司MySQL AB开发&#xff0c;目前隶属于Oracle Corporation。在DB-Engines的排名中&#xff0c;MySQL稳…

计网Lesson9 - 链路协议和网络概述

文章目录 数据链路层协议Ethernet V2标准Ethernet V2帧格式Ethernet V2帧长度标准以太网帧 MAC 帧协议 PPP 协议PPP 概述PPP 帧 网络层网络层的设计选择 数据链路层协议 Ethernet V2标准 Ethernet V2帧格式 以太网帧格式说明&#xff1a; 6 6 6 字节目标地址 6 6 6 字节源地…

【广州华锐视点】物流数字孪生三维可视化系统打造更高效、智能的物流管理体验

在当今快速发展的物流行业中&#xff0c;传统的管理和监控方法往往难以满足复杂运营的需求。为了解决这个问题&#xff0c;广州华锐互动提供物流数字孪生三维可视化系统定制开发服务&#xff0c;打造更为高效、智能的物流管理体验。 物流数字孪生三维可视化系统是一种基于虚拟现…

【算法与数据结构】455、LeetCode分发饼干

文章目录 一、题目二、解法三、完整代码 所有的LeetCode题解索引&#xff0c;可以看这篇文章——【算法和数据结构】LeetCode题解。 一、题目 二、解法 思路分析&#xff1a;因为大饼干可以满足大胃口的孩子也必然可以满足小胃口的孩子&#xff0c;如果要尽可能的满足孩子的胃口…