Exemplo n.º 1
0
void PlayerMoveComponent::update(double deltaTime)
{
	//Prüft die Tastatureingabe und berechnet mit der Beschleunigung die Geschwindigkeit
	determineDirection();
	velocity += deltaTime * accel;
	if (velocity.getLength() > maxVelocity) {
		velocity.normalize();
		velocity *= maxVelocity;
	}

	CVector position = parent->getPosition();
	double rotation = parent->getRotation();

	position += PIXEL_PER_METER *deltaTime * velocity;


	angularVelo += deltaTime * angularAccel;
	if (abs(angularVelo) > maxAngularVelocity) {
		angularVelo = (angularVelo > 0.0)? maxAngularVelocity : - maxAngularVelocity;
	}
	rotation += deltaTime * angularVelo;

	if (rotation > 360.0) rotation  -= 360.0;
	if (rotation < -360.0) rotation += 360.0;

//Prüfen ob der Spieler aus dem Bild laufen würde
	if (position[0] + playerSize > 1024) {
		position[0] = 1024 - playerSize;
		velocity[0] *= -0.2;
	

	}
	if (position[0] < 0 + playerSize) {
		position[0] = 0 + playerSize;
		velocity[0] *= -0.2;
	}
	if (position[1] + playerSize + 20 > 800) {
		position[1] = 800 - playerSize - 20;
		velocity[1] *= -0.2;
	}
	if (position[1] < 0 + playerSize + 10) {
		position[1] = 0 + playerSize + 10;
		velocity[1] *= -0.2;
	}

	parent->setPosition(position);

	//Kollisionsabfrage
	quadColission();
	
	//Prüfen ob der Spieler einen Gegenstand aufnehmen würde
	Character *item = CharacterManager::instance()->getCharacter("Item");
	ItemComponent *itemComp = getComponent<ItemComponent>(item);
	if((item->getPosition()-getPosition()).getLength() < 50.0f){
		itemComp->pickUp();
		score++;
	}
}
Exemplo n.º 2
0
/** Computes the direction (straight, left, right) of all graph nodes and the
 *  lastest graph node that is still turning in the given direction. For
 *  example, if a successor to this graph node is turning left, it will compute
 *  the last graph node that is still turning left. This data is used by the
 *  AI to estimate the turn radius.
 *  At this stage there is one restriction: if a node with more than one
 *  successor is ahead, only successor 0 is used. That might lead to somewhat
 *  incorrect results (i.e. the last successor is determined assuming that
 *  the kart is always using successor 0, while in reality it might follow
 *  a different successor, resulting in a different turn radius. It is not
 *  expected that this makes much difference for the AI (since it will update
 *  its data constantly, i.e. if it takes a different turn, it will be using
 *  the new data).
 */
void QuadGraph::computeDirectionData()
{
    for(unsigned int i=0; i<m_all_nodes.size(); i++)
    {
        for(unsigned int succ_index=0;
            succ_index<m_all_nodes[i]->getNumberOfSuccessors();
            succ_index++)
        {
            determineDirection(i, succ_index);
        }   // for next < getNumberOfSuccessor

    }   // for i < m_all_nodes.size()
}   // computeDirectionData
Exemplo n.º 3
0
Formula::Formula(Node nodeA, Node nodeB, int laneNumber)
{
    a = determineSlope(nodeA.x(), nodeB.x(), nodeA.y(), nodeB.y());
    b = determineB(nodeA.x(), nodeA.y());
    Node tempNode = Node(nodeB.x(), nodeA.y());

    float distanceX = calculateDistance(nodeA, tempNode);
    float distanceY = calculateDistance(nodeB, tempNode);
    lineLength_ = calculateDistance(nodeA, nodeB);

    variationX_ = (distanceX / lineLength_);
    variationY_ = (distanceY / lineLength_);

    determinePerpendicular(nodeA, nodeB, laneNumber);
    determineDirection(nodeA, nodeB);
}
Exemplo n.º 4
0
void StepperDriver::setAction(long steps_to_move){
  this->seq_steps_left = abs(steps_to_move);  // how many steps to take
  determineDirection(steps_to_move);
}
Exemplo n.º 5
0
Graph <Point2D> EarClipper::triangulate(const Graph <Point2D> &arg, std::vector <Triangle2D> *triangles) {
    Graph <Point2D> result (arg);
    std::vector<bool> vertexStatus (arg.getVertexCount(), false); //1 - ear, 0 - not ear
    std::list<int> remainingVertices;
    short direction = determineDirection(arg);

    for (unsigned int i = 0; i < arg.getVertexCount(); ++i) {
        remainingVertices.push_back(i);
    }

    for (std::list<int>::iterator it = remainingVertices.begin(); it != remainingVertices.end(); ++it) {
        vertexStatus[*it] = isEar(arg, remainingVertices, it, direction);
    }

    std::list<int>::iterator currentVertex = remainingVertices.begin();
    while (remainingVertices.size() > 3) {
        bool earFound = false;

        for (unsigned int i = remainingVertices.size(); i > 0 && remainingVertices.size() > 3; --i) {
            if (vertexStatus[*currentVertex] == 1) {
                earFound = true;
                addTriangle(result, remainingVertices, currentVertex, triangles);

                std::list<int>::iterator vertexToRemove = currentVertex;

                if (++currentVertex == remainingVertices.end()) {
                    currentVertex = remainingVertices.begin();
                }
                remainingVertices.erase(vertexToRemove);
                vertexStatus[*currentVertex] = isEar(arg, remainingVertices, currentVertex, direction);

                if (currentVertex == remainingVertices.begin()) {
                    currentVertex = --remainingVertices.end();
                } else {
                    --currentVertex;
                }
                vertexStatus[*currentVertex] = isEar(arg, remainingVertices, currentVertex, direction);
            } else {
                if (++currentVertex == remainingVertices.end()) {
                    currentVertex = remainingVertices.begin();
                }
            }
        }

        if (!earFound) {
            result.connectVertices();
            triangles->clear();

            std::cerr << "Impossoble to triangulate\n";
            return result;
        }
    }

    if (triangles != 0 && remainingVertices.size() == 3) { //add remains to triangulation
        triangles->push_back(Triangle2D(arg.getVertex(*remainingVertices.begin()), arg.getVertex(*++remainingVertices.begin()),
                                        arg.getVertex(*--remainingVertices.end())));
    }

    if (triangles != 0) {
        if (validateTriangulation(arg, *triangles)) {
            std::cout << "Validation OK\n";
        } else {
            std::cerr << "Validation failed\n";
        }
    }

    return result;
}