void TriggerHandler::deleteTriggers() { while(!mDeleteTriggerStack.empty()) { TriggerBase *pTrigger = mDeleteTriggerStack.top(); //Attempt to remove the trigger's bounding volumes. if(pTrigger->getSourceBV()) { DX10Module::getInstance()->removeRenderObject(pTrigger->getSourceBV()); } if(pTrigger->getDestinationBV()) { DX10Module::getInstance()->removeRenderObject(pTrigger->getDestinationBV()); } if(pTrigger) { delete pTrigger; pTrigger = NULL; } mDeleteTriggerStack.pop(); } }
HitResponse Player::collision(GameObject& other, const CollisionHit& ) { Bullet* bullet = dynamic_cast<Bullet*> (&other); if(bullet) { return FORCE_MOVE; } if(other.get_flags() & FLAG_PORTABLE) { Portable* portable = dynamic_cast<Portable*> (&other); assert(portable != NULL); if(portable && grabbed_object == NULL && controller->hold(Controller::ACTION) /*&& fabsf(hit.normal.x) > .9*/) { grabbed_object = portable; grabbed_object->grab(*this, get_pos(), dir); return CONTINUE; } } #ifdef DEBUG assert(dynamic_cast<MovingObject*> (&other) != NULL); #endif MovingObject* moving_object = static_cast<MovingObject*> (&other); if(moving_object->get_group() == COLGROUP_TOUCHABLE) { TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other); if(trigger) { if(controller->pressed(Controller::UP)) trigger->event(*this, TriggerBase::EVENT_ACTIVATE); } return FORCE_MOVE; } BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy != NULL) { if(safe_timer.started() || invincible_timer.started()) return FORCE_MOVE; return CONTINUE; } return FORCE_MOVE; }
void Arrangement :: updateMotion(MotionManager& motionManager, cv::Mat homography){ if(!active) return; for(int i = 0; i<triggerCount; i++) { TriggerBase * trigger = triggers[i]; if(!trigger->active) continue; float motion = motionManager.getMotionAtPosition(trigger->pos, trigger->radius*2, homography); trigger->registerMotion(motion/255); //cout << motion << endl; } }
HitResponse Player::collision(GameObject& other, const CollisionHit& hit) { Bullet* bullet = dynamic_cast<Bullet*> (&other); if(bullet) { return FORCE_MOVE; } Player* player = dynamic_cast<Player*> (&other); if(player) { return ABORT_MOVE; } if(hit.left || hit.right) { try_grab(); //grab objects right now, in update it will be too late } assert(dynamic_cast<MovingObject*> (&other) != NULL); MovingObject* moving_object = static_cast<MovingObject*> (&other); if(moving_object->get_group() == COLGROUP_TOUCHABLE) { TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other); if(trigger) { if(controller->pressed(Controller::UP)) trigger->event(*this, TriggerBase::EVENT_ACTIVATE); } return FORCE_MOVE; } BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy != NULL) { if(safe_timer.started() || invincible_timer.started()) return FORCE_MOVE; return CONTINUE; } return CONTINUE; }
void Arrangement :: updateLayout(ofRectangle& triggerarea, float minspacing, bool showDebug, bool triggersDisabled) { triggerArea = triggerarea; minimumSpacing = minspacing; float xPos = 0;//triggerArea.x; int triggerIndex = 0; triggerCount = 0; float lastSpacing = 0; if(triggerPattern.triggers.size()==0) return; if(fixedPosition) { //vector<TriggerBase*>& triggers = triggerPattern.triggers; for (int i = 0; i<triggerPattern.triggers.size(); i++) { TriggerBase* trigger = triggerPattern.triggers[i]; float yvar = triggerPattern.verticalVariations[triggerIndex]; float ypos = triggerPattern.verticalPositions[triggerIndex] + ofRandom(-yvar, yvar); ypos *= triggerArea.height/2; if(!trigger->fixedPosition) trigger->pos.x = xPos + triggerArea.x; trigger->pos.y = ypos + triggerArea.getCenter().y; xPos += 50;//triggerPattern.horizSpacings[i]; //cout << trigger->pos.x << " " << trigger->pos.y << endl; if(triggers.size()<=i) triggers.push_back(trigger); if(active) trigger->start(); trigger->disabled = triggersDisabled; trigger->showDebugData = showDebug; triggerCount++; } } else { //cout << "updateLayout " << triggerArea.x << " " << triggerArea.width << endl; while (xPos < (triggerArea.width/2)-minimumSpacing/2) { //cout << xPos << endl; TriggerBase* triggerLeft; TriggerBase* triggerRight; //bool makeNew = false; if(triggersLeft.size()>triggerCount) { triggerLeft = triggersLeft[triggerCount]; triggerRight = triggersRight[triggerCount]; //cout << "REUSING TRIGGERS" << endl; } else { triggerLeft = triggerPattern.triggers[triggerIndex]->clone(); triggerRight = triggerPattern.triggers[triggerIndex]->clone(); triggersLeft.push_back(triggerLeft); triggersRight.push_back(triggerRight); triggers.push_back(triggerLeft); triggers.push_back(triggerRight); //cout << "MAKING NEW TRIGGERS" << endl; } float yvar = triggerPattern.verticalVariations[triggerIndex]; float ypos = triggerPattern.verticalPositions[triggerIndex] + ofRandom(-yvar, yvar); ypos *= triggerArea.height/2; triggerLeft->pos.y = ypos + triggerArea.getCenter().y; triggerLeft->pos.x = xPos; triggerRight->pos = triggerLeft->pos; lastSpacing = (minimumSpacing * triggerPattern.horizSpacings[triggerIndex]); xPos+=lastSpacing; triggerIndex++; if(triggerIndex>=triggerPattern.triggers.size()) triggerIndex = 0; triggerCount++; } // times by two to get both sets triggerCount *=2; // and subtract one to get rid of double in middle //triggerCount--; float spacing = (triggerArea.width/2) / (xPos- (lastSpacing*0.5)) ; //cout << "spacing " << spacing << endl; //cout << triggerCount << endl; for(int i = 0; i<triggers.size(); i+=2) { //cout << i << " trigger "; triggers[i]->pos.x *=spacing; triggers[i+1]->pos.x = (triggerArea.x + triggerArea.width) - triggers[i]->pos.x; triggers[i]->pos.x+=triggerArea.x; // disable spares! if(i>=triggerCount) triggers[i]->stop(); else { if(active) triggers[i]->start(); triggers[i]->disabled = triggersDisabled; triggers[i]->showDebugData = showDebug; } if(i+1>=triggerCount) triggers[i+1]->stop(); else { if(active) triggers[i+1]->start(); triggers[i+1]->disabled = triggersDisabled; triggers[i+1]->showDebugData = showDebug; } } } }