Ejemplo n.º 1
0
    private void CheckTileClicked(MouseClickEvent mcei)
    {
        //Devide the mouse click loction with the tile size to get the correct click position on your map, assuming the tilemap is set to 0,0 position
        Vector2 mapPos = mcei.clickPos / 32;
        //Grab the players position to determin if the player is close enough to break the tile
        Vector2 playerPos = GetNode <KinematicBody2D>("../Player").GlobalPosition;
        //Fire the tile destroy event to add ammo to the player
        TileDestroyEvent tdei = new TileDestroyEvent();

        if (tileMap.GetCellv(mapPos) == (int)TileType.WALL_BREAKABLE && mcei.clickPos.DistanceTo(playerPos) < 150)
        {
            //Replace the tile instabce with the floor
            tileMap.SetCellv(mapPos, (int)TileType.FLOOR);
            //Set the tile destroyed event to true
            tdei.tileDestroyed = true;
            //Update the map once a tile has been changed
            tileMap.UpdateBitmaskRegion(mapPos - Vector2.One, mapPos + Vector2.One);
        }
        tdei.FireEvent();
    }
Ejemplo n.º 2
0
    private void AddAmmo(TileDestroyEvent tdei)
    {
        //Check if the tile destroyed bool is true
        if (tdei.tileDestroyed)
        {
            //Add ammo if a tile was destroyed
            ammo++;
        }
        else
        {
            if (ammo > 0)
            {
                //Create a ne bullet
                bullet = bulletScene.Instance();
                //Set the direction of the bullet when instanced
                AddChild(bullet);
                ammo--;
            }
        }
        SendAmmoEvent saei = new SendAmmoEvent();

        saei.ammo = ammo;
        saei.FireEvent();
    }
Ejemplo n.º 3
0
 public override void _ExitTree()
 {
     TileDestroyEvent.UnregisterListener(AddAmmo);
 }
Ejemplo n.º 4
0
    public override void _Ready()
    {
        TileDestroyEvent.RegisterListener(AddAmmo);

        bulletScene = ResourceLoader.Load("res://Scenes/Bullet.tscn") as PackedScene;
    }