GMS 2 Healthbar behind walls on screen

D

Dasaki

Guest
So I'm building an engine very close to what VTS Studios has and it's coming along pretty solidly, however my draw_healthbar function for the player returns with some walls obstructing the health bar.

So to begin, this is the few pages of code for the level generator that VTS had on his channel, with some minor alterations and fixes of a few create instance bugs.


Code:
/// Create room initialization
// Size room
randomize();
N = 50;
BLOCK_SIZE = sprite_get_height(spr_wall);

room_set_width(rm_Main, N * BLOCK_SIZE)
room_set_height(rm_Main, N * BLOCK_SIZE)

// Determine Placement of walls
var probWall = 0.15;
var probEnemy = 0.005;
layout[N - 1, N - 1] = 0;
for (var i = 0; i < N; i++)
    for (var j = 0; j < N; j++)
    {
        layout[i, j] = noone;
       
        if (random(1.0) <= probWall)
        {
            layout[i, j] = obj_wall;
            continue;
        }
       
        if (random(1.0) <= probEnemy)
        {
            layout[i, j] = obj_monster001
            continue;
        }
    }
   
// Proper room destination
room_goto(rm_Main);
which leads to the next code since room sizing and the like can't be done on the same room.

Code:
if (room == rm_Main)
{
   var playerX = irandom(N - 1);
   var playerY = irandom(N - 1);
  
   for (var i = 0; i < N; i++)
       for (var j = 0; j < N; j++)
       {
           if (i == playerX and (j == playerY or j == playerY +1)) {
               if (j == playerY + 1)
               continue;
               instance_create_depth(i * BLOCK_SIZE, j * BLOCK_SIZE,
                   depth, obj_player);
               continue;
           }
          
           if (layout[i, j] == noone)
               continue;
              
           if (collision_point(i * BLOCK_SIZE, j * BLOCK_SIZE, all,
                   false, true)) {
                   }
           instance_create_depth(i * BLOCK_SIZE, j * BLOCK_SIZE,
               depth, layout[i, j]);
       }

// Creating room border  
   for (var i = -1; i < N +1; i++)
   {
       instance_create_depth(i * BLOCK_SIZE, -BLOCK_SIZE, depth, obj_wall);
       instance_create_depth(i * BLOCK_SIZE, (N + 1) * BLOCK_SIZE, depth, obj_wall);
       instance_create_depth(-BLOCK_SIZE, i * BLOCK_SIZE, depth, obj_wall);
       instance_create_depth((N + 1) * BLOCK_SIZE, i * BLOCK_SIZE, depth, obj_wall);
   }

}
These two codes together not only provide the spawning of walls and enemies, but also provide the probability and randomization that comes with it.

My Show_health bar codes for both the player, and the enemy is as follows.

Player Health Bar
Code:
/// @desc health

draw_self();

var amount = currenthp / maxhp * 100;
draw_healthbar(16, 16, 64, 32, amount, c_dkgray, c_red, c_green, 0,
   true, true);
Monster Health Bar
Code:
/// @desc health

draw_self();

var amount = currenthp / maxhp * 100;
draw_healthbar(x, y - 6, x + sprite_width * 1.1, y - 2, amount,
   c_dkgray, c_red, c_green, 0, true, true);
The Monster draw health works as intended. The Player healthbar however hides behind the wall that spawns in front.
Below are some images showing the problem and showing what the bar is supposed to look like


bug_2.png bug.png bug_2.png

Any help is appreciated!
 

Attachments

Top