【发布时间】:2019-12-06 17:29:54
【问题描述】:
所以,对于最后一个项目,我尝试用三种不同的流星制作游戏;青铜、白银和黄金。虽然 Bronze 阵列在 Setup() 中运行良好,但 Silver 和 Gold 流星出于某种未知原因高速运行。
function setup() {
createCanvas(windowWidth, windowHeight);
spaceship = new Spaceship(100, 100, 5, spaceshipImage, bulletImage, 40);
healthStar = new Star(1000, 100, 10, healthStarImage, 50);
//the Meteor Array
// Run a for loop numMeteor times to generate each meteor and put it in the array
// with random values for each star
for (let i = 0; i < numMeteor; i++) {
let meteorX = random(0, width);
let meteorY = random(0, height);
let meteorSpeed = random(2, 20);
let meteorRadius = random(10, 60);
meteor.push(new Meteor(meteorX, meteorY, meteorSpeed, meteorBronzeImage, meteorRadius));
}
}
// draw()
//
// Handles input, movement, eating, and displaying for the system's objects
function draw() {
// Set the background to a safari scene
background(skyBackground);
// Check if the game is in play
if (playing == true) {
// Handle input for the tiger
spaceship.handleInput();
// Move all the "animals"
spaceship.move();
healthStar.move();
if (spaceship.dodges >= 5){
levelTwo = true;
}
//lvl 2
if (levelTwo == true){
meteor = [];
for (let i = 0; i < numMeteor; i++) {
let meteorX = random(0, width);
let meteorY = random(0, height);
let meteorSpeed = random(2, 20);
let meteorRadius = random(10, 60);
meteor.push(new Meteor(meteorX, meteorY, meteorSpeed, meteorSilverImage, meteorRadius));
}
}
if (spaceship.dodges >= 8){
levelThree = true;
}
//lvl 3
if (levelThree == true){
levelTwo = false;
meteor = [];
for (let i = 0; i < numMeteor; i++) {
let meteorX = random(0, width);
let meteorY = random(0, height);
let meteorSpeed = random(2, 20);
let meteorRadius = random(10, 60);
meteor.push(new Meteor(meteorX, meteorY, meteorSpeed, meteorGoldImage, meteorRadius));
}
}
// Handle the tiger and lion eating any of the star
spaceship.handleEating(healthStar);
//
spaceship.handleBullets();
// Handle the tragic death of the tiger
spaceship.handleDeath();
// Check to see when the game is over
checkGameOver();
// Display all the "animals"
spaceship.display();
healthStar.display();
// Display and making sure the tiger can eat the copies of the star
for (let i = 0; i < meteor.length; i++) {
meteor[i].move();
meteor[i].display();
//meteor[i].handleDamage();
spaceship.handleHurting(meteor[i]);
spaceship.handleDodging(meteor[i]);
}
}
// Once the game is over, display a Game Over Message
if (gameOver == true) {
displayGameOver();
}
// Otherwise we display the message to start the game
else {
displayStartMessage();
}
}
我试图改变速度,把关卡设置为错误,除了青铜流星什么都没有。
【问题讨论】:
-
您在问题中提到了 Setup() 函数,但代码中不存在该函数。大概您提供的代码是该函数的主体?明确说明会很有帮助 - 我们看不到您的项目中未提供的部分。按照这些思路,不包括负责流星运动的任何代码(您的描述表明问题可能存在的地方)。题外话建议:除了图像之外,您用于填充流星数组的代码在每种情况下都是相同的。将其提取到以图像为参数的函数中。不要重复自己(干)
-
我只是编辑它以包含所有内容,我认为放太多会太混乱。我很抱歉。
-
无需道歉。理想情况下,您需要尽可能多地为从未看过您的项目的人提供足够的背景信息。
-
@Andy 谢谢!我忘记了正确的术语/链接
标签: javascript arrays github atom-editor