这是我github的链接。 https://github.com/inventive-dev217/arcade-game。我需要allEnemies数组中的项目以随机速度移动。现在,它们都以相同的速度运动。任何想法如何实现这一点将不胜感激。
答案 0 :(得分:0)
嗨,我不是JS方面的专家,但是类似的方法应该可以工作:
var Enemy = function(x, y) {
// Variables applied to each of our instances go here,
// we've provided one for you to get started
// The image/sprite for our enemies, this uses
// a helper we've provided to easily load images
this.sprite = 'images/enemy-bug.png';
this.x = x;
this.y = y;
this.speed = Math.floor(Math.random() * MaxSpeedValue) + MinSpeedValue;
}