//------------------------------------------------ //------------------------------------------------ void ScoringSystem::OnBallHitTrigger(CSCore::Entity* in_trigger) { for(u32 i=0; i<m_goaltriggers.size(); ++i) { if(m_goaltriggers[i] == in_trigger) { IncrementScore(i); return; } } }
//--------------------------- HandleMessage ----------------------------------- //----------------------------------------------------------------------------- bool Raven_Bot::HandleMessage(const Telegram& msg) { //first see if the current goal accepts the message if (GetBrain()->HandleMessage(msg)) return true; //handle any messages not handles by the goals switch(msg.Msg) { case Msg_TakeThatMF: //just return if already dead or spawning if (isDead() || isSpawning()) return true; //the extra info field of the telegram carries the amount of damage ReduceHealth(DereferenceToType<int>(msg.ExtraInfo)); //if this bot is now dead let the shooter know if (isDead()) { Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, ID(), msg.Sender, Msg_YouGotMeYouSOB, NO_ADDITIONAL_INFO); } return true; case Msg_YouGotMeYouSOB: IncrementScore(); //the bot this bot has just killed should be removed as the target m_pTargSys->ClearTarget(); return true; case Msg_GunshotSound: //add the source of this sound to the bot's percepts GetSensoryMem()->UpdateWithSoundSource((Raven_Bot*)msg.ExtraInfo); return true; case Msg_UserHasRemovedBot: { Raven_Bot* pRemovedBot = (Raven_Bot*)msg.ExtraInfo; GetSensoryMem()->RemoveBotFromMemory(pRemovedBot); //if the removed bot is the target, make sure the target is cleared if (pRemovedBot == GetTargetSys()->GetTarget()) { GetTargetSys()->ClearTarget(); } return true; } case Msg_IWasKilledAndIHadWeapons: { GraveMarkers::GraveRecord* pGrave = (GraveMarkers::GraveRecord*)msg.ExtraInfo; GetSensoryMem()->AddGraveToMemory(pGrave); return true; } default: return false; } }
void ModuleEnemy::OnCollision(Collider* a, Collider* b){ bool exit = false; if (a->type == ENEMY_SPAWNPOINT_COLLIDER){ list<EnemySpawn* >::iterator it = spawns.begin(); while (it != spawns.end() && !exit){ if ((*it)->Collide(a)) { exit = true; } else ++it; } } else if (a->type == GRUNT_ATTACK_COLLIDER){ a->to_delete = true; } else if (b->type == PLAYER_SHOT_COLLIDER || b->type == DEMON_SHOT_COLLIDER){ list<Enemy* >::iterator it = enemies.begin(); while (it != enemies.end() && !exit){ if ((*it)->collider == a) { if (!(*it)->invisible) { (*it)->Hit(); IncrementScore((*it)->type); } exit = true; } else ++it; } if (!exit){ list<EnemySpawn* >::iterator spawns_it = spawns.begin(); while (spawns_it != spawns.end() && !exit){ if ((*spawns_it)->collider == a) { (*spawns_it)->Hit(); exit = true; } else ++spawns_it; } } } else{ if (b->type == PLAYER_COLLIDER){ list<Enemy* >::iterator it = enemies.begin(); while (it != enemies.end() && !exit){ if ((*it)->collider == a && (*it)->type == GHOST) { (*it)->dead = true; game->player->Hit(GHOST); exit = true; } else ++it; } } list<Enemy* >::iterator it = enemies.begin(); while (it != enemies.end() && !exit){ if ((*it)->collider == a) { double center_ax = a->rect.x + a->rect.w / 2; double center_ay = a->rect.y + a->rect.h / 2; double center_bx = b->rect.x + b->rect.w / 2; double center_by = b->rect.y + b->rect.h / 2; double vector_x = center_bx - center_ax; double vector_y = center_by - center_ay; double vector_dir = sqrt(pow(vector_x, 2) + pow(vector_y, 2)); double angle = acos(vector_x / vector_dir); if (angle < M_PI / 4 || angle > 7 * M_PI / 4) (*it)->right = BLOCK; else if (angle >= 3 * M_PI / 4 && angle < 5 * M_PI / 4) (*it)->left = BLOCK; else{ if (center_ay > center_by) (*it)->up = BLOCK; else if (center_ay < center_by) (*it)->down = BLOCK; } exit = true; } else ++it; } } }