Esempio n. 1
0
void Collision::initAnimations(){
    CCString* animationName = CCString::create("anim");
    CCString* className = CCString::create("CollisionObject");
    this->setAnim(loadPlistForAnimationWithName(animationName, className));
    getAnim()->retain();
    getAnim()->setRestoreOriginalFrame(false);
    
}
Esempio n. 2
0
/**
 * Determine whether or not the event is overlapping the given area
 *
 * @param left The x-coordinate of the left of the area
 * @param top The y-coordinate of the top of the area
 * @param width The width of the area
 * @param height The height of the area
 *
 * @return Whether or not there is an overlap
 */
bool Event::overlap (fixed left, fixed top, fixed width, fixed height) {

	fixed offset = 0;
	if (getAnim() && noAnimOffset)
		offset = getAnim()->getOffset();

	return (x + getWidth() >= left) &&
		(x < left + width) &&
		(y + offset >= top) &&
		(y + offset - getHeight() < top + height);

}
Esempio n. 3
0
/**
 * Get the height of the event
 *
 * @return The height of the event
 */
fixed Event::getHeight () {

	if (animType == E_NOANIM) return F32;

	if ((set->anims[animType] & 0x7F) == 0) return 0;

	return ITOF(getAnim()->getHeight());

}
Esempio n. 4
0
/**
 * Initiate the destruction of the event
 *
 * @param ticks Time
 */
void Event::destroy (unsigned int ticks) {

	animType = E_LFINISHANIM | (animType & 1);

	level->setEventTime(gridX, gridY, ticks + (getAnim()->getLength() * set->animSpeed << 3));

	level->playSound(set->sound);

	return;

}
Esempio n. 5
0
void Sprite::animate(int anim, float& frame, float spd)
	{
	Anim& a=getAnim(anim);
	if(spd<0.0f)
		frame+=a.getAspd()*WindowEngine::getDelta();
	else
		frame+=spd*WindowEngine::getDelta();
	if((int)frame>=a.getFrameCount())
		{
		float diff=frame-(int)(frame);
		frame=a.getFret()+diff;
		}
	}
Esempio n. 6
0
void Gate::Animate(Graphics* graphics, Audio* audio) {

    if (getAnim() == NULL) { //TODO shouldn't happen
        return;
    }

    if (getAnim()->getCurrentFrame() == 0 && state == sOpening) {
        getAnim()->Stop();
        state = sOpened;
    }

    if (getAnim()->getCurrentFrame() == getAnim()->getLastFrameNr() && state == sClosing) {
        getAnim()->Stop();
        state = sClosed;
        audio->PlaySound(Audio::gate_close);
    }

    if (state == sOpened) {
        if (timer->GetTimeMilli() > delay) {
            state = sClosing;

            this->getAnim()->setForward();
            this->getAnim()->setDisplayTime(slowTime);
            this->getAnim()->Play();
        }
    }

    if (state == sClosing && getAnim()->isEffectPending()) {
        audio->PlaySound(Audio::gate_down);
        getAnim()->setEffectDone();
    }

    if (state == sOpening && getAnim()->isEffectPending()) {
        audio->PlaySound(Audio::gate_up);
        getAnim()->setEffectDone();
    }

    Entity::Animate(graphics);
}
Esempio n. 7
0
void Collision::changeState(CharacterStates newState){
    this->setcharacterState(newState);
    CCAction *action = NULL;
    if (newState == kStateTapped){
        CCSequence *sequence = CCSequence::create(CCAnimate::create(getAnim()), CCCallFuncN::create(this, callfuncN_selector(Collision::removeAndClean)) ,NULL);
        action = sequence;
    }
    else if(newState == kStateDead){
        this->setIsActive(false);
        this->setVisible(false);
        this->removeFromParentAndCleanup(true);
    }
    if (action != NULL) {
        this->runAction(action);
    }
}
Esempio n. 8
0
/**
 * Get the width of the event
 *
 * @return The width of the event
 */
fixed Event::getWidth () {

	fixed width;

	if (animType == E_NOANIM) return F32;

	if ((set->anims[animType] & 0x7F) == 0) return 0;

	width = ITOF(getAnim()->getWidth());

	// Blank sprites for e.g. invisible springs
	if ((width == F1) && (getHeight() == F1)) return F32;

	return width;

}
Action::ResultE
AnimBindAction::bindFields(AttachmentContainer *attCon)
{
    AnimTargetAttachment *targetAtt = getTargetAtt(attCon);

    if(targetAtt == NULL)
        return Action::Continue;

    Animation       *anim  = getAnim();
    DataSourceMapIt  dsIt  = _dsMap.begin();
    DataSourceMapIt  dsEnd = _dsMap.end  ();

    while(dsIt != dsEnd)
    {
        if(dsIt->first.find(targetAtt->getTargetId()) != 0)
        {
            ++dsIt;
            continue;
        }

        std::string targetId;
        std::string subTargetId;

        splitTargetId(dsIt->first, targetId, subTargetId);

        if(targetId != targetAtt->getTargetId())
        {
            ++dsIt;
            continue;
        }

        SINFO << "AnimBindAction::bindFields: binding source '"
              << dsIt->first << "' to '" << targetId << "' - '"
              << subTargetId << "'" << std::endl;

        FieldDescriptionBase *fDesc =
            attCon->getType().getFieldDesc(subTargetId.c_str());

        if(fDesc == NULL)
        {
            SWARNING << "AnimBindAction::bindFields: no Field for "
                     << "subTargetId [" << subTargetId << "] found."
                     << std::endl;
            ++dsIt;
            continue;
        }

        // create channel
        AnimChannelUnrecPtr channel = dsIt->second->createChannel();
        anim->editMFChannels()->push_back(channel);

         // create blender
        UInt32 fId = fDesc->getFieldId();

        if(targetAtt->getMFBlenders()->size() <= fId)
            targetAtt->editMFBlenders()->resize(fId + 1, NULL);

        AnimBlenderUnrecPtr blender = targetAtt->getBlenders(fId);

        if(blender == NULL)
        {
            blender = dsIt->second->createBlender();
            targetAtt->editMFBlenders()->replace(fId, blender);
        }

        // on create all fields are marked as changed - this causes
        // the blender to write to its destination even though
        // it has no valid input data - avoid it by committing before
        // connecting the blender to its dest
        commitChanges();

        blender->addChannel(channel                 );
        blender->connectTo (attCon, fDesc->getName());

        // remove bound data source from map
        DataSourceMapIt eraseIt = dsIt;
        ++dsIt;
        _dsMap.erase(eraseIt);
    }

    if(_dsMap.empty() == true)
    {
        return Action::Quit;
    }
    else
    {
        return Action::Continue;
    }
}