Attempting card mechanics - Issue with depth & detection

S

Stephen Cena

Guest
I've been tinkering with GMP & really enjoying it. Right now, I'm trying to make card mechanics (decks, tableau, etc). My issue is with a tableau. I have an obj_Stall which has both the sprite for the tableau as well as the ds_list of the cards in the tableau. My current collision detection is done only against the obj_Stall.

When a Left Pressed is received on obj_Card:
================================
/// Pick up the card
global.active_card = self;
global.active_card.image_index = 1;
global.previous_depth = object_get_depth(self);
global.previous_x = x;
global.previous_y = y;
object_set_depth(self, active_card_depth);
================================

A Left Released event on obj_Card is:
================================
/// Drop the card

if (global.active_card != noone)
{
var dest_deck = noone;

dest_deck = instance_position(mouse_x, mouse_y, obj_Stall);

if (dest_deck != noone)
{
with (dest_deck)
{
var index = ds_list_size(deck);
global.active_card.x = x;
global.active_card.y = y + (index * deck_offset);
object_set_depth(global.active_card, index);
ds_list_add(dest_deck.deck,global.active_card);
}
} else {
global.active_card.x = global.previous_x;
global.active_card.y = global.previous_y;
object_set_depth(global.active_card, global.previous_depth);
global.active_card.image_index = 0;
}

global.active_card = noone;
}
================================
I have a obj_Controller that holds the ID for the card selected. I currently have 4 cards on screen in random locations (obj_Card->obj_D1 .. obj_Card->D4). If I click and drag the card onto the stall, it drop & displays correctly. Lets say the cards I have are (in order): 2D, 4D, AD, 3D. If I click on the visible part of the 4D I will get the 2D. My drop depth is also inconsistent. Sometimes they lay down right, other times the draw depth gets mixed up. Originally, my code for setting the depth used a negative index:

object_set_depth(global.active_card, -index);

I tried a solution where I attempted to modify the collision mask to only what was visible on screen. Couldn't get it to work when the card flipped (image_index 0 = back, image_index 1 = front).

Any help would be appreciated. Thanks!
 

Attachments

S

Stephen Cena

Guest
Ok, I've made some progress but I have a new issue now:

If I use sprite_duplicate and then use sprite_collision_mask to change the collision area to just the visible part of the card, I now pick up the correct card. However now when I release the left button, it doesn't register the "Left Released" event.

Left pressed event code:
// Card is moving
active = true;

// Set the card face up
image_index = 1;

// Back up the cards previous location and depth
previous_x = x;
previous_y = y;
previous_depth = depth;

// Set net draw depth
depth = draw_depth_active_card;
-----------------------------------------------------------------------------------
Code after we've colided with a stall:

if (ds_list_find_index(dest.stall, self) = -1)
{
// Adjust the card properties
x = dest.x;
y = dest.y + (ds_list_size(dest.stall) * stall_card_offset);
depth = dest.next_depth;
home = dest;
// Add the card to the list
ds_list_add(dest.stall, self);
// Adjust the next card depth
dest.next_depth = dest.next_depth - 1;
// Fix the colission box for the previous card
size = ds_list_size(dest.stall);
if (size > 0)
{
// Get the last card
var prev_card = ds_list_find_value(dest.stall, size-1);
prev_card.covered_sprite = sprite_duplicate(prev_card.sprite_index);
sprite_collision_mask(prev_card.covered_sprite, true, 2, 0, 0, sprite_get_width(prev_card.covered_sprite), stall_card_offset, 1, 0 );
// Assign the new sprite
prev_card.sprite_index = prev_card.covered_sprite;
}
}
-----------------------------------------------

I can post additional code or screenshots, but this one is weird to me. I don't see how the operations I'm performing cause the card the "Left Released" to not fire.
 
S

Stephen Cena

Guest
Found one bug... the ds_list_add is happening too soon so i'm improperly setting the collision mask if there is just one card.

more to come.....

#debugging
 
S

Stephen Cena

Guest
I *think* I know what it is..... trying to test it:

When I lay one card over the other, I change the collision area to the exposed card. Great.
I then click on the exposed card and I pick it up. Kinda great. Why? Because my code makes the center of the card "jump" to the mouse pointer which is now OUTSIDE of the collision box, so when I release the card with Left Released it's not firing. Pure speculation on my part right now but I think that's what my issue is.......
 
S

Stephen Cena

Guest
DING DING DING DING. That was it. By changing the collision area & making the card "jump" to my mouse cursor position it made the card stay in my "hand" indefinitely. Calculating the relative position of the card versus the position of the mouse pointer fixed the issue. I can now pick the cards up properly and drop them!!!
 
Top