Bullet* createBullet(Tower *tower){ Bullet *bullet = malloc(sizeof (Bullet)); bullet->type = tower->type->typeBul; bullet->position = searchEnemy(tower); return bullet; }
bool Mutalisk::update(float dt) { checkUnitDirection(); setAnimationFromDirection(); // This sets animation according to their angle direction setParticleBehaviour(); //particleDirection(); coll->setPos(center.x + collider_offset.x, center.y + collider_offset.y); switch (state) { case IDLE: if (timer_to_check.read() >= TIME_TO_CHECK) { target_to_attack = searchEnemy(); if (target_to_attack != NULL) { newEntityFound(); second_target_to_attack = target_to_attack->searchNearestAlly(); } else if (faction == COMPUTER && target_pos.x != -1 && target_pos.y != -1 && (range_of_vision / 2) < (abs(center.x - target_pos.x) + abs(center.y - target_pos.y) - (coll->rect.w / 2 + coll->rect.h / 2) / 2)) app->entity_manager->SetEnemyToPos(this, target_pos); timer_to_check.start(); } break; case MOVE: if (has_target) move(dt); break; case MOVE_ALERT: if (timer_to_check.read() >= TIME_TO_CHECK) { target_to_attack = searchEnemy(); if (target_to_attack != NULL) { newEntityFound(); second_target_to_attack = target_to_attack->searchNearestAlly(); } timer_to_check.start(); } if (has_target) move(dt); break; case MOVE_ALERT_TO_ATTACK: if (timer_to_check.read() >= TIME_TO_CHECK) { target_to_attack = searchEnemy(); if (target_to_attack != NULL) { newEntityFound(); second_target_to_attack = target_to_attack->searchNearestAlly(); } else { has_target = false; state = IDLE; } timer_to_check.start(); } if (has_target) move(dt); break; case ATTACK: if (timer_attack.read() >= (attack_frequency * attack_frequency_multiplier)) { if (area_attack) { list<Entity*> targets = searchEntitiesInRange(target_to_attack, area_range); while (targets.begin() != targets.end()) { attackWithoutRange(targets.front()); targets.pop_front(); } if (!attack(target_to_attack)) { state = IDLE; target_to_attack = NULL; second_target_to_attack = NULL; } } else if (!attack(target_to_attack)) { state = IDLE; target_to_attack = NULL; second_target_to_attack = NULL; } timer_attack.start(); Entity* target = target_to_attack; target_to_attack = searchEnemy(); if (target_to_attack != NULL) second_target_to_attack = target_to_attack->searchNearestAlly(); if (target_to_attack != NULL && (target == NULL || target->center != target_to_attack->center)) { newEntityFound(); } } break; case DYING: if (sound_active == true) { app->audio->playFx(app->entity_manager->fx_mutalisk_death, 0); sound_active = false; } if (current_animation->finished()) { to_delete = true; coll->to_delete = true; } break; case WAITING_PATH_MOVE: if (app->path->getPathFound(id, path)) { has_target = true; state = MOVE; timer_to_check.start(); } break; case WAITING_PATH_MOVE_ALERT: if (app->path->getPathFound(id, path)) { has_target = true; state = MOVE_ALERT; timer_to_check.start(); } break; case WAITING_PATH_MOVE_ALERT_TO_ATTACK: if (app->path->getPathFound(id, path)) { has_target = true; state = MOVE_ALERT_TO_ATTACK; timer_to_check.start(); } break; } if (grouped && (state != MOVE && state != MOVE_ALERT && state != WAITING_PATH_MOVE && state != WAITING_PATH_MOVE_ALERT && state != IDLE)) { grouped = false; flying = true; } return true; }