Logic Help - CCLabelBMFont - Action Move - Detecting if labels collide

I’ve been thinking about this for awhile and can’t wrap my head around the logic to accomplish the following.

My game has random words that fall tetris style, created in a CCARRAY with CCLabelBMFont. I would like these labels to continue dropping at random spots, however if one label is going to intersect with another label I would like them to stack on top of each other.

As they drop: FallingWord1
>
>
FallingWord2
>
>
Result: FallingWord1
FallingWord2

Any help on the logic would be much appreciated. I am fairly new to cocos2d and haven’t done C++ for a very long time. Very thankful for Cocos2d, loving it so far.

My big issue right now is, I spawn each of these labels the same way enemies are spawned in the SimpleGame example. The movement starts each time addSprite is called, where would I be able to implement the code to check each labels ending coordinates before the move ends?

Thanks in advance

Ryan

I think I found what I need to do. I could use a little help on actions though.

Currently whenever I add a falling word I make a CCRect that I pass into an array. I can then loop through that array to see if any of the rectangles intersect with the newly spawned word and adjust the new words Y coords so that it will sit on top of the existing word.

My issue is, each time I spawn a word I use CCFiniteTimeAction with CCMoveTo, during the move I may need to adjust the end position. What is the proper way to adjust an existing move, do I have to find its tag and stop it and then do a new move with the new location or is there a better way?

Here are the parts of my code that are relevant to this question.

My current issue is I am not detecting any collisions until there are already a bunch of words that have collided. The goal is to have words start at the top of the screen and end just above the onscreen keyboard. If the user accurately types the falling word before it reaches the bottom it is removed from the array and the screen and I will give the user a score. If the words are not typed they will pile up like tetris blocks.

Am I going about this the right way? Should I be looking into a different type of collision detection besides making rectangles out of the word locations?

Thanks in advance.

GameLogic calls addWord() every 3 seconds

    this->schedule( schedule_selector(HelloWorld::GameLogic), 3.0);
    this->schedule( schedule_selector(HelloWorld::updateGame) );

This is the majority of my addWord() function, each word is a CCLabelBMFont object. Each word is added to the *words CCArray
<pre>
word~~>setPosition);
this~~>addChild;
CCFiniteTimeAction* actionMove = CCMoveTo::create~~>getVisibleOrigin.x + actualX),finalY));
CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create);
CCSequence* moveSequence = );
word~~>runAction;
actionMove~~>setTag;
word~~>setTag;
_words~~>addObject;
</pre>
When a label reaches the bottom of screen, remove the word from the
word array and add a rectangle to *wordRect for collision detectoin in update function
<pre>
void HelloWorld::labelMoveFinished
{
CCLabelBMFont **word = sender;
//Make a Rectangle for the current words position
CCRect wordRect = CCRectMake.x - .width/2),
word~~>getPosition.y~~ .height/2),
word~~>getContentSize.width,
word~~>getContentSize.height);
//Cast the above rectangle into a CCValue for array storage
CCValue**wordRectValue = CCValue::valueWithValue;
//Add the rectangle to an array of words that finished their move
wordRects~~>addObject;
//Remove the word from the
words array since the user can no longer interact with this word
_words~~>removeObject;
}</pre>
updateGame gets the word closest to landing and makes it into a rectangle and checks it against the rectangles in _wordRect for collisions
<pre>
void HelloWorld::updateGame
//Cast first word in array back to CCLabelBMFont
CCLabelBMFont *currentWord = dynamic_cast<CCLabelBMFont>);
//make a rectangle out of the first word in array which should be closest to landing
CCRect currentWordRect = CCRectMake.x - .width/2),
currentWord~~>getPosition.y~~ .height/2),
currentWord~~>getContentSize.width,
currentWord~~>getContentSize.height);
CCARRAY_FOREACH_REVERSE
{
CCValue**wordRectValue = dynamic_cast<CCValue*>;
CCRect finishedWordRect = wordRectValue~~>getValue();

if(finishedWordRect.intersectsRect(currentWordRect) && collisionDetected == false)
{
CCLog(“Collision Detected”);
//currentWord->stopActionByTag(1);
//stop current action and create a new action to place current word on top of existing word
collisionDetected = true;
}
} }