Esempio n. 1
0
    void Physics::detectCollisions (const std::vector<PhysicsObject*>& objects)
    {
        // Lets go through each collidable object checking if they collide.
        for (auto i = 0U; i < objects.size(); ++i)
        {
            // Cache the values for the first object.
            auto        first        = objects[i];
            const auto& check        = first->getCollider();
            const auto  checkLayer   = m_layers[check.getLayer()];

            auto checkBox           = check.getBox();
            checkBox.translate (first->getPosition().x, first->getPosition().y);

            for (auto j = i + 1; j < objects.size(); ++j)
            {
                // Cache the values for the second object.
                auto        second  = objects[j];
                const auto& against = second->getCollider();

                // Check if their layers collide.
                if ((checkLayer | (1 << against.getLayer())) > 0)
                {
                    // We must now check if the rectangles intersect.
                    auto againstBox = against.getBox();
                    againstBox.translate (second->getPosition().x, second->getPosition().y);

                    // Check if they intersect.
                    if (checkBox.intersects (againstBox))
                    {
                        // Determine the desired collision type.
                        if (check.isTrigger())
                        {
                            first->onTrigger (second);

                            if (against.isTrigger())
                            {
                                second->onTrigger (first);
                            }
                        }

                        // Collider on trigger.
                        else if (against.isTrigger())
                        {
                            second->onTrigger (first);
                        }

                        // Collider on collider.
                        else
                        {
                            first->onCollision (second);
                            second->onCollision (first);
                        }
                    }
                }
            }
        }
    }
Esempio n. 2
0
void Trigger::update(float deltaTime)
{
	Actor::update(deltaTime);

	if(pollConditions())
		onTrigger();
	else
		onDoesntTrigger();
}
Esempio n. 3
0
COLL_RET AwardNode::onCollision(cocos2d::Node *other)
{
	if (COLL_FELLOWS == other->getTag())
	{
		_tank = dynamic_cast<TankSprite *>(other);
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(FileUtils::getInstance()->fullPathForFilename("audio/award.wav").c_str());
		onTrigger();
		return DESTROY;
	}
	return RETAIN;
}
Esempio n. 4
0
bool Tower::init()
{
	Layer::init();
	bool bRet = false;
	do{
		initModel();
		//_listener = EventListenerCustom::create(getName(), CC_CALLBACK_1(Tower::onTrigger, this));
		_listener = EventListenerCustom::create(getName(), [=](EventCustom *event){onTrigger(event);});
		CC_SAFE_RETAIN(_listener);
		_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this);
		bRet = true;
	} while (0);
	return bRet;
}
Esempio n. 5
0
bool HudPanel::init()
{
	_joyStickLayOut = static_cast<Layout*>(Helper::seekWidgetByName(_root, "Panel_joyStickLayOut"));
	_joyStickPanel = JoyStickPanel::create("joyStick");
	_joyStickPanel->setPosition(Vec2(400,72));
	addChild(_joyStickPanel);

	_joyStickPanel->setDieRadius(100);//设置死亡半径(外圈)
	_joyStickPanel->setFailRadius(10);//设置失效半径(內圈)
	//_stick->setAutoPosition(true);
	Detect::shareDetect()->setJoyStick(_joyStickPanel);

	_popPanel = PopPanel::getInstance();

	_bubbleLabel = BubbleLabel::create();
	addChild(_bubbleLabel);

	_layerColor = LayerColor::create(Color4B(0,0,0,255));
	_layerColor->setContentSize(Director::getInstance()->getWinSize());
	_layerColor->setOpacity(0);
	addChild(_layerColor);

	_popPanel = PopPanel::getInstance();
	_popPanel->reset();
	addChild(_popPanel);
	ChatManager::getInstance()->setChatPanel(_popPanel->chatPanel);

	//_listener = EventListenerCustom::create("hud", CC_CALLBACK_1(HudPanel::onTrigger, this));
	_listener = EventListenerCustom::create("hud", [=](EventCustom *event){onTrigger(event);});
	_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this);

	for(auto node:_buttons->getChildren())
	{
		auto button = static_cast<Button*>(node);
		button->addTouchEventListener(CC_CALLBACK_2(HudPanel::onButtonClicked, this));
	}

	auto action1 = ScaleBy::create(0.15,1.5,1.5,1.0);
	_stress1 = Sequence::create(action1,action1->reverse(),nullptr);
	_stress1->retain();

	_plotBlock = false;

	_buffList = static_cast<ListView*>(Helper::seekWidgetByName(_root, "ListView_buffs"));
	updateBuffList();
	_buffList->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(HudPanel::selectedBuffEvent, this));
	return true;
}
Esempio n. 6
0
void Processor::onTrigger(const std::shared_ptr<ProcessContext> &context, const std::shared_ptr<ProcessSessionFactory> &sessionFactory) {
  auto session = sessionFactory->createSession();

  try {
    // Call the virtual trigger function
    onTrigger(context, session);
    session->commit();
  } catch (std::exception &exception) {
    logger_->log_debug("Caught Exception %s", exception.what());
    session->rollback();
    throw;
  } catch (...) {
    logger_->log_debug("Caught Exception Processor::onTrigger");
    session->rollback();
    throw;
  }
}
void BouncyBee::update()
{
	if (triggerBox)
	{
		//printf("bouncyBee::triggerBox = %d\n", triggerBox);
		if (triggerBox->wasTripped())
		{
			active = true;
		}
	}
	if (!active)
		return;

	if (!triggerState)
	{
		onTrigger();
	}

	dx = 0;
	dy = 0;
	bool prev_at_target = at_target;
	at_target = false;
	double delta = targX - x;
	if ((int)targX - (int)x > 0)
	{
		facingRight = false;
		if (delta > maxSpeed)
		{
			dx = maxSpeed;
		}
		else
		{
			dx = delta;
		}
	}	
	else if ((int)targX - (int)x < 0)
	{
		facingRight = true;
		if (-1*delta > maxSpeed)
		{
			dx = -1*maxSpeed;
		}
		else
		{
			dx = delta;
		}
	}
	else
	{
		at_target = true;
	}	
	if (!prev_at_target && at_target)
	{
		bee_sound->stop(6);
	}

	x += dx;
	y += dy;

	if (dx || dy)
	{
		if (currentAction != FLYING)
		{
			currentAction = FLYING;
            animation.setFrames(animationTexture, sprite_rects[currentAction], frameNumbers[currentAction]);
            animation.setDelay(300);
            width = sprite_rects[currentAction][animation.getFrame()].w;
		}
	}
	else
	{
		if (currentAction != IDLE)
        {
            currentAction = IDLE;
            animation.setFrames(animationTexture, sprite_rects[currentAction], frameNumbers[currentAction]);
            animation.setDelay(-1);
            width = sprite_rects[currentAction][animation.getFrame()].w;
        }
	}
	
	animation.update();
	triggerState = true;
}
Esempio n. 8
0
Altar::Altar()
{
	/*ValueMap modell;
	ValueVector formsl;
	int i = 0,j = 0,k = 0;
	for(int i = 0; i < 5; i++)
	{

		ValueMap forml;
		ValueVector rewardl;
		rewardl.push_back(cocos2d::Value("target:detect|type:add~~~typeId:2001001|site:{5,1}"));
		rewardl.push_back(cocos2d::Value("sdfsfsfsfsfsf"));
		ValueVector mapl;

		for(int j = 0; j < 7;j++)
		{
			ValueVector rowsl;
			for(int k = 0; k < 7; k++)
			{
				rowsl.push_back(cocos2d::Value(0));
			}
			mapl.push_back(cocos2d::Value(rowsl));
		}

		forml["map"] = mapl;
		forml["reward"] = rewardl;

		formsl.push_back(cocos2d::Value(forml));
	}
	modell["forms"] = formsl;
	ValueVector switchsl;
	for(int i = 2;i < 9; i++)
	{
		for(int j = 4; j < 11;j ++)
		{
			ValueMap smodel;
			smodel["typeId"] = 2005006;
			smodel["site"] = pointToString(Vec2(i,j));
			smodel["towerId"] = 6;
			smodel["floorId"] = 4;
			switchsl.push_back(cocos2d::Value(smodel));
		}
	}
	modell["switchs"] = switchsl;

	FileUtils::getInstance()->writeToFile(modell,"altar.plist");*/




	_model = FileUtils::getInstance()->getValueMapFromFile("altar.plist");
	forms = _model["forms"].asValueVector();

	int fromNum = 0;
	for(auto pair:forms)
	{
		std::vector<std::vector<int>> formTemp;

		auto form = pair.asValueMap();
		for(auto i:form["map"].asValueVector())
		{
			std::vector<int> rowTemp;
			for(auto j:i.asValueVector())
			{
				rowTemp.push_back(j.asInt());
			}
			formTemp.push_back(rowTemp);
		}
		maps.insert(std::make_pair(fromNum, formTemp));
		fromNum++;
	}

	

	ValueVector switchsm = _model["switchs"].asValueVector();
	for(auto pair:switchsm)
	{
		auto switchModel = pair.asValueMap();
		auto cell = CellFactory::getInstance()->createCell(switchModel);
		Detect::shareDetect()->addCell(cell,PointFromString(switchModel["site"].asString()),1,switchModel["floorId"].asInt(),switchModel["towerId"].asInt());
		_switchs.push_back(cell->getName());
	}

	//_listener = EventListenerCustom::create(getName(), CC_CALLBACK_1(World::onTrigger, this));
	_listener = EventListenerCustom::create("altar1", [=](EventCustom *event){onTrigger(event);});
	CC_SAFE_RETAIN(_listener);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this);
}
Esempio n. 9
0
//-----------------------------------------------------------------------------
// 
// VEvent::onControllerUpdate( pTime, pDelta )
// 
// Integrate is only called when this event is the Next Event for the parent
// track. For each track, there is only ever *one* event being integrated - the
// event that needs to be triggered next.
//
// If the event has a duration greater than 0, then this event will continue to
// integrate until its time is up, or the controller finishes playing
// (whichever happens first).
// 
// If a value of true is returned, then this event will continue to integrate
// until a value of false is returned to the parent track. When this happens,
// this event ceases to be the track's Next Event and will not continue
// updating.
// 
//-----------------------------------------------------------------------------
bool VEvent::onControllerUpdate( const S32 &pTime, const S32 &pDelta )
{
    if ( !isEnabled() )
    {
        return false;
    }

    const S32  newTime    = ( pTime + pDelta );
    const S32 &startTime  = getStartTime();
    const S32 &finishTime = getFinishTime();

    if ( !mIsPlaying || !mTriggered )
    {
        if ( !mIsPlaying )
        {
            if ( ( pDelta > 0 && newTime < startTime )
                 || ( pDelta < 0 && newTime > startTime ) )
            {
                // Not Time to Trigger.
                return true;
            }

            if ( ( pDelta > 0 && pTime > startTime )
                 || ( pDelta < 0 && pTime < startTime ) )
            {
                //AssertFatal( false, "VEvent::onControllerUpdate() - Event has been skipped." );
                return false;
            }
        }

        if ( !mTriggered )
        {
            // Play and Trigger.
            mIsPlaying = ( mDuration > 0 );
            mTriggered = true;

            // Callback.
            onTrigger( pTime, pDelta );

            if ( mDuration == 0 )
            {
                // Stop Integrating.
                return false;
            }

            // Return Here.
            // Note: If Duration is non-zero this event will continue to update
            //       so that VEvent:: onUpdate is processed for the full event
            //       duration.
            return ( mDuration != 0 );
        }
    }

    // Complete?
    const bool isComplete = ( ( pDelta > 0 && newTime > finishTime )
                               || ( pDelta < 0 && newTime < finishTime ) );

    if ( !isComplete )
    {
        // Callback.
        onUpdate( pTime, pDelta );
    }
    else
    {
        // Complete.
        mIsPlaying = false;

        // Callback.
        onComplete( pTime, pDelta );
    }

    // Continue?
    return !isComplete;
}