I'm implementing a card minigame in my game and I want the cards to "pop" up and move to the front when the mouse moves over them. When the player moves the cursor at a "reasonable" speed, things go well:

However, if the cursor moves too fast, some cards will get "stuck" in their top position and won't go back down:

Also, if I leave the cursor at just the right spot, the card will start jumping up and down, since it will constantly move in and out of the cursor's hotspot:

This last case doesn't worry me too much since it's kind of an edge case, but the cards getting stuck is a real problem that makes the whole thing look kind of bad. Is there any way I could avoid that?
My code:
Code: ags

However, if the cursor moves too fast, some cards will get "stuck" in their top position and won't go back down:

Also, if I leave the cursor at just the right spot, the card will start jumping up and down, since it will constantly move in and out of the cursor's hotspot:

This last case doesn't worry me too much since it's kind of an edge case, but the cards getting stuck is a real problem that makes the whole thing look kind of bad. Is there any way I could avoid that?
My code:
Object* previouscard;
void descendCard(Object* card)
{
int ycoord;
switch(card)
{
case oObject1:
case oObject4:
ycoord = 220;
break;
case oObject2:
case oObject3:
ycoord = 205;
break;
case oObject0:
ycoord = 190;
break;
}
card.TweenY(0.25, ycoord, eEaseOutBackTween, eNoBlockTween);
}
void ascendCard (Object* card)
{
int ycoord;
switch(card)
{
case oObject1:
case oObject4:
ycoord = 210;
break;
case oObject2:
case oObject3:
ycoord = 195;
break;
case oObject0:
ycoord = 180;
break;
}
card.TweenY(0.25, ycoord, eEaseOutBackTween, eNoBlockTween);
}
function room_Load()
{
oObject1.Baseline = 189;
oObject2.Baseline = 190;
oObject0.Baseline = 191;
oObject3.Baseline = 190;
oObject4.Baseline = 189;
// there's a series of dynamic sprite rotations here which I'm omitting because they're not relevant
}
function room_RepExec()
{
Object* o = Object.GetAtScreenXY(mouse.x, mouse.y);
if (o == null) { // to empty space
if (previouscard != null) {
previouscard.Baseline = previouscard.Baseline - 3;
descendCard(previouscard);
previouscard = null;
}
}
else if (o != null && previouscard != null && o != previouscard) { // from one card to another
o.Baseline = o.Baseline + 3;
ascendCard(o);
previouscard.Baseline = previouscard.Baseline - 3;
descendCard(previouscard);
previouscard = o;
}
else if (o != previouscard) { // from empty space to card
o.Baseline = o.Baseline + 3;
ascendCard(o);
previouscard = o;
}
}