1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 cant push box

Discussion in 'Programming' started by phillipPbor, Feb 11, 2017.

  1. phillipPbor

    phillipPbor Member

    Joined:
    Jun 21, 2016
    Posts:
    223
    hey, trying to fix a box pushing mechanic in a puzzle platform

    upload_2017-2-11_17-41-35.png

    upload_2017-2-11_17-42-25.png

    upload_2017-2-11_17-43-1.png

    as I run a game it just idle, you know trying to make layer do push animation when collide with box left or right.

    so my question was, how do you make a pushable box perfect?
     
    Last edited: Feb 12, 2017
  2. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    968
    So...what exactly is your issue? Also, code as plaintext please.
     
  3. phillipPbor

    phillipPbor Member

    Joined:
    Jun 21, 2016
    Posts:
    223
    okay, my issue is that I have the push code but this turns out wrong, just look at vid.



    ja, this box sticks to player when I climb ladder, and pass through me.
    I want a box to be like simple. here is my code. ill use spoilers for now on.

    you ready? forgive me for this. I just cant resister any websites.

    check collision script

    Code:
    ///checkCollision(x, y)
    
    var xpos = argument[0];
    var ypos = argument[1];
    
    if (place_meeting(xpos, ypos, obj_platform)) // Check for collisions against normal blocks
      {
      return true;
      }
    else
    
     
      {
      // Check for collisions against jump-through platforms
      var platform = instance_place(xpos, ypos, obj_jumpthrough_platform);
      if (platform == noone)
        return false;
      if (image_blend == c_red) // If it's in red mode, allow moving up through it, but not falling down
        return ((vsp > 0 and bbox_bottom <= platform.bbox_top) or (vsp == 0 and bbox_bottom < platform.bbox_bottom));
      else
        return (vsp <= 0 and bbox_bottom > platform.bbox_bottom); // When in cyan mode, allow falling through, but not jumping up or walking through it
       }
     // return false;
     
     return false;
        
        
    
    //by benjamin ...............................................................................
    
    
    // { // Check for collisions against jump-through platforms
    //  var platform = instance_place(xpos, ypos, obj_jumpthrough_platform_2);
    //  if (platform == noone)
    //    return false;
    //  if (image_blend == c_aqua) // If it's in red mode, allow moving up through it, but not falling down
    //    return ((vsp < 0 and bbox_bottom >= platform.bbox_top) or (vsp == 0 and bbox_bottom > platform.bbox_bottom));
    //  else
    //    return (vsp >= 0 and bbox_bottom < platform.bbox_bottom); // When in cyan mode, allow falling through, but not jumping up or walking through it
    //    }
    
    

    player movement (the would script)

    Code:
    ///player script
    
    // player output.................................................
    
    if !stop
    KyR = keyboard_check_direct(vk_right);
    KyL = -keyboard_check_direct(vk_left);
    KyJ = keyboard_check_pressed(vk_up);
    KyU = keyboard_check_direct(vk_up);
    KyD = keyboard_check_direct(vk_down);
    // react inputs..................................................
    
    if !stop
    move = KyL + KyR;
    
    
    if !stop
    hsp = move * msp;
    
    
    if !stop
    if (vsp < 10) vsp += grav;
    
    
    if !stop
    if (checkCollision(x,y+1))
     {
       vsp = KyJ * -jsp
     }
    
    
    //push animation................................................
    
    if !stop
    if (checkCollision(x+hsp,y,obj_box))
     {
       sprite_index = any_push;
    }
    
    // push............................................................ooo__________________________________________-
    if !stop + !ladder
    with (instance_place(x+image_xscale, y, obj_box))
    {
      // x += other.hsp;   or  image_xscale = move;
       x +=other.hsp;
    }
    
    // horizontal...................................................
    
    if !stop
    if (checkCollision(x+hsp,y))
    {
     while(!checkCollision(x+sign(hsp),y))
      {
        x += sign(hsp);
      }
      hsp = 0;
    }
    x += hsp;
    
    // vertical...................................................
    
    if !stop
    if (checkCollision(x,y+vsp))
    {
    while(!checkCollision(x,y+sign(vsp)))
      {
        y += sign(vsp);
      }
      vsp = 0;
    }
    y += vsp;
    
    //.....................................................................
    
    
    // animate......................................................     
     
    if !(ladder)
    {
    if !stop
    if (move!=0) image_xscale = move;
    image_speed = 0.5;
        if (checkCollision(x,y+1))
         {
            if (move!=0) sprite_index = any_run; else sprite_index = any_stand;
         }
        else
         {
            if (vsp < 0) sprite_index = any_jump; else sprite_index = any_fall;
         }
    }
    
    //push animation...................................................................................
    
    // bounce spring................................................
    
    var inst = instance_place(x, y, obj_spring);
    if (inst != noone)
    {
    if (inst.y > y+16)
      {
     vsp = -jps;
      }
    }
    
    
    //exit...........................................................
    if stop = true
    {
    sprite_index = any_stand
    vsp = 0
    hsp = 0
    }
    
    //death..........................................................
    if !deathless
    if (place_meeting(x,y,obj_death_par))
    {
    deathless = true;
    alarm[0] = 80;
    lives-=3;
    audio_play_sound(sou_hurt,1,0);
    }
    
    
    //deathless........................................................
    if deathless = true
    {
      image_alpha = 0.5;
    }
    else
    {
      image_alpha = 1;
    }
    
    //hit by or bounce on enemy.................................................................
    if !deathless
    if instance_place(x,y,obj_enemy_par)
    {
        if (obj_enemy_par.y > y+16)
        {
            obj_enemy_par.HP-=1;
            vsp = -jsp;
            audio_play_sound(sou_enemyhit,1,0);
        }
        else
        {
          hsp = -image_xscale*1;
          vsp = -3;
          deathless = true
          alarm[0] = 80;
          lives-=1;
          audio_play_sound(sou_hurt,1,0);
        }
    }
    
    //hit by invincenemy.................................................................
    if !deathless
    if instance_place(x,y,obj_bullet_par)
    {
          hsp = -image_xscale*1;
          vsp = -3;
          deathless = true
          alarm[0] = 80;
          lives-=1;
          audio_play_sound(sou_hurt,1,0);
    }
    
    // convayor.......................................................
    if !stop
    if (place_meeting(x,y+1,obj_convayor_platform))
    {
    if (other.image_blend == c_red)
    {x-=1.5}
    else
    {x+=1.5}
    }
    
    
    
    //Ladder.....................................................................................
    if (KyU || KyD)
    {
        if place_meeting(x,y,par_ladder) ladder = true;
    }
    
    if (ladder)
    {
        vsp = 0;
        grav = 0;
        if (KyU) vsp = -2 ;
        if (KyD) vsp = 2 ;
        
        if !place_meeting(x,y,par_ladder)
        ladder = false; 
      
    }
    if !(ladder)
    grav = 0.3;
    
    //ladder animation............................................................
    if (ladder)
    {
        sprite_index = any_climb;
        image_speed = 0;
        if (KyU) image_speed = 0.2;
        if (KyD) image_speed = 0.2;
    }
    //stuck death............................................................
    
    
    if place_meeting(x,y, obj_platform_red)
     {
      deathless = true;
      alarm[0] = 80;
      lives-=3;
      audio_play_sound(sou_hurt,1,0);
     }
    
    if place_meeting(x,y, obj_platform_cyan)
     {
      deathless = true;
      alarm[0] = 80;
      lives-=3;
      audio_play_sound(sou_hurt,1,0);
     }
    
    
    //.........................................................................................
    
    
     
    Last edited: Feb 12, 2017

Share This Page