我在這里遇到的問題不一定是代碼,更多的是敵人的生成方式,你看我已經構建了一個腳本,它會自動為敵人選擇一個新的“X”位置,當你消除了上一個級別時,這個事件會詛咒敵人的。對我來說,解釋我是如何為敵人制作命中框的是相當困難的。我的主要問題是敵人的產卵對角線彼此相鄰。
附上一張敵人如何生成的影像,并為您提供代碼。注意:敵人確實在不同的位置產卵,但似乎總是彼此對角線
敵人生成輸出
setInterval(function resetWaveSurviver(){
if (waveSurviver == true){
if (enemy1.style.left == '-100px'){
if (enemy2.style.left == '-100px'){
if (enemy3.style.left == '-100px'){
if (enemy4.style.left == '-100px'){
hits = 0;
E1X1 = Math.floor(Math.random() * 529) 1;
E2X1 = Math.floor(Math.random() * 521) 1;
E3X1 = Math.floor(Math.random() * 540) 1;
E4X1 = Math.floor(Math.random() * 530) 1;
E1X2 = E1X1 50
E1Y1 = E1X1
E1Y2 = E1Y1 50
E2X2 = E2X1 50
E2Y1 = E2X1
E2Y2 = E2Y1 50
E3X2 = E3X1 50
E3Y1 = E3X1
E3Y2 = E3Y1 50
E4X2 = E4X1 50
E4Y1 = E4X1
E4Y2 = E4Y1 50
enemy1.style.left = '' E1X1 'px'
enemy2.style.left = '' E2X1 'px'
enemy3.style.left = '' E3X1 'px'
enemy4.style.left = '' E4X1 'px'
enemy1.style.top = '' E1Y1 'px'
enemy2.style.top = '' E2Y1 'px'
enemy3.style.top = '' E3Y1 'px'
enemy4.style.top = '' E4Y1 'px'
cycle = false;
hits = 0;
}
}
}
}
}
})
uj5u.com熱心網友回復:
它們是對角線的,因為您分配的 Y 坐標與 X: 相同E1Y1 = E1X1。
如果你想要隨機位置,你需要:
E1Y1 = Math.floor(Math.random() * maxHeight) 1;
E1Y2 = E1Y1 50;
E2Y1 = Math.floor(Math.random() * maxHeight) 1;
E2Y2 = E2Y1 50;
E3Y1 = Math.floor(Math.random() * maxHeight) 1;
E3Y2 = E3Y1 50;
E4Y1 = Math.floor(Math.random() * maxHeight) 1;
E4Y2 = E4Y1 50;
對于 X,所有值都保持不變。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409530.html
標籤:
上一篇:如何從PHP驗證動態單選按鈕
