空中跳一跳

news2024/10/5 14:26:28

欢迎来到程序小院

空中跳一跳

玩法:
跳一跳长按鼠标左键,松开鼠标进行跳跃,跳到下一个格子中,进行分数统计,三次生命机会,格子中也会有爱心出现,吃掉安心增加一次生命哦^^。

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

html

<div id="game"></div>

css

#game canvas {
    position: relative;
    margin: 0 auto;
}

js

var mainState = function(game){
  var group, player, effect, point;

  var moving; // 用于记录tween动画状态
  var holding;  // 用于记录鼠标按下状态
  var holdTime; // 用于记录鼠标按下时间

  this.pArr = [17,15,12,10,15,13,8,17]; // 各种类型平台宽度,与平台spritesheet各帧对应
  this.init = function(){

    moving = true;
    holding = false;
    holdTime = 0;

    this.lastX = 40;// 最后一次的距离、方向、平台类型
    this.lastY = 20;
    this.lastD = 1;
    this.lastP = 0;

    this.bonus = 0;
    this.playerStyle = this.game.playerStyle; // 角色样式,对应帧号
    this.items = {txt:[null,null,null],val:[0,3,3]}; // 游戏数据在一个对象中保存:[分数,生命,瞄准器]
  };
  this.create = function(){
    var back = this.game.add.sprite(0,0,"back");
    back.scale.set(this.game.width/160,this.game.height/280);
    // clouds
    for (var i=0; i<3; i++){
      var firstX = this.game.rnd.between(20,this.game.width-20);
      var firstTime = Math.floor((20000-3000*i)*(firstX+150)/(this.game.width+200));
      var cloud = this.game.add.sprite(firstX,this.game.height-250+50*i,"cloud",this.game.rnd.integerInRange(0,2));
      cloud.scale.set(1+0.5*i);
      cloud.alpha = 0.3;
      this.game.add.tween(cloud).to({x:-150},firstTime,"Linear",true).onComplete.add(function(obj,tw,twTime){
        obj.x = this.game.width+50;
        this.game.add.tween(obj).to({x:-150},twTime,"Linear",true,0,-1).onLoop.add(function(obj){
          obj.frame = this.game.rnd.integerInRange(0,2);
        },this);
      },this,0,20000-3000*i);
    }

    group = this.game.add.group();
    this.plate1 = group.create(this.world.centerX-this.lastX, this.world.centerY+this.lastY, "plate", 0);
    this.plate1.anchor.set(0.5,0.4);
    // 连环tween
    this.game.add.tween(this.plate1).from({y:this.plate1.y-50,alpha:0},200,"Linear",true).onComplete.add(function(){
      this.plate2 = group.create(this.world.centerX+this.lastX, this.world.centerY-this.lastY, "plate", 0);
      this.plate2.anchor.set(0.5,0.4);
      this.plate2.sendToBack();
      this.game.add.tween(this.plate2).from({y:this.plate2.y-50,alpha:0},200,"Linear",true).onComplete.add(function(){
        // 光效
        effect = group.create(0, 0, "button", 6); 
        effect.anchor.set(0.5);
        effect.visible = false; // 与平台共一个组,只用visible控制显示或隐藏,用kill的话会被拿去做平台

        // 瞄准器
        point = group.create(0, 0, "button", 7); 
        point.anchor.set(0.5);
        point.scale.set(0.5);
        point.visible = false; // 与平台共一个组,只用visible控制显示或隐藏,用kill的话会被拿去做平台

        player = group.create(this.world.centerX-this.lastX, this.world.centerY+this.lastY);
        // 身体
        player.b = player.addChild(this.game.add.sprite(0, 0, "player", this.playerStyle));
        player.b.anchor.set(0.5,0.875);
        player.b.animations.add("delay",[this.playerStyle],10,false);
        // 加分提示文本
        player.txt = player.addChild(this.game.add.text(0, -30, "",
        {fontSize:"16px", fill:"#fff"}));
        player.txt.anchor.set(0.5);

        this.game.add.tween(player).from({y:player.y-50,alpha:0},200,"Linear",true)
        .onComplete.add(function(){
          moving = false;
        },this);
      },this);
    },this);

    this.items.txt[0] = this.game.add.text(this.world.centerX, 80, "0", 
    {fontSize:"48px", fill:"#999"});  
    this.items.txt[0].anchor.set(0.5);
    this.game.add.sprite(10,10,"icon",0);
    this.game.add.sprite(75,10,"icon",1);
    this.items.txt[1] = this.game.add.text(35, 10, this.items.val[1], 
    {fontSize:"16px", fill:"#999"});
    this.items.txt[2] = this.game.add.text(100, 10, this.items.val[2], 
    {fontSize:"16px", fill:"#999"});

    this.game.input.onDown.add(function(){
      if(!moving && !holding){
        holding=true;
        holdTime=this.game.time.now;
        if(this.items.val[2]>0){
          point.x=player.x;
          point.y=player.y;
          point.visible = true;
        }
      }
    },this);
    this.game.input.onUp.add(this._jump,this);
  };
  this.update = function(){
    if(holding){ // 储力效果,简单的缩短
      var power = Math.min(Math.floor((this.game.time.now - holdTime) / 16), 250);
      // 计算力度,限制数值最大为250
      player.scale.y = 1 - (power>100 ? 0.3 : 0.3 * power / 100);
      if(this.items.val[2]>0){
        var tarX = this.world.centerX-this.lastX+this.lastD*power*2;
        var tarY = this.world.centerY+this.lastY-power;
        point.x=tarX;
        point.y=tarY;
      }
    }
  };
  this._setItem = function(id, v){
    this.items.val[id]+=v;
    this.items.txt[id].text = this.items.val[id];
  };
  this._jump = function(){
    if(!moving && holding){
      moving = true;
      holding = false;
      player.scale.y = 1;
      point.visible = false;
      var power = Math.min(Math.floor((this.game.time.now - holdTime) / 16), 250);
      // 计算力度,限制数值最大为250
      var jumpX = this.world.centerX-this.lastX+this.lastD*power*2;
      var jumpY = this.world.centerY+this.lastY-power;
      // *** 跳跃效果 ***
      var jumpTime = 300; // 跳跃动作时长
      // 外壳直线位移至目的地
      this.game.add.tween(player).to({x:jumpX, y:jumpY},jumpTime,"Linear",true)
      .onComplete.add(function(obj){
        if(this._checkScore()){
          obj.b.animations.play("delay",10).onComplete.addOnce(this._newPlate,this);
          // 这里用帧动画实现停顿效果(帧速10代表停顿十分之一秒)
        }else{
          obj.b.animations.play("delay",10).onComplete.addOnce(this._fall,this);
        }
      },this);
      // 身体只做跳跃动作即可
      player.b.y = -40; 
      player.b.angle = -this.lastD * 150;
      this.game.add.tween(player.b).to({angle:-this.lastD*90, 
      x:this.lastD*20, y:-80}, jumpTime/2, Phaser.Easing.Quadratic.Out, false)
      .to({angle:0,x:0,y:0},jumpTime/2,Phaser.Easing.Quadratic.In,true);
      // ******
    }
  };

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

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

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

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

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

相关文章

第19章 并发与竞争实验(iTOP-RK3568开发板驱动开发指南 )

在前面章节的学习中&#xff0c;相信大家已经对用户空间与内核空间数据传递进行了实验&#xff0c;假如要传递的数据被存放在了全局变量&#xff0c;该数据就可以作为共享资源被多个任务共同读写&#xff0c;从而造成数据的错误传输&#xff0c;多个程序同时访问一个共享资源产…

取个好名,是一生中极为重要之事

我们每十年一大运&#xff0c;五年一小运。每交次大运时&#xff0c;就会改变一次你身边的一切环境。每个大运&#xff0c;都会把你带入不同的风景&#xff0c;人生想要须尽欢&#xff0c;就不要太在意外在的一切&#xff0c;永远向内求。有志同道合的人就一起上路&#xff0c;…

《Tree of Thoughts: Deliberate Problem Solving with Large Language Models》中文翻译

《Tree of Thoughts: Deliberate Problem Solving with Large Language Models》- 思维树&#xff1a;用大型语言模型有意识地解决问题 论文信息摘要1. 介绍2. 背景3. 思想树&#xff1a;用 LM 有意识地解决问题4. 实验4.1 24 人游戏4.2 创意写作4.3 迷你填字游戏 5. 相关工作6…

语音芯片NRK3302 在按摩仪上的应用

在当今生活节奏快&#xff0c;生活压力大的现代社会。按摩仪已逐渐成为人们生活中不可或缺的日常用品&#xff0c;人们需要一个能够随时放松身体的工具。智能按摩仪应运而生&#xff0c;在按摩仪中加入语音芯片&#xff0c;让按摩仪变得更加智能&#xff0c;使用起来更加便利化…

私有云不是真正的云计算!

大数据产业创新服务媒体 ——聚焦数据 改变商业 中国云计算遇到困境&#xff0c;IaaS层面&#xff0c;阿里云、腾讯云等增长乏力&#xff1b;SaaS没有发展起来。反观美国&#xff0c;整个云计算蓬勃发展&#xff0c;AWS、微软云、谷歌云体量更大&#xff0c;增速却不低&#x…

YOLO目标检测——工地安全帽识别检测数据集+已标注yolo格式标签下载分享

实际项目应用&#xff1a;目标检测工地安全帽识别检测数据集在工地安全监测、工地管理、安全培训和教育、违规检测和预警以及安全统计和分析等领域都有着广泛的应用。通过准确识别和检测工人是否佩戴安全帽&#xff0c;可以帮助提高工地的安全性和管理效率&#xff0c;减少事故…

通过finalshell快速在ubuntu上安装jdk1.8

这篇文章主要介绍一下怎么通过finalshell连接ubuntu&#xff0c;然后在ubuntu上安装jdk1.8&#xff0c;让不熟悉linux操作系统的童鞋也能快速地完成安装。 目录 一、准备一台虚拟机 二、安装finalshell远程连接工具 三、获取ubuntu虚拟机的ip地址 四、通过finalshell连接u…

Spring以及SpringBoot/SpringCloud注解

一、SpringBoot/Spring 1、SpringBootApplication 包含Configuration、EnableAutoConfiguration、ComponentScan通常在主类上 其中ComponentScan让Spring Boot扫描到Configuration类并把它加入到程序上下文&#xff0c;如果扫描到有Component Controller Service等这些注解的…

vscode配置conda环境

vscode配置conda环境 写在最前面安装vscodeanaconda3 配置vscode中文vscode配置anaconda环境步骤 新建.ipynb项目 写在最前面 之前一直是jupyter notebookpycharm 帮朋友配置环境的时候发现&#xff1a;vscode结合了cell自动补齐&#xff0c;狠狠心动了 于是安装配置vscode 参…

数据结构和算法(3):列表

列表是一种线性数据结构&#xff0c;它允许在其中存储多个元素&#xff0c;并且可以动态地添加或删除元素。 循秩访问 可通过重载下标操作符&#xff0c;实现寻秩访问 template <typename T> // assert: 0 < r < size T List<T>::operator[](Rank r) cons…

easyrecovery 2023年最好用的数据恢复软件

EasyRecovery是一款操作简单、功能强大数据恢复软件,通过easyrecovery可以从硬盘、光盘、U盘、数码相机、手机等各种设备中恢复被删除或丢失的文件、图片、音频、视频等数据文件。 easyrecovery数据恢复软件&#xff0c;是国内顶尖工作室的技术杰作。它是一个硬盘数据恢复工具&…

[NLP]LLM---大模型指令微调中的“Prompt”

一 指令微调数据集形式太多 大家有没有分析过 prompt对模型训练或者推理的影响&#xff1f;之前推理的时候&#xff0c;发现不加训练的时候prompt&#xff0c;直接输入模型性能会变差的&#xff0c;这个倒是可以理解。假如不加prompt直接训练&#xff0c;是不是测试的时候不加…

1. Flink简述

Flink与Spark Streaming对比 数据模型和处理模型 ​ Spark 的数据模型是 RDD&#xff0c;很多时候 RDD 可以实现为分布式共享内存或者完全虚拟化&#xff08;即有的中间结果 RDD 当下游处理完全在本地时可以直接优化省略掉&#xff09;。这样可以省掉很多不必要的 I/O。 ​ …

LinkWeChat 私域管理平台基于企业微信的开源 SCRM

LinkWeChat 是国内首个基于企业微信的开源 SCRM&#xff0c;在集成了企微强大的开放能力的基础上&#xff0c;进一步升级拓展灵活高效的客户运营能力及多元化精准营销能力&#xff0c;让客户与企业之间建立强链接&#xff0c;帮助企业提高客户运营效率&#xff0c;强化营销能力…

ERROR: Failed building wheel for mpi4py

在深度学习虚拟环境中使用pip方式安装mpi4py时&#xff0c;出现错误&#xff1a; 无法安装成功时&#xff0c;可以尝试使用conda的方式&#xff1a;conda install mpi4py。

4. 广播变量

一、分区规则&#xff08;DataStream Broadcast&#xff09;和广播变量&#xff08;Flink Broadcast&#xff09; 1.1 DataStream Broadcast&#xff08;分区规则&#xff09; ​ 分区规则是把元素广播给所有的分区&#xff0c;数据会被重复处理。 DataStream.broadcast()1.…

揭秘#AI Grant 第二期项目,我是如何用AI获取灵感的?

hi&#xff0c;大家好&#xff0c;最近看到一篇文章&#xff0c;介绍了 AI版YC的二期项目&#xff0c;里面的项目非常值得我们去研究&#xff0c;推荐给大家&#xff1a; aigrant.com AI版YC 指的是 AI Grant&#xff0c;这是一家&#xff1a; 提供资金和支持的加速器项目由Nat…

Redis高并发分布式锁实战

高并发场景秒杀抢购超卖bug实战重现 秒杀抢购场景下实战JVM级别锁与分布式锁 大厂分布式锁Resisson框架实战 Lua脚本语言快速入门与使用注意事项 Redisson分布式锁源码剖析 Redis主从架构锁失效问题解析 从CAP角度剖析Redis与Zookeeper分布式锁区别 Redlock分布式锁原理与…

PostGreSQL:时间戳时区问题

时间|日期类型 PostGreSQL数据库内置的时间类型如下&#xff0c;注意到&#xff1a;内置的时间类型被分为了with time zone-带时区、without time zone-不带时区两种类型&#xff0c; time、timestamp和interval都可以接受一个可选的精度值 p&#xff08;取值&#xff1a;0-6&a…

探索云计算和大数据分析的崛起:API行业的机遇与挑战【电商大数据与电商API接入】

I. 引言 随着云计算和大数据分析技术的快速发展&#xff0c;企业和个人对数据分析和处理的需求不断增加。在这个信息爆炸的时代&#xff0c;数据已成为企业决策和战略规划的重要基础。云计算提供了强大的计算和存储能力&#xff0c;使得大规模数据的处理和分析变得更加容易和高…