javascript - 每当蛇吃了加速器时,我如何暂时加速我的蛇?
问题描述
每当蛇吃了提升(蓝色)时,我想暂时加速我的蛇。
如有任何反馈和修改,不胜感激
if (ateFood) {
this.food.active = false;
this.game.score += 10;
this.$score.innerText = this.game.score;
this.soundEffects.score.play();
this.snake.pop();
} else if (ateBoost) {
this.boost.active = false;
this.soundEffects.score.play();
speed = 50;
//stuck at here
this.snake.pop();
} else {
this.snake.pop();
}
解决方案
在你加速蛇的speed = 50
工作后,你可以setTimeout(function(){ speed = oldSpeed; }, millisecondsOfBoost);
在下一行。因此,如果默认速度为 10 并且您想要提升 2 秒,那么它将是setTimeout(function(){ speed = 10; }, 2000);
推荐阅读
- python - 当有很多这样的元素时,如何找到列表中出现次数最多的元素?
- python - 如何将href文本标签添加到dict?
- php - 如何将爆炸数组(Group_Concat Result)推送到另一个数组
- socket.io - 如何使用 Socket-io.client 在 Angular 中获取套接字 ID
- html - 想要滚动时如何防止页面加载
- android - MotionEvent - 如何在点击时执行操作,而不是拖动
- python - 获取所有可能的字符串分区,其中每个分区都是回文
- ios - 如何通过firebase-functions将数据传递给Paypal?
- angular - 发布新版本的 angular2 应用程序时会看到旧网站
- vue.js - 即使值存在,localStorage.getItem() 也始终返回 null