GM:S 1.4 (SOLVED) Sprites, objects and Collisions!

Discussion in 'Programming' started by josh jones, Sep 28, 2017.

  1. josh jones

    josh jones Guest

    colour-twist.png

    Hi I am creating a game called colour twist.

    The game concepts consist of going through different portals to change colour to pass through the end portal, which takes you to the next level. Simples. I managed that easily.

    However I wanted to add more difficulty and tried to add a boundary, for example if the player sprite is red then it can pass through the RED gate, but if its blue or green or yellow then it cannot. Is there anyone who can help.

    I essentially need ...
    I put this code in the RED boundary colliion code with the player
    ...
    if(sPlayerBlue || sPlayerRed) [then I dont know what to put next] ?? what could I put to make the RED bondary solid for other colours.​
     
  2. DaMuffin

    DaMuffin Member

    Joined:
    Jun 22, 2016
    Posts:
    30
    Sounds interesting.
    You want something like this?
    Code:
    if player_color=="red"
    {
      //pass through
    }
    else
    {
      //don't pass through
      player.x -= x_push_back;
      player.y -= y_push_back;
    }
     
  3. josh jones

    josh jones Guest


    I have just put this code into my game with neccesary changes and it seems to be an error with the push back... personally never dealt with push back coding, what could be the issue.. thanks for helping
     
  4. DaMuffin

    DaMuffin Member

    Joined:
    Jun 22, 2016
    Posts:
    30
    You can change "x_push_back" & "y_push_back" to any number except zero. It depends on how you handle movement and collisions. What does the error say? Would you mind showing any related code?
     
  5. josh jones

    josh jones Guest

    Player step event ////

    ----------------------------------------------------------------------------------
    //Get the player's input
    key_right = keyboard_check(vk_right);
    key_left = -keyboard_check(vk_left);
    key_jump = keyboard_check_pressed(vk_space);

    //React to inputs
    move = key_left + key_right;
    hsp = move * movespeed;
    if (vsp < 10) vsp += grav;

    if (place_meeting(x,y+1,oBlock))
    {
    vsp = key_jump * -jumpspeed
    }

    //Horizontal Collision
    if (place_meeting(x+hsp,y,oBlock))
    {
    while(!place_meeting(x+sign(hsp),y,oBlock))
    {
    x += sign(hsp);
    }
    hsp = 0;
    }
    x += hsp;

    //Vertical Collision
    if (place_meeting(x,y+vsp,oBlock))
    {
    while(!place_meeting(x,y+sign(vsp),oBlock))
    {
    y += sign(vsp);
    }
    vsp = 0;
    }
    y += vsp;

    ----------------------------------------------------------------------------------------
     
  6. DaMuffin

    DaMuffin Member

    Joined:
    Jun 22, 2016
    Posts:
    30
    In your collision event, if the player cannot pass, set the hsp and/or vsp to a number for pushback. Perhaps disable player input to prevent the player from holding left when they're supposed to be pushed right.
     
  7. josh jones

    josh jones Guest

    S O L V E D{}{}{}

    thankyouu
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice