Пример #1
0
bool World::resetTet(TetrominoType* type) {
    Vec2d* newCoords = new Vec2d(spawnPoint);
    if (nextTet == nullptr) {
        TetrominoType* randomType = typeFactory->getRandomType();
        int spawnOffset = randomType->getHeight();
        newCoords->setY(newCoords->getY() - spawnOffset);
        activeTet = tetFactory->getTetromino(randomType, newCoords)->withDirection(defaultDirection);
    } else {
        delete activeTet;
        activeTet = nextTet;
    }

    type = typeFactory->getRandomType();
    int spawnOffset = type->getHeight();
    delete newCoords;

    newCoords = new Vec2d(spawnPoint);
    if (mode == INFINITY_MODE) newCoords->setX((rand() % 8) + 1);
    newCoords->setY(newCoords->getY() - spawnOffset);
    nextTet = tetFactory->getTetromino(type, newCoords)->withDirection(defaultDirection);
    
    Translation translation = Translation(activeTet->getCoords());
    
    vector<Quad*>* resetQuads = translation.transform(activeTet->getQuads());
    bool success = !heap->collidesWithQuads(resetQuads);
    
    Quad::deleteQuads(resetQuads, true);

    delete newCoords;
    
    return success;
}
Пример #2
0
void Gameplay::draw(Drawable* drawable, GLint pixelSize) {
    Vec2d* drawCoords = drawable->getCoords()->applyScale(pixelSize);
    glPushMatrix();
    glTranslatef(drawCoords->getX(), drawCoords->getY(), 0);
    for (Segment* segment : *drawable->getMesh()) {
        Vec2d* relativeOffset = segment->getRelativeCoord()->getInverse();
        glTranslatef(relativeOffset->getX() * pixelSize, relativeOffset->getY() * pixelSize, 0);
        glColor3fv(segment->getColour()->getColour3fv());
        Primitive::drawSquare(pixelSize);
    }
    glPopMatrix();
}
Пример #3
0
bool World::collidesWithQuads(vector<Quad*>* quads) {
    for (auto quad : *quads) {
        for (int i = 0; i < quad->getVertexCount(); i++) {
            Vec2d* vertex = quad->getVertices()[i];
            if (vertex->getY() < 0 || vertex->getY() > bounds->getY() || vertex->getX() < 0 || vertex->getX() > bounds->getX()) {
                cout << "Collision with world " << vertex->toString() << endl;
                return true;
            }
        }
    }
    return false;
}
Пример #4
0
bool World::resetTet(char letter) {
    TetrominoType* type = typeFactory->getType(letter);

    Vec2d* newCoords = new Vec2d(spawnPoint);
    int spawnOffset = type->getHeight();
    newCoords->setY(newCoords->getY() - spawnOffset);
    
    activeTet = tetFactory->getTetromino(type, newCoords)->withDirection(defaultDirection);
    nextTet = tetFactory->getTetromino(type, newCoords)->withDirection(defaultDirection);
    
    return !heap->collidesWithQuads(activeTet->getQuads());
}