Legacy GM (SOLVED) Sprites, objects and Collisions!

J

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.​
 

DaMuffin

Member
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;
}
 
J

josh jones

Guest
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;
}

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
 

DaMuffin

Member
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?
 
J

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;

----------------------------------------------------------------------------------------
 

DaMuffin

Member
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.
 
Top