コード例 #1
0
ファイル: snake.cpp プロジェクト: glararan/QtSnake
void Snake::update()
{
    if(getIsDead())
    {
        emit snakeIsDead();

        return;
    }

    if(getHead().x() <= -1 || getHead().x() >= grid.x() || getHead().y() <= -1 || getHead().y() >= grid.y())
    {
        emit killedSelf();

        return;
    }

    for(int i = 0; i < body.count(); ++i)
    {
        if(i == 0)
        {
            last = body.first();

            switch(direction)
            {
                case Top:
                    body.first().setY(body.first().y() - 1);
                    break;

                case Bottom:
                    body.first().setY(body.first().y() + 1);
                    break;

                case Left:
                    body.first().setX(body.first().x() - 1);
                    break;

                case Right:
                    body.first().setX(body.first().x() + 1);
                    break;
            }
        }
        else
        {
            QPoint now = body[i];

            if(body[i] == body.first())
                emit killedSelf();

            body[i] = last;

            last = now;
        }
    }

    dirChanged = false;
}
コード例 #2
0
ファイル: Mario.hpp プロジェクト: Imkid/ballin-adventure
sf::Vector2f cMario::getMovement(void)
{
    sf::Vector2f movementVector;

    if (!getIsDead()) {
        if (isOnGround()) {
        ySpeed = -8;
        yAccel = 0;
        xAccel = rand() % 4;
        }
    }
    yAccel += .3;

    movementVector.x = xSpeed + xAccel;
    movementVector.y = ySpeed + yAccel;
    return movementVector;
}