• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Add delay before changing sprite after collision

P

PRellevart

Guest
Hi guys, I'm running into some of the problem here that I don't know how to fix

I'm trying to add a delay before changing sprite to a different one when two players collide each other. It is a game of tag, therefore I like one person to be "it" and the other to be running away
I ran into some problem about collision as the player collide horizontally, they will go through each other instead of bouncing off in vertical. When the player bounce off, the "it" change to the other person perfectly, but when they go through each other, the "it" keeps on changing between players indefinitely until they are not overlap.

Therefore, I'm trying to add a delay function (or an alarm event) to let the player who got tag and become "it" wait for 3 seconds before they can tag the other again and change "it". However, I don't know the coding aspect of it

This is my code so far

In step event:

#region //movement and collision with platform


key_left = keyboard_check((vk_left));
key_right = keyboard_check((vk_right));
key_jump = keyboard_check((vk_up));

var move = key_right - key_left;
horispd = move*walkspd;
vertspd = vertspd + grav;
#endregion


#region // collision with platform

if (place_meeting(x,y+1,Obj_floor)) && (key_jump)
{
vertspd = jumppower;
}

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

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

#endregion

#region //it not it

if (it = true)
{
image_index = 0;
walkspd =6;
}
else
{
image_index = 1;
walkspd = 4;
}

#endregion



in collision event between 2 player:

if (it = true)
{
image_index = 0;
it = false;
}
else
{
image_index = 1;
it = true;
}
//horizontal
if place_meeting(x+horispd,y,Obj_player1)
{
horispd = -horispd+grav;

}

//vertical
if place_meeting(x,y+vertspd,Obj_player1)
{
vertspd = -vertspd;
}


Many thanks guys
 

obscene

Member
First, use the [ code ] tag on the forum so it's readable.

Then just add a timer.

Code:
if timer timer-=1;
else { 
   your collision code
   timer=180;
}
 
P

PRellevart

Guest
Thanks! this solve my problem, and sorry first time using the forum hear
 
Top