void EntityManager :: updateJellies(){ for( vector<Jelly*>::iterator j = jellies.begin(); j < jellies.end(); ){ (*j)->update(); (*j)->collide(hero->global, 30.0f); (*j)->setDestination( (*j)-> global ); //jellyfish also collide with sparks for(int i = 0; i < sparks.size(); i++){ (*j)->collide(sparks.at(i)->global, 30.0f); } oscManager->jelly( (*j)->contacts(), dist( (*j)->global, hero->global) ); if((*j)->onScreen() == true){ entityGenerator->jellyLastSeen = 0; } //delete if too far away if( farFromHero( (*j)->global ) == true ){ removeFromColliders( (GameObject*)(*j) ); delete *j; j = jellies.erase(j); } else { ++j; } } entityGenerator->jellyLastSeen++; }
void Guardian::updateState() { bool needChange = false; switch (state) { case IDLE: { if (pressSkill()) { event = stateMachine->findEventVal("EVENT_SKILLA"); needChange = true; break; } // if (armature->getAnimation()->isComplete()) { if (lostHero()) { event = stateMachine->findEventVal("EVENT_LOSTHERO"); needChange = true; }else if (farFromHero()) { event = stateMachine->findEventVal("EVENT_LOSTTARGET"); needChange = true; } // } } break; case CHASE: { if (pressSkill()) { event = stateMachine->findEventVal("EVENT_SKILLA"); needChange = true; break; } if (arrivePos(targetMovePos)) { event = stateMachine->findEventVal("EVENT_ARRIVE_TARGET"); needChange = true; } } break; case SKILL: { if (armature->getAnimation()->isComplete()) { event = stateMachine->findEventVal("EVENT_ACTIONOVER"); needChange = true; } } break; } if(event == stateMachine->action_undefined){ currKey = 0; needChange = false; return; } currKey = 0; if (needChange) { switch2NextState(state, event); needChange = false; event = StateMachine::action_undefined; } }
void EntityManager :: updateSpores(){ for( vector<Spore*>::iterator p = spores.begin(); p < spores.end(); ){ bool ended = false; if( farFromHero( (*p)->global ) == true ){ //true if spore is ended for any reason (either via the player collision, or from being too far away from the player) ended = true; } else { (*p)->update(); (*p)->collide(hero->global); //sound happens if there's any contact with the field if((*p)->contact() == true){ environment->splash( (*p)->global, 22*(*p)->depth, 30 ); oscManager->sporeBoop( (*p)->health ); } //reset field counter if the character is near enough to any field if(((*p)->onScreen() == true)){ entityGenerator->sporeLastSeen = 0; } //checks if health is low enough if((*p)->alive() == false){ ended = true; //do spark-creating business (new Spark, bubbles, splashes, OSC message) sparks.push_back(new Spark((*p)->global, (*p)->type(), &image->sparkImg ) ); oscManager->newSpark( (*p)->type() ); colliders.push_back( sparks.back() ); environment->bubble( (*p)->local, 6 ); for(int i = 0; i < 10; i++){ environment->splash( (*p)->global + vrand(10), rand(5,20), rand(5,35) ); } } } if(ended == true){ delete *p; p = spores.erase(p); } else { ++p; } } entityGenerator->sporeLastSeen++; }
void EntityManager :: updateEggs(){ bool inside = false; for( vector<Egg*>::iterator p = eggs.begin(); p < eggs.end(); ){ if( farFromHero( (*p)->global ) == true ){ //delete if too far from hero removeFromColliders((GameObject*)(*p)); delete *p; p = eggs.erase(p); } else { //update (*p)->update(); (*p)->collide(hero->global, hero->radius + 15.0f); (*p)->setInside(hero->global); //friendlies can also cause collision with egg for(int i = 0 ; i < friendlies.size(); i++){ (*p)->collide( friendlies.at(i)->global, friendlies.at(i)->radius + 15.0f ); } //change the global 'inside' state - true if the hero is inside ANY of the eggs if( (*p)->inside() == true ){ inside = true; } if( (*p)->onScreen() == true){ entityGenerator->eggLastSeen = 0; } ++p; } } //if player is inside, send osc message, slow hero down if(inside == true){ if(insideEgg == false){ insideEgg = true; oscManager->egg(1); hero->slow(true); } } else { if(insideEgg == true){ insideEgg = false; oscManager->egg(0); hero->slow(false); } } entityGenerator->eggLastSeen++; }
void EntityManager :: updatePlankton(){ for( vector<Plankton*>::iterator p = plankton.begin(); p < plankton.end(); ){ (*p)->update(); //true if plankton should be deleted (either from being eaten, or from being too far from the hero) bool deleteThisPlankton = false; if( farFromHero( (*p)->global ) == true ){ deleteThisPlankton = true; //if plankton is far enough away from hero, delete } else { //cycle through colliders, see if any have eaten the plankton int i = 0; while(!deleteThisPlankton && i < colliders.size()){ //check if collider has eaten plankton if(dist( (*p)->global, colliders.at(i)->global) < (*p)->radius + colliders.at(i)->radius ){ //do plankton eating business (bubbles, splashes, osc message) environment->bubble( (*p)->local, 3); environment->splash( (*p)->global, 1, 75 ); float pan = ( (*p)->global.x - hero->global.x); oscManager->eatPlankton( (*p)->type(), pan , dist(hero->global, (*p)->global) ); //if collider is the HERO ( collider #0 ) and not any other entity if(i == 0){ //hero levels up etc hero->incEaten( (*p)->type() ); if(hero->getEaten() % 20 == 0){ hero->levelUp(); environment->splash( hero->global, 0, 100 ); oscManager->eighthPlankton(); } } deleteThisPlankton = true; } i++; } } //if plankton needs to be deleted (through being eaten, or being too far away from hero), delete if(deleteThisPlankton){ delete *p; p = plankton.erase(p); } else { ++p; } } }
void EntityManager :: updateUrchins(){ for( vector<Urchin*>::iterator p = urchins.begin(); p != urchins.end(); ){ //if Urchin is far enough away from hero if( farFromHero( (*p)->global ) == true){ //remove from collider list, then delete from urchin list and erase object removeFromColliders((GameObject*)(*p)); delete *p; p = urchins.erase(p); } else { //Otherwise, go through standard update: collision, target, OSC messages (*p)->collide(hero->global, hero->radius+10.0f); (*p)->update(); (*p)->avoidColliders(&colliders); if((*p)->inSpace == true){ if(plankton.size() > 0){ if(plankton.at(0)->global.y > -1000 && dist(plankton.at(0)->global, (*p)->global ) < 800 ){ (*p)->setDestination( plankton.at(0)->global ); } else { (*p)->setDestination( vec2((*p)->global.x + rand(-100,100), rand(0,300)) ); } } } //friendlies also cause collision for(int i = 0 ; i < friendlies.size(); i++){ (*p)->collide( friendlies.at(i)->global, 30.0f ); } //OSC message - distance and collision amount oscManager->urchin( dist( (*p)->global, hero->global ), (*p)->contactAmount() ); if((*p)->onScreen() ){ entityGenerator->urchinLastSeen = 0; } ++p; } } entityGenerator->urchinLastSeen++; }
void EntityManager :: updateStarfish(){ for( vector<Starfish*>::iterator p = starfish.begin(); p < starfish.end(); ){ if( farFromHero( (*p)->global ) == true ){ //delete if too far away removeFromColliders((GameObject*)(*p)); delete *p; p = starfish.erase(p); } else { //update standardly (*p)->collide(hero->global); (*p)->update(); //chord change if active if( (*p)->activated() == true){ oscManager->changeChord(); environment->splash( (*p)->global, 20.0f, 100.0f ); environment->bubble( (*p)->local, 5 ); } if( (*p)->onScreen() == true){ entityGenerator->starLastSeen = 0; } //periodically creates bubbles if( (*p)->fleeing ) { if( getElapsedFrames() % 15 == 0) environment->bubble( (*p)->local, 1 ); if( getElapsedFrames() % 3 == 0) environment->splash( (*p)->global, 30.0f, 40.0f); } ++p; } } entityGenerator->starLastSeen++; }