Пример #1
0
bool AGENT::check_fight_collisions(void)
{
	int xhit, yhit, ttmp;
	if ((state == AGENT::READY_FIGHT || state == AGENT::FIGHTING) && !group->is_single_unit() && (ttmp = check_attackcollisions(xhit, yhit))) {
		
		double xup = (x > get_previous_x()) ? get_actual_speed() : -get_actual_speed();
		double yup = (y > get_previous_y()) ? get_actual_speed() : -get_actual_speed();
		
		switch (ttmp) {
			case 1:
			x = get_previous_x();
			y = get_previous_y();
			break;

			case 2:
			y = get_previous_y();
			x += xup;
			break;

			case 3:
			x = get_previous_x();
			y += yup;
			break;
			
			default:
			break;
		}

        double r = angle_to(xhit, yhit) * M_PI / 180;
		

		// rotate if not stuck
		if (!is_stuckcounter()) turn_fromto(angle_dest(), angle_to(group->get_x(), group->get_y()));
		if (has_not_moved()) stuckcounter++;
		else if (stuckcounter > 0) stuckcounter --;

		collision = PATHER::AGENT_COLLIDE;
		agent_collided = NULL;
		return false;
		return true;
    }
    return false;
}
Пример #2
0
void dial_view::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
  o_dial_widget->mInitPos = event->pos();
  QLineF line(boundingRect().center(), o_dial_widget->mInitPos);
  QLineF base_line(boundingRect().width() / 2, 0.0, boundingRect().center().x(),
                   boundingRect().center().y());
  o_dial_widget->mAngle = angle_to(line, base_line) - 180;
  o_dial_widget->m_is_pressed = 1;
  update();

  std::for_each(std::begin(o_dial_widget->m_on_dial_callback_list),
                std::end(o_dial_widget->m_on_dial_callback_list),
                [=](on_dial_callback_func a_func) {

    if (a_func)
      a_func(o_dial_widget->mProgressValue);
  });
}
Пример #3
0
void AGENT::update_rangedfight(GROUP* target_group)
{
	// get target
	AGENT * t = find_target_random(target_group);
	if (!t) return; // didn't find one

	// fight
	move_mult(collision ? 3.0 : 1.0);
	set_dest(t->get_x(), t->get_y());
	if (dist_dest() > unitData->range - group->get_radius()/2) { // move to target
		fight_timer--;
		if (!collision) move((int)get_dest_x(), (int)get_dest_y(), true); // move
		else collision_avoid(); // collision avoid
		state = AGENT::READY_FIGHT;
		setAnimation(is_stuckcounter() ? ANIMATION_DATA::STAND : ANIMATION_DATA::MOVE, true);
	} else { // close enough to target
		move_stop();
		state = AGENT::FIGHTING;
		double angle = rotation * M_PI / 180.;
		double angle_target = angle_to(t->get_x() - unitData->r_horiz_offset*cos(angle + M_PI/2), t->get_y() - unitData->r_horiz_offset*sin(angle + M_PI/2));
		if (is_near_angle(angle_target, 15) || group->is_building()) { // deal damage
			// create projectile
			if (frame_num() == unitData->rattack_frame) {
			    if (is_first_frame_display()) {
			        double t_angle = angle_target*M_PI/180;
			        int plife = (int)(dist_to(t->get_x(), t->get_y()) - getRadius() - 2*t->getRadius());
                    part_sys.add(attack_type->particle, x + getRadius()*cos(t_angle) + unitData->r_horiz_offset*cos(t_angle + M_PI/2), y + getRadius()*sin(t_angle) + unitData->r_horiz_offset*sin(t_angle + M_PI/2), angle_target, (plife > 0) ? plife : t->getRadius(), attack_type, t->getGroup(), t->get_id(), group->get_id());
			    }
			}
            // unit stuff
            set_dest(x, y);
			setAnimation(ANIMATION_DATA::RANGED, true);
		} else { // face target
			fight_timer--;
			rotate_towards((int)angle_target);
			if (!is_near_angle(angle_target, 20)) setAnimation(ANIMATION_DATA::STAND, true);
		}
	}

	// single units sync group position with their own
	if (group->is_single_unit()) group->sync_to(this);

	// update gemeric stuff
	update();
}