threejs-jump

用 threejs 模仿微信跳一跳程序

效果

原理

跳一跳分为两类物体,一类是跳动的小跳棋对象,一类是跳棋降落的物体。

这里的物体形状主要是立方体和圆柱体,规则的几何体利于计算跳棋的落点,
通过随机数可以生成这两类物体。

物体之间的位置关系可以分为两类,在xz平面上,下一个物体可能在上一个物体的
-z轴正方向,也可能在 +x 轴方向。

跳棋不同的落点对应不同的动画和处理方式,所以判断落点要分类讨论,落点可能的情况
如下图所示:

通过比较落点跟几个特殊点之间的距离来判断降落类型。

// 随机产生一个图形
createCube: function (){var relativePos = Math.random() > 0.5 ? 'zDir' : 'xDir';// var relativePos = 'xDir';var cubeType = Math.random() > 0.5 ? 'cube' : 'cylinder';var geometry = cubeType === 'cube' ?new THREE.CubeGeometry(this.config.cubeX, this.config.cubeY, this.config.cubeZ):new THREE.CylinderGeometry(this.config.cylinderRadius, this.config.cylinderRadius, this.config.cylinderHeight, 100);var color = cubeType === 'cube' ? this.config.cubeColor : this.config.cylinderColor;var material = new THREE.MeshLambertMaterial( { color: color } );var mesh = new THREE.Mesh(geometry, material);
http://www.biyezuopin.vip// 产生随机图形if (this.cubes.length){var dis = this.getRandomValue(this.config.cubeMinDis, this.config.cubeMaxDis);var lastcube = this.cubes[this.cubes.length - 1];if (relativePos === 'zDir'){if (cubeType === 'cube'){if (lastcube.geometry instanceof THREE.CubeGeometry)// 方体 -> 方体mesh.position.set(lastcube.position.x, lastcube.position.y, lastcube.position.z - dis - this.config.cubeZ );else  // 方体 -> 圆柱体mesh.position.set(lastcube.position.x, lastcube.position.y, lastcube.position.z - dis - this.config.cylinderRadius - this.config.cubeZ / 2);} else {if (lastcube.geometry instanceof THREE.CubeGeometry)// 圆柱体 -> 方体mesh.position.set(lastcube.position.x, lastcube.position.y, lastcube.position.z - dis - this.config.cylinderRadius - this.config.cubeZ / 2);else// 圆柱体 -> 圆柱体mesh.position.set(lastcube.position.x, lastcube.position.y, lastcube.position.z -  dis - this.config.cylinderRadius * 2 );}} else {if (cubeType === 'cube'){if (lastcube.geometry instanceof THREE.CubeGeometry)// 方体 -> 方体mesh.position.set(lastcube.position.x + dis + this.config.cubeX, lastcube.position.y, lastcube.position.z);else  // 方体 -> 圆柱体mesh.position.set(lastcube.position.x + dis + this.config.cubeX / 2 + this.config.cylinderRadius, lastcube.position.y, lastcube.position.z);} else {if (lastcube.geometry instanceof THREE.CubeGeometry)// 圆柱体 -> 方体mesh.position.set(lastcube.position.x + dis + this.config.cylinderRadius + this.config.cubeX / 2 , lastcube.position.y, lastcube.position.z);else// 圆柱体 -> 圆柱体mesh.position.set(lastcube.position.x + dis + this.config.cylinderRadius * 2, lastcube.position.y, lastcube.position.z);}}} else {mesh.position.set(0, 0, 0);}
http://www.biyezuopin.vipthis.testPosition(mesh.position);this.cubes.push(mesh);this.scene.add(mesh);this._render();// 如果缓存图形数大于最大缓存数,去掉一个if (this.cubes.length > this.config.cubeMaxLen){this.scene.remove(this.cubes.shift());}if (this.cubes.length > 1){// 更新相机位置this._updateCameraPos();} else {this.camera.lookAt(this.cameraPos.current);}
}
/*
* 根据落点判断是否成功或失败,共分为以下几种情况
* 返回值 1: 成功,但落点仍然在当前块上
* 返回值 2: 成功,落点在下一个块上
* 返回值 3: 成功,落点在中心点 (先不考虑,后续优化)
* 返回值 -1:失败,落点在当前块边缘 或 在下一个块外边缘
* 返回值 -2:失败,落点在当前块与下一块之间 或 在下一个块之外
* 返回值 -3:失败,落点在下一个块内边缘*/
getJumpState: function (){var jumpR = this.config.jumpBottomRadius;var vard = this.getd();var d = vard.d;var d1 = vard.d1;var d2 = vard.d2;var d3 = vard.d3;var d4 = vard.d4;if (d <= d1) {return 1;}  else if (d > d1 && Math.abs(d - d1) <= jumpR) {return -1;} else if (Math.abs(d - d1) > jumpR && d < d2 && Math.abs(d - d2) >= jumpR){return -2;} else if ( d < d2 && Math.abs(d - d2) < jumpR){return -3;} else if ( d > d2 && d <= d4){return 2;} else if ( d > d4 && Math.abs(d - d4) < jumpR){return -1;} else {return -2;}
},getd: function (){var d, d1, d2, d3, d4;var fromObj = this.cubes[this.cubes.length - 2];var fromPosition = fromObj.position;var fromType = fromObj.geometry instanceof THREE.CubeGeometry ? 'cube' : 'cylinder';var toObj = this.cubes[this.cubes.length - 1];var toPosition = toObj.position;var toType = toObj.geometry instanceof THREE.CubeGeometry ? 'cube' : 'cylinder';var jumpObj = this.jumper;var position = jumpObj.position;if (fromType === 'cube'){if (toType === 'cube'){if ( fromPosition.x === toPosition.x ){// -z 方向d = Math.abs(position.z);d1 = Math.abs(fromPosition.z - this.config.cubeZ / 2);d2 = Math.abs(toPosition.z + this.config.cubeZ / 2);d3 = Math.abs(toPosition.z);d4 = Math.abs(toPosition.z - this.config.cubeZ / 2);} else {// x 方向d = Math.abs(position.x);d1 = Math.abs(fromPosition.x + this.config.cubeX / 2);d2 = Math.abs(toPosition.x - this.config.cubeX / 2);d3 = Math.abs(toPosition.x);d4 = Math.abs(toPosition.x + this.config.cubeX / 2);}} else {if ( fromPosition.x === toPosition.x ){// -z 方向d = Math.abs(position.z);d1 = Math.abs(fromPosition.z - this.config.cubeZ / 2);d2 = Math.abs(toPosition.z + this.config.cylinderRadius);d3 = Math.abs(toPosition.z);d4 = Math.abs(toPosition.z - this.config.cylinderRadius);} else {// x 方向d = Math.abs(position.x);d1 = Math.abs(fromPosition.x + this.config.cubeX / 2);d2 = Math.abs(toPosition.x - this.config.cylinderRadius);d3 = Math.abs(toPosition.x);d4 = Math.abs(toPosition.x + this.config.cylinderRadius);}}} else {if (toType === 'cube'){if ( fromPosition.x === toPosition.x ){// -z 方向d = Math.abs(position.z);d1 = Math.abs(fromPosition.z - this.config.cylinderRadius);d2 = Math.abs(toPosition.z + this.config.cubeZ / 2);d3 = Math.abs(toPosition.z);d4 = Math.abs(toPosition.z - this.config.cubeZ / 2);} else {// x 方向d = Math.abs(position.x);d1 = Math.abs(fromPosition.x + this.config.cylinderRadius);d2 = Math.abs(toPosition.x - this.config.cubeX / 2);d3 = Math.abs(toPosition.x);d4 = Math.abs(toPosition.x + this.config.cubeX / 2);}} else {if ( fromPosition.x === toPosition.x ){// -z 方向d = Math.abs(position.z);d1 = Math.abs(fromPosition.z - this.config.cylinderRadius);d2 = Math.abs(toPosition.z + this.config.cylinderRadius);d3 = Math.abs(toPosition.z);d4 = Math.abs(toPosition.z - this.config.cylinderRadius);} else {// x 方向d = Math.abs(position.x);d1 = Math.abs(fromPosition.x + this.config.cylinderRadius);d2 = Math.abs(toPosition.x - this.config.cylinderRadius);d3 = Math.abs(toPosition.x);d4 = Math.abs(toPosition.x + this.config.cylinderRadius);}}}return {d: d, d1: d1, d2: d2, d3: d3, d4: d4};
}

threejs写的模仿微信跳一跳游戏相关推荐

  1. python 遍历usb设备_python程序员教你写脚本玩微信跳一跳,只要有耐心,你就是王者!...

    温馨提示:微信已经开始检测分数异常高的情况了,请大家不要跑太高哦 游戏模式 这是一个 2.5D 插画风格的益智游戏,玩家可以通过按压屏幕时间的长短来控制这个「小人」跳跃的距离.可能刚开始上手的时候,因 ...

  2. python 游戏辅助脚本_python版微信跳一跳游戏辅助

    本文实例为大家分享了微信跳一跳游戏辅助python代码,供大家参考,具体内容如下 import os import PIL import numpy import matplotlib matplot ...

  3. python跳一跳脚本详解_微信跳一跳游戏 python脚本辅助得高分

    微信小程序一时间火爆朋友圈,关键是还有排行榜!游戏操作简单,可直接根据电脑识别,用python写出自动跳辅助脚本,本想动手写下,索性网上有大神写了现成脚本,修改了一小部分参数,就可以稳定使用了霸榜没有 ...

  4. python做的游戏怎么导到微信_微信跳一跳游戏的脚本-scratch导出到微信-微信小程序是怎么做的...

    1. 微信更新后出来了一块比较火的小游戏,要是一款不涉及到排行的游戏,可能没人去关注这款游戏.最开自己一直苦练技术,想在微信排行上面装一装,练了好久才跑三百多分.接着在Github(Github地址: ...

  5. 微信跳一跳游戏的脚本

    原文:http://blog.csdn.net/shi4862758/article/details/78951269 微信更新后出来了一块比较火的小游戏,要是一款不涉及到排行的游戏,可能 没人去关注 ...

  6. 跳一跳python源码下载_微信跳一跳游戏python脚本

    微信更新后出来了一块比较火的小游戏,要是一款不涉及到排行的游戏,可能 没人去关注这款游戏.最开自己一直苦练技术,想在微信排行上面装一装,练了好久才跑三百多分.接着在Github(Github地址),有 ...

  7. 微信跳一跳游戏外挂(mac电脑+android手机)

    外挂源码地址:https://github.com/wangshub/wechat_jump_game 1.先下载github的脚本代码 进入下载后的文件夹,安装依赖文件 pip install -r ...

  8. python写安卓游戏辅助软件_python微信跳一跳辅助软件

    python微信跳一跳辅助软件是一款跳一跳小游戏的刷分辅助工具应用,用户在微信玩跳一跳游戏的时候使用软件可以随意的修改其中的成绩分数,按照你自己的意愿进行相关的改变,更好的帮助你达成游戏的最高峰,喜欢 ...

  9. python微信跳一跳小游戏刷分

    iOS #python 微信跳一跳小游戏刷分 首先我们安装Facebook的WebDriverAgent,这是一款新的iOS移动测试框架 在GitHub上找到https://github.com/fa ...

  10. 微信跳一跳(游戏辅助小外挂C语言版)

    相信微信跳一跳这个游戏大家应该都或多或少听过或者玩过,想必好多朋友看到自己好友们得高分自己却分数老是玩不高! 之前在这个游戏刚出来时候有人用Python写出了一个小外挂,随后网上各种各样的外挂包括物理 ...

最新文章

  1. 能说明你的Javascript技术很烂的五个原因
  2. if...else 小练习
  3. python爬虫实战案例-Python爬虫实战案例:手机APP抓包爬虫
  4. 从syslinux源码定制LiveUSB
  5. a commit git 参数是什么意思_git commit 命令
  6. JAVA中的适配器应用_Java适配器模式应用之电源适配器功能详解
  7. 获取泛型T的ClassT clazz
  8. 如何让Java应用在Aone上打包速度提高100%以上
  9. 有没有安卓4.0的java模拟器_电脑端安装Android4.0模拟器使用教程
  10. 高并发来袭,如何搭建微服务架构?
  11. 计算机病毒是以独立的文件形式存在的对吗,计算机病毒以什么形式存在?
  12. 获取当前屏幕高度方法总结
  13. GitLab之docker注册Runner
  14. Windows下如何对声卡音频输出进行录音
  15. sencha app watch php,使用新的SenchaCmd4命令appwatch
  16. 网线传输速度测试_网络传输速率及测速方法
  17. 记一次悲催的软件异常崩溃调试解决历程,错误0xc0000417,无效参数,_set_invalid_parameter_handler
  18. C++ fabs和abs区别
  19. 【CodeForces】【DP】14E Camels
  20. discuz db_mysql.calss.php_刚发现得好东西!discuz 7.0 db_mysql.php 详解

热门文章

  1. iOS13beta2版描述文件,修复了,修复了,修复了,可以用描述文件更新了
  2. OpenDaylight VTN 项目指南
  3. 马云、奥巴马都上当:“女版乔布斯”600亿惊天骗局,电影都不敢这么拍
  4. apache common-chain 简单使用
  5. Latex之复杂距离、自定义章节样式、自定义目录样式
  6. win7系统桌面上计算机不见了怎么办,win7桌面上我的电脑图标不见了怎么办
  7. mysql数据库 存储过程_Mysql数据库-存储过程
  8. css中如何使图标的旋转
  9. FIFO调度算法和LRU算法
  10. 企业微信 网页授权登入demo