Jmarlin3

Member
The objective is to have the player enter the cupboard with the open sprite. I right click to open, and right click to close.

Code for player:
Code:
//Stealth Variables
if(vspeed != 0 or hspeed != 0)
{
    noise_level = max_speed*25;   
}
else
{
    noise_level = 0;   
}
scr_player_keyboard_controls();
//Check collision

scr_check_collision();

//Check if the player is hidden

scr_player_check_hidden();

//scr_check_collision

//Moving down
if(vspeed > 0)
{
    
    if(place_meeting(x, y+vspeed, obj_cupboard_closed))
    {
        while(!place_meeting(x, y+1, obj_cupboard_closed)) {y++};
        vspeed = 0;
    }
    
}

//Moving up
if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_closed))
    {
        while(!place_meeting(x, y-1, obj_cupboard_closed)) {y--};   
        vspeed = 0;
    }
}

//Moving right
if(hspeed > 0)
{
    
    if(place_meeting(x+hspeed,y, obj_cupboard_closed))
    {
        while(!place_meeting(x+1, y, obj_cupboard_closed)) {x++};
        hspeed = 0;
    }
}

//Moving left
if(hspeed < 0)
{

    if(place_meeting(x+hspeed,y, obj_cupboard_closed))
    {
        while(!place_meeting(x+1, y, obj_cupboard_closed)) {x--};
        hspeed = 0;
    }
}

//scr_check_collision

//Moving down
if(vspeed > 0)
{
    
    if(place_meeting(x, y+vspeed, obj_cupboard_open))
    {
        while(!place_meeting(x, y+1, obj_cupboard_open)) {y++};
        vspeed = 0;
    }
    
}

//Moving up
if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_open))
    {
        while(!place_meeting(x, y-1, obj_cupboard_open)) {y--};   
        vspeed = 0;
    }
}

//Moving right
if(hspeed > 0)
{
    
    if(place_meeting(x+hspeed,y, obj_cupboard_open))
    {
        while(!place_meeting(x+1, y, obj_cupboard_open)) {x++};
        hspeed = 0;
    }
}

//Moving left
if(hspeed < 0)
{

    if(place_meeting(x+hspeed,y, obj_cupboard_open))
    {
        while(!place_meeting(x+1, y, obj_cupboard_open)) {x--};
        hspeed = 0;
    }
}
scr_check_collision (but this is for the walls in the room:

//scr_check_collision
//Moving down
if(vspeed > 0)
{

if(place_meeting(x, y+vspeed, obj_wall))
{
while(!place_meeting(x, y+1, obj_wall)) {y++};
vspeed = 0;
}
}
//Moving up
if(vspeed < 0)
{
if(place_meeting(x, y+vspeed, obj_wall))
{
while(!place_meeting(x, y-1, obj_wall)) {y--};
vspeed = 0;
}
}
//Moving right
if(hspeed > 0)
{

if(place_meeting(x+hspeed,y, obj_wall))
{
while(!place_meeting(x+1, y, obj_wall)) {x++};
hspeed = 0;
}
}
//Moving left
if(hspeed < 0)
{
if(place_meeting(x+hspeed,y, obj_wall))
{
while(!place_meeting(x+1, y, obj_wall)) {x--};
hspeed = 0;
}
}

obj_cupboard_closed:
Draw Event:
//Draw yourself
draw_self();
//Draw top of cupboard
draw_sprite_ext(spr_cupboard_top,0,x,y,1.0,1.0,image_angle, c_white, 1.0);

Right Pressed Event:
/// Open if clicked
if(point_distance(x,y,obj_player.x,obj_player.y) <= obj_player.reach)
{
open = instance_create_depth(x,y,2,obj_cupboard_open);
open.image_angle = image_angle;
instance_destroy();


}

Step Event:
scr_check_collision();

Now for obj_cupboard_open

Draw Event:
//Draw yourself
draw_self();
//Draw top of cupboard
draw_sprite_ext(spr_cupboard_top,0,x,y,1.0,1.0,image_angle, c_white, 1.0);

Right Pressed Event:
/// Open if clicked
if(point_distance(x,y,obj_player.x,obj_player.y) <= obj_player.reach)
{
closed = instance_create_depth(x,y,2,obj_cupboard_closed);
closed.image_angle = image_angle;
instance_destroy();


}

Step Event:
scr_check_collision();


The problem is that when I open the cupboard (switching sprites), the player won't enter the open version of the cupboard. I assume becuase it still thinks of itself as the closed version. How can I remedy this?!
 
K

Kris Hyre

Guest
Code:
if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_open))
    {
        while(!place_meeting(x, y-1, obj_cupboard_open)) {y--};   
        vspeed = 0;
    }
}

if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_closed))
    {
        while(!place_meeting(x, y-1, obj_cupboard_closed)) {y--};   
        vspeed = 0;
    }
}
Looking at your movement code, it looks like the exact same behavior for both place_meeting with obj_cupboard_open and obj_cupboard_closed: it moves up to colliding and then stops, setting speed to 0.
 

Jmarlin3

Member
Code:
if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_open))
    {
        while(!place_meeting(x, y-1, obj_cupboard_open)) {y--};  
        vspeed = 0;
    }
}

if(vspeed < 0)
{
    if(place_meeting(x, y+vspeed, obj_cupboard_closed))
    {
        while(!place_meeting(x, y-1, obj_cupboard_closed)) {y--};  
        vspeed = 0;
    }
}
Looking at your movement code, it looks like the exact same behavior for both place_meeting with obj_cupboard_open and obj_cupboard_closed: it moves up to colliding and then stops, setting speed to 0.
Thanks for your help, but I realized that I just needed to change the collision mask.
 
Top