Javascript/Perlenspiel
您好,我正在尝试制作一个函数/代码,让玩家拾取项目“BOMB”,然后通过按“b”在 map 上的任何位置激活它。炸弹将摧毁玩家 2 颗珠子半径内的所有墙壁。
我如何开始这样做?我不熟悉这样的物体或按键。
这是我迄今为止唯一拥有的东西:
//Player
var PLAYER = {
x : 1, // The x and y of where the player is now
y : 1,
StartX : 1,
StartY : 1,
glyph : "➽",
color : 0x0000FF,
data : "player",
//dead : false,
}
var BOMB = {
x : 3,
y : 3,
glyph : "♾",
color : 0x000000,
data : "bomb",
}
\var dataAtPlayer = PS.data(PLAYER.x, PLAYER.y);
if(dataAtPlayer ="bomb"){
PS.debugClear();
PS.debug("You picked up a bomb! Press the b key to use it!\n");
if(key == 98){
eraseBead(PLAYER.x + 1, 0);
}
}
最佳答案
首先,您需要更多对象,其中包括:
- 墙
- map
您的游戏循环将包括(伪代码):
while(!player.isDead)
{
...
if(keyPress==KeyToPickupBOMB)
{
if(PlayerIsOnBomb(Player,Map))
{
PlayerPicksUpBomb(Player,Map)
}
}
...
if(keyPress=="B")
{
if(PlayerHasBomb(Player))
{
explodeBomb(Player,Map)
}
}
...
}
炸墙的函数是
function explodeBomb(Player,Map)
{
//Check for Borders
for(int x = Player.X-2; x<=Player.X+2;x++)
{
for(int y = Player.y-2; y<=Player.y+2;y++)
{
if(Map[x][y] is a Wall)
{
Map[x][y] is now empty space
}
}
}
}
关于javascript - 如何在 Perlenspiel/Javascript 中制作炸弹功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32752035/