随着微信小游戏(跳一跳)的出现一下子火了起来,听说试玩用户已经超过了1.7亿大关,这是要搞事情啊!我有预感,随着微信小游戏的推出,后面能够带来了一批h5小游戏的狂潮,应该还是有潜力的。
不说废话了,直接正如主题,前几天研究了一下跳一跳发现还是挺有趣儿的,麻雀虽小五脏俱全,涉及一些算法,比如棋子跳跃的力度控制,跳跃的弧度数,还有跳跃时候有个二次方曲线,还用到了粒子,还有图形学相关的知识(ps Creator没有3d概念,只能用斜切的xy来搞咯),与制造回收 对象池 。
日常博客上车图镇楼。

come on 坐稳了发车。
今天主要从四个角度来进行剖析跳一跳,分别是 手指按下时,手指释放时,block的产生与回收对象池,检测与结束游戏逻辑处理。
按下状态:首先这块我们来拆分两块来讲,
1.player:首先我们根据按下时的状态,能够看出 这里的player做了一个蓄力的动作,是通过改变scaleY进行的,这里面用了run’Action来进行补间操作,公式为:scale * dt / scle < Maxdt 可以理解为 按下时scaleY小于1,并且大于底数,(不能让低于底数否则会出现player怪异变形)
2.jump player:这次我们来说弹跳,我们先要考虑的是跳跃值得计算公式,this.speed += dt * this.this.power 既底数 += dt按下时长 * 蓄力值,我们得到了底数后,带入
this.jumpDistance += this.speed * dt ; 跳跃距离 += 底数 * 按下时长,
松开状态:这里也拆分两块讲。
1.很明显他在松开时候player在空中进行了一个360翻转的动作,这里代码为
cc.rotateBy(0.5,this.direction*360);
2.翻转后明显看到我们的player的scale变回来了scale为1。
block处理:
let n = Math.floor(Math.random() * this.blockList.length);
let blockNode=cc.instantiate(this.blockList[n]);
this.blockLayer.addChild(blockNode);
let block=blockNode.getComponent(Block);
let scale=block.minScale+Math.random() * (block.maxScale-block.minScale);
let distance=block.minDistance+Math.random() * (block.maxDistance-block.minDistance);
blockNode.scale=scale;
if (this.player.direction>0) {
blockNode.x=this.currBlock.node.x+distance;
blockNode.y=this.currBlock.node.y+distance*this.arrayRatio;
} else {
blockNode.x=this.currBlock.node.x-distance;
blockNode.y=this.currBlock.node.y+distance*this.arrayRatio;
}
this.currBlock=this.nextBlock;
this.nextBlock=block;
returnblock;
随机从数组对象池里面取出一个下标,通过下标索引对应图片的url地址,在进行addChild 添加到舞台上(距离为 最小距离 + 随机数 * (最大 – 最小))从而保证图片不会超出屏幕scale为相同算法,再次进行匹配节点的位置,最后返回方块。
再然后就是进行判断,先将世界坐标转到局部坐标位置,通过u来进行判断是在ringt or left 并将记录存储,进行便利操作,
检测:player的位置是否在 nearWrap.left < player.loacl < nearWrap.right &&nearWrap.bottom < player.loacl < nearWrap.top,如果是那么你成功了,直接返回getPosition,这里转移坐标用
convertToNodeSpaceAR函数
,如果不是那么直接调遮罩层与得分面板弹出,gameOver,打完收工。
游戏githunb地址 : https://github.com/894658027/HTML5-Games/tree/master/cocosCreator/jump-jump/jump
Biswas Shivhare S, et al priligy in usa What Do Beets Have That Lower Blood Pressure
63 V V O L16 2 Ој O 2 1 priligy tablet
Conjunctival injection examination can i order cytotec no prescription The presence of one or more of these features with a central facial distribution is suggestive of rosacea
cytotec generic and brand name While the liver does an amazing job of detoxifying natural estrogen, it cannot possibly be expected to detoxify the daily onslaught of harmful synthetic estrogen like chemicals sent its way
Peptidyl prolyl cis trans isomerase NIMA interacting 1 PIN1 interacts with serum and glucocorticoid inducible protein kinase 1 SGK1 buy augmentin without rx