Beispiel #1
0
Drawable* AllMovable::checkBottom()
{
    
    if (this->objectType() == MARIO && this->getYVelocity() > 0) {
        return NULL;
    }
    
    // get instance of level
	Level* level = Level::sharedLevel();
    
	// initialize iterators
	LListIterator liBlocks, liMovable, liDrawable;
	liBlocks.init(level->getActiveBlocks());
	liMovable.init(level->getActiveMovable());
	liDrawable.init(level->getActiveDrawable());
    
    Drawable *item;
    int thisBottom, thisLeft, thisRight, objTop, objBottom, objLeft, objRight;
    
	// get right value of object
	thisBottom = this->bottom();
    thisLeft = this->left();
    thisRight = this->right();
    
    // iterate through active Blocks list
	while ((item = liBlocks.next())) 
	{
		//get left, right, top and bottom of block
		objTop = item->top();
		objBottom = item->bottom();
        objLeft = item->left();
        objRight = item->right();
        
		// if the top is in between objects top & bottom boundaries
		if (thisBottom >= objBottom && thisBottom <= objTop)
		{
			if ((thisLeft >= objLeft && thisLeft < objRight) || (thisRight > objLeft && thisRight <= objRight)) {
                if (item->objectType() != BACKGROUND) {
                    return item;
                }
            }
		}
	}
    
    // iterate through active Movable list
	while ((item = liMovable.next())) 
	{
		//get left, right, top and bottom of block
		objTop = item->top();
		objBottom = item->bottom();
        objRight = item->right();
        objLeft = item->left();
        
		// if the top is in between objects top & bottom boundaries
		if (thisBottom >= objBottom && thisBottom <= objTop && item != this)
		{
			if ((thisLeft >= objLeft && thisLeft < objRight) || (thisRight > objLeft && thisRight <= objRight)) {
                if (item->objectType() != BACKGROUND) {
                    return item;
                }
            }
		}
	}
    
	// iterate through active Drawable list
	while ((item = liDrawable.next())) 
	{
		//get left, right, top and bottom of block
		objTop = item->top();
		objBottom = item->bottom();
        objRight = item->right();
        objLeft = item->left();
        
		// if the top is in between objects top & bottom boundaries
		if (thisBottom >= objBottom && thisBottom <= objTop)
		{
			if ((thisLeft >= objLeft && thisLeft < objRight) || (thisRight > objLeft && thisRight <= objRight)) {
                if (item->objectType() != BACKGROUND) {
                    return item;
                }
            }
		}
	}
    
	return NULL;
}