long SensorSystem::scanMover (Mover* mover) { //--------------------------------------------------------------------- // For now, I DO NOT return the largest contact. This should be // okay, since it'll just get caught during the next normal update next // frame. if (!enabled()) return(0); if (mover->getExists() && (mover->getTeamId() != owner->getTeamId())) { long contactStatus = calcContactStatus(mover); if (isContact(mover)) { if (contactStatus == CONTACT_NONE) removeContact(mover); else { modifyContact(mover, contactStatus == CONTACT_VISUAL ? true : false); //getLargest(currentLargest,mover,contactStatus); } } else { if (contactStatus != CONTACT_NONE) { addContact(mover, contactStatus == CONTACT_VISUAL ? true : false); //getLargest(currentLargest,mover,contactStatus); totalContacts++; } } } return(0); }
void KrecikApp::updateCar(Time elapsed) { // ruch kołami float spd = cc.motorSpeed; // [dg/s] Body* car = this->getBody("car"); b2WheelJoint* left = this->getJoint<b2WheelJoint>(car, this->getBody("left wheel")); b2WheelJoint* right = this->getJoint<b2WheelJoint>(car, this->getBody("right wheel")); if(Keyboard::isKeyPressed(Keyboard::Up)) { left->SetMotorSpeed(DGtoRD(spd)); right->SetMotorSpeed(DGtoRD(spd)); } else if(Keyboard::isKeyPressed(Keyboard::Down)) { left->SetMotorSpeed(-DGtoRD(spd)); right->SetMotorSpeed(-DGtoRD(spd)); } else { left->SetMotorSpeed(0.0f); right->SetMotorSpeed(0.0f); } // obrót! float angle = RDtoDG(car->b->GetAngle()); if(angle > 360.0f) { car->b->SetTransform(car->b->GetPosition(), DGtoRD(angle - 360.0f)); dispBonusMsg(L"Obrót!\n +50"); pts += 50; } if(angle < -360.0f) { car->b->SetTransform(car->b->GetPosition(), DGtoRD(angle + 360.0f)); dispBonusMsg(L"Obrót!\n +50"); pts += 50; } // skok i mega skok if(lastTouch.getElapsedTime() >= seconds(1.5f)) { if(isContact(car, getBody("ground"))) lastTouch.restart(); else { dispBonusMsg(L"Skok!\n +70"); pts += 70; lastTouch.restart(); } } // ustaw widok View v = this->win.getView(); v.setCenter(getCarPos()); this->win.setView(v); }
bool TriggerNode::removeContact(TriggerNode *t) { if (!isContact(t)) return false; contacts.remove(t); scene->eventTrigger(this, t, TRIGGER_EVENT_DISCONTACT); if (events[TRIGGER_EVENT_DISCONTACT].function != NULL) { events[TRIGGER_EVENT_DISCONTACT].function(this, t, events[TRIGGER_EVENT_DISCONTACT].data); } return true; }
bool TriggerNode::appendContact(TriggerNode *t) { if (isContact(t)) return false; contacts.append(t); scene->eventTrigger(this, t, TRIGGER_EVENT_CONTACT); if (events[TRIGGER_EVENT_CONTACT].function != NULL) { events[TRIGGER_EVENT_CONTACT].function(this, t, events[TRIGGER_EVENT_CONTACT].data); } return true; }
void SensorSystem::addContact (MoverPtr mover, bool visual) { Assert(!isContact(mover), 0, " SensorSystem.addContact: already contact "); if (numContacts < MAX_CONTACTS_PER_SENSOR) { contacts[numContacts] = mover->getHandle(); if (visual) contacts[numContacts] |= VISUAL_CONTACT_FLAG; if (notShutdown) master->addContact(this, mover, numContacts, visual ? CONTACT_VISUAL : getSensorQuality()); numContacts++; } }
//--------------------------------------------------------------------------- long SensorSystem::scanBattlefield (void) { //NOW returns size of largest contact! long currentLargest = -1; if (!owner) Fatal(0, " Sensor has no owner "); if (!master) Fatal(0, " Sensor has no master "); if ((masterIndex == -1) || (range < 0.0)) return(0); long numNewContacts = 0; long numMovers = ObjectManager->getNumMovers(); for (long i = 0; i < numMovers; i++) { MoverPtr mover = (MoverPtr)ObjectManager->getMover(i); if (mover->getExists() && (mover->getTeamId() != owner->getTeamId())) { long contactStatus = calcContactStatus(mover); if (isContact(mover)) { if (contactStatus == CONTACT_NONE) removeContact(mover); else { modifyContact(mover, contactStatus == CONTACT_VISUAL ? true : false); getLargest(currentLargest,mover,contactStatus); } } else { if (contactStatus != CONTACT_NONE) { addContact(mover, contactStatus == CONTACT_VISUAL ? true : false); getLargest(currentLargest,mover,contactStatus); numNewContacts++; } } } } totalContacts += numNewContacts; return(currentLargest); }