• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

i am confused on how to make walls

S

supermasher/ti

Guest
i did tried watching a few videos but i got confused or they were not working properly so i am wondering how to add walls Slide1.PNG so all i have right now is movement

here is my code so far

OBJ_player

Creat//:
Code:
idle = 1;
walking = 0;

up = 3;
right = 2;
down = 1;
left = 0;

Action = idle;
Direction = down;

View[1,3] = v_p_upIdle;
View[1,2] = v_p_rightIdle;
View[1,1] = v_p_downIdle;
View[1,0] = v_p_leftIdle;

View[0,3] = v_p_upWalking;
View[0,2] = v_p_rightWalking;
View[0,1] = v_p_downWalking;
View[0,0] = v_p_leftWalking;
Step//:
Code:
/// @description
 
if (keyboard_check(vk_up) || keyboard_check(vk_right) || keyboard_check(vk_down) || keyboard_check(vk_left)) {
    Action = walking;
    if (keyboard_check(vk_up)) {Direction = up;}
    if (keyboard_check(vk_right)) {Direction = right;}
    if (keyboard_check(vk_down)) {Direction = down;}
    if (keyboard_check(vk_left)) {Direction = left;}
} else {Action = idle}

sprite_index = View[Action, Direction];


speed = 0;  //this doesn't work if you have acceleration, but you don't have acceleration probably
if (keyboard_check(vk_up) || keyboard_check(vk_right) || keyboard_check(vk_down) || keyboard_check(vk_left)) {
   Action = walking;
   if (keyboard_check(vk_up)) {Direction = up; vspeed = -2;}
   if (keyboard_check(vk_right)) {Direction = right; hspeed = 2;}
   if (keyboard_check(vk_down)) {Direction = down; vspeed = 2;}
   if (keyboard_check(vk_left)) {Direction = left; hspeed = -2;}
} else {Action = idle;}

//walls
and i did try something like this to add walls but it did not work and it started glitching

Step//:
Code:
//walls

if(place_meeting(x+hspeed,y,OBJ_Colishion))
{
    while(place_meeting(x+sign(hspeed),y,OBJ_Colishion))
    {
        x= x+sign(hspeed);
    }
    hspeed = 0;
}
 
if(!place_meeting(x+hspeed,y,OBJ_Colishion))
{
while(!place_meeting(x+sign(hspeed),y,OBJ_Colishion))
{
x= x+sign(hspeed);
}
hspeed = 0;
}

I think that should fix it... If I am understanding the only issue at least
 
S

supermasher/ti

Guest
the video gamester

for some reason when i use you code the play game window won't show up but if I remove you code it comes up fine
 
the video gamester

for some reason when i use you code the play game window won't show up but if I remove you code it comes up fine
Check the compiler window for any errors. If it says "non-zero status" or something like that, you've got an error... scroll through the compiler until you find what's wrong.

As for walls, are you wanting the player to collide with walls? Then you just make a collision event with the obj_wall.
 

Slyddar

Member
for some reason when i use you code the play game window won't show up but if I remove you code it comes up fine
That's because it's a endless loop.

if(!place_meeting(x+hspeed,y,OBJ_Colishion))
{
while(!place_meeting(x+sign(hspeed),y,OBJ_Colishion))
{
x= x+sign(hspeed);
}
hspeed = 0;
}

I think that should fix it... If I am understanding the only issue at least
You are saying if there is not a collision, then run this collision code that loops while there is not a collision.

I've given the correct code above.
 
Last edited:
That's because it's a endless loop.
I don't think its an infinite loop. I use similar code for my movement
Code:
if(checkGrid(x+hspd,y)){
    while(!checkGrid(x+sign(hspd),y)){
        x+= sign(hspd);
    }
    hspd = 0;
    if(destroy){
        instance_destroy();
    }
}
my check grid function acts exactly as the gamemaker check position does. It never causes me any issues. The while loop is so that you get pixel perfect collisions. Edit: My bad. I accidently added an extra !.
 
Last edited:
the video gamester

for some reason when i use you code the play game window won't show up but if I remove you code it comes up fine
Any error messages in the output window?

I did actually throw in an extra ! symbol. corrected code

Code:
if(place_meeting(x+hspeed,y,OBJ_Colishion))
{
while(!place_meeting(x+sign(hspeed),y,OBJ_Colishion))
{
x= x+sign(hspeed);
}
hspeed = 0;
}
 
Yeah, solid, along with a few other in-built GM variables should really be avoided. They remove control in ways that can introduce impossible to fix bugs (impossible to fix because GM itself is handling the bit that needs fixing).
 
Top