Example #1
0
void Monster::onThink(Duration elapsedTime) {
	Creature::onThink(elapsedTime);

	if (!isAlive()) {
		return;
	}

	if (despawn()) {
		exitWorld();
		return;
	}

	updateRelationship();
	updateTarget();
	updateRetargeting(elapsedTime);
	updateFollowing();
	updateBabbling(elapsedTime);

	// TODO refactor >>
	onThinkDefense(std::chrono::duration_cast<Milliseconds>(elapsedTime).count());
	// <<
}
Example #2
0
//-----------------------------------------------------------------
void ofxTrackingHistory::updatePosition(cv::Point posUpdate)
{

    //vectorCopy(close, prevClose); // copies the close vector
    //vectorSetFalse(close);
    prevClose = close;
    close = vector<bool>(followed[followingPath].size(), false); //boolean of trail points within distance threshold

    double prop = findAdjacentTrailPoints(posUpdate, close); // marks the close trail points true
    double newProp = vectorDiffProp(close, prevClose); // look 1 update back for new points

    // check if any of them are true.
    /*bool follow = false;
    for (int ii = 0; ii<close.size(); ii++) {
        if (close[ii]) {
            follow = true;
            break;
        }
    }*/
    followed[followingPath] = vectorOR(followed[followingPath], close); // bools for individual path points
    pos.push_back(posUpdate); // save the position to the history
    updateFollowing(newProp, prop>0); // update some other stuff
}
Example #3
0
bool DrawPathTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	cur_pos = event->pos();
	cur_pos_map = map_coord;
	
	if (!containsDrawingButtons(event->buttons()))
	{
		updateHover();
	}
	else if (!editingInProgress())
	{
		left_mouse_down = true;
		if (picking_angle)
			pickAngle(map_coord, widget);
		else
			return false;
	}
	else if (following)
	{
		updateFollowing();
	}
	else
	{
		bool drag_distance_reached = (event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx();
		if (dragging && !drag_distance_reached)
		{
			if (create_spline_corner)
			{
				create_spline_corner = false;
			}
			else if (path_has_preview_point)
			{
				undoLastPoint();
			}
		}
		else if (drag_distance_reached)
		{
			// Giving a direction by dragging
			dragging = true;
			create_spline_corner = false;
			create_segment = true;
			
			if (previous_point_is_curve_point)
				angle_helper->setCenter(click_pos_map);
			
			QPointF constrained_pos;
			angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget);
			
			if (previous_point_is_curve_point)
			{
				hidePreviewPoints();
				float drag_direction = calculateRotation(constrained_pos.toPoint(), constrained_pos_map);
				
				// Add a new node or convert the last node into a corner?
				if ((widget->mapToViewport(previous_pos_map) - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx())
					createPreviewCurve(MapCoord(click_pos_map), drag_direction);
				else
				{
					create_spline_corner = true;
					// This hides the old direction indicator
					previous_drag_map = previous_pos_map;
				}
			}
			
			updateDirtyRect();
		}
	}
	
	return true;
}