如何在Perlenspiel/Javascript中制作炸弹函数

How to make a bomb function in Perlenspiel/Javascript?

本文关键字:炸弹 函数 Javascript Perlenspiel      更新时间:2023-09-26

Javascript/Perlenspiel

你好,我正在尝试制作一个功能/代码,让玩家拿起物品"BOMB",然后按"b"在地图上的任何地方激活它。炸弹将摧毁玩家半径为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);
        }   
    }

要开始,您需要更多的对象,其中包括:

  • 地图

你的游戏循环将包括(伪代码(:

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
              }
          }
     }
}