Пример #1
0
    void Paddle::die() {
        setLives(getLives() - 1);
        updateLives();

        if(getLives() > 0) {
            reset();
            updateView(_view);
        }
    }
Пример #2
0
void ParticleEmitter::update(float time_delta)
{
	spawnParticles(time_delta);
	updateLives(time_delta);
	updatePositions(time_delta);
	updateRotations(time_delta);
	for (auto* module : m_modules)
	{
		module->update(time_delta);
	}
}
Пример #3
0
// Neues Level starten
void startNewLevel(Game *g)
{
    g->level++;
    g->player.lives++;
    
    if (g->enemyShots != NULL) {
        freeShotList(g->enemyShots);
        g->enemyShots = NULL;
    }
    if (g->player.shot != NULL) {
        free(g->player.shot);
        g->player.shot = NULL;
    }
    
    updateLives(g);
    
    // Erste Reihe: Typ 1
    for (int x = 0; x < ENEMYFIELD_WIDTH; x++) {
        g->enemyContainer.enemys[x][0].dead = false;
        g->enemyContainer.enemys[x][0].type = 1;
        g->enemyContainer.enemys[x][0].animationState = 0;
    }
    
    // Reihe 2+3: Typ 2
    for (int y = 1; y < 3; y++) {
        for (int x = 0; x < ENEMYFIELD_WIDTH; x++) {
            g->enemyContainer.enemys[x][y].dead = false;
            g->enemyContainer.enemys[x][y].type = 2;
            g->enemyContainer.enemys[x][y].animationState = 0;
        }
    }
    
    // Reihe 4+5: Typ 3
    for (int y = 3; y < ENEMYFIELD_HEIGHT; y++) {
        for (int x = 0; x < ENEMYFIELD_WIDTH; x++) {
            g->enemyContainer.enemys[x][y].dead = false;
            g->enemyContainer.enemys[x][y].type = 3;
            g->enemyContainer.enemys[x][y].animationState = 0;
        }
    }
    
    // Alien Box Positionieren
    g->enemyContainer.posx = BORDER;
    g->enemyContainer.posy = BORDER_TOP + 50;
    g->enemyContainer.aliveCount = ENEMY_COUNT;
    g->enemyContainer.moveDirection = Right;
    
    SDL_Flip(g->screen);
    usleep(500000);
    
    // Box Zeichnen
    moveEnemys(g);
}
Пример #4
0
SIDlg::SIDlg(QWidget *parent)
:QDialog(parent)
{
    setMinimumSize(450, 450);

    setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) | Qt::WindowMaximized);

    setSizeGripEnabled(true);
    setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
    setWindowTitle("Happy Cube Space Invaders!");

    QVBoxLayout *layout = new QVBoxLayout;
    setLayout(layout);
    m_game = new GameWidget(this);
    m_game->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    connect(m_game, SIGNAL(levelChanged(int)), this, SLOT(setLevel(int)));
    connect(m_game, SIGNAL(scoreChanged(int)), this, SLOT(setScore(int)));
    connect(m_game, SIGNAL(livesChanged(int)), this, SLOT(updateLives(int)));

    layout->addWidget(m_game);

    m_lowbar = new QHBoxLayout;
    layout->addLayout(m_lowbar);
    m_level = new QLabel("Level: 1");
    m_score = new QLabel("Score: 0");

    m_lowbar->addWidget(m_score);
    m_lowbar->addStretch();
    m_lowbar->addWidget(m_level);

    QFont font("Courier", 20, QFont::Bold);
    m_level->setFont(font);
    m_score->setFont(font);

    m_lifePix = PicBucket::instance().getPic(1, 2).pixmap.scaled(QSize(25, 25), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    updateLives(3);
}
Пример #5
0
    void Paddle::aquire(const Item& item, Ball& ball) {
        switch(item.getType()) {
            case Item::Type::PaddleSize:
                if(getWidth() < 90) {
                    setWidth(getWidth() + 10);
                    setPositionRange(255, 544 - getWidth());

                    if(_position.x - 5 > _positionRange.x)
                        _position.x -= 5;

                    updateView(_view);
                }
                break;

            case Item::Type::ExtraLive:
                setLives(getLives() + 1);
                updateLives();
                break;

            case Item::Type::BallSpeedReduction:
                ball.resetSpeedFactor();
                break;
        }
    }
Пример #6
0
void SinglePlayerView::setLevelData( LevelData *newData )
{
	this->data = newData;

	QObject::connect( data, SIGNAL( loading( int, const QString& ) ), this, SLOT( onDataLoading( int, const QString& ) ) );
	QObject::connect( data, SIGNAL( error( int, const QString& ) ), this, SLOT( onDataError( int, const QString& ) ) );
	QObject::connect( data, SIGNAL( success() ), this, SLOT( onDataSuccess() ) );

	if ( !data->isDataLoaded() ) {
		data->loadData();
	}

	if ( !data->isDataLoaded() ) {
		return;
	}

	model = new BoardModel(

	    data->pieceRows(),
	    data->pieceColumns(),
	    data->placeRows(),
	    data->placeColumns()
	);

	QObject::connect( model, SIGNAL( boardComplete() ), this, SLOT( onBoardComplete() ) );

	// Set the backgroung
	scene->setBackgroundBrush( data->bgBrush() );
	data->bgItem()->setPos( 0, 0 );
	data->bgItem()->setZValue( 0 );
	scene->addItem( data->bgItem() );
	scene->removeItem( prevbg );

	board = new BoardItem( data, model );

	int n = data->pieces()->size();

	for ( int i = 0;i < n;i++ ) {
		PieceItem *item = data->pieces()->at( i );
		scene->addItem( item );
		item->setParentItem( board );
	}

	board->setPos( data->boardRect().x(), data->boardRect().y() );

	qDebug() << "Put board into position" << data->boardRect().x() << data->boardRect().y();
	board->scale(
	    ( float ) data->boardRect().width() / ( float ) board->boundingRect().width(),
	    ( float ) data->boardRect().height() / ( float ) board->boundingRect().height()
	);

	qDebug() << "Scaling board by" <<
	( float ) data->boardRect().width() / ( float ) board->boundingRect().width() <<
	( float ) data->boardRect().height() / ( float ) board->boundingRect().height() <<
	"to size" << ( float ) data->boardRect().width() << ( float ) data->boardRect().height() <<
	"from size" << ( float ) board->boundingRect().width() << ( float ) board->boundingRect().height() ;

	board->setZValue( 500 );
	board->setAcceptsHoverEvents( true );

	scene->addItem( board );

	// Add Lives

	if ( data->lifePixmap() ) {
		int x0=data->lifeRect().x();
		int y0=data->lifeRect().y();
		int dx=data->lifeRect().width()/4;
		int dy=data->lifeRect().height();
		qDebug() << "Life position (" << x0 << y0 << ") and size ("<<dx<<dy<<")";

		QPixmap s=data->lifePixmap()->scaled(QSize(dx,dy), Qt::KeepAspectRatio, Qt::SmoothTransformation);
		qDebug() << "Life position (" << x0 << y0 << ") and size" << s.size();
		life1 = new QGraphicsPixmapItem( s );
		life2 = new QGraphicsPixmapItem( s );
		life3 = new QGraphicsPixmapItem( s );
		life4 = new QGraphicsPixmapItem( s );
		life1->setPos( x0, y0 );
		life2->setPos( x0+dx, y0 );
		life3->setPos( x0+2*dx, y0 );
		life4->setPos( x0+3*dx, y0 );
		scene->addItem(life1);
		scene->addItem(life2);
		scene->addItem(life3);
		scene->addItem(life4);

	}

	updateLives();

	// Add Time
	totalTime=timeLeft= data->time();
	timerrect=new QGraphicsRectItem(data->timeRect());
	timerrect->setBrush(data->timerBrush());
	scene->addItem(timerrect);
	updateTimer();
	// Add Score

	scene->setSceneRect( data->bgItem()->boundingRect() );
	fitInView( data->bgItem()->boundingRect(), Qt::KeepAspectRatio );
	QTimer::singleShot( 10, this, SLOT( showready() ) );
	QTimer::singleShot( 1110, this, SLOT( showset() ) );
	QTimer::singleShot( 2210, this, SLOT( showgo() ) );
}
Пример #7
0
int main(int argc, char *argv[])
{
    Game *g = (Game*) malloc(sizeof(Game));
    SDL_Event event;
    Uint8 *keystates;
    Uint8 quit = false;
    long lastplayerupdate = ms_time();
    long lastenemyupdate = ms_time();
    long lastshotupdate = ms_time();
    long lastufoupdate = ms_time();
    
    srand((unsigned int) time(NULL));
    
    // SDL initialisieren
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
        printf("Kann Video nicht initialisieren: %s\n", SDL_GetError());
        exit(1);
    }
    
    atexit(SDL_Quit);
    
    g->screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_HWSURFACE);
    
    if (g->screen == NULL) {
        printf("Kann Video-Modus nicht festlegen: %s\n", SDL_GetError());
        exit(1);
    }
    
    TTF_Init();
    
    
    // Game initialisieren
    initGame(g);
    startNewLevel(g);
    updateScore(g);
    updateLives(g);
    showHighscore(g);
    updateBlocks(g);
    
    // Nächster Grafikzustand
    SDL_Flip(g->screen);
    
    // Loop
    while (!quit) {
        // SDL Events abfragen
        SDL_PollEvent(&event);
        
        // Tastenstatus laden
        keystates = SDL_GetKeyState(NULL);
        
        // Escape gedrückt -> beenden
        // TODO: Menü aufrufen statt beenden
        if (keystates[SDLK_ESCAPE]) {
            saveHighscore(g->score);
            quit = true;
        }
        
        // Nur wenn entweder Links oder Rechts, nicht beide zur selben Zeit
        if (keystates[SDLK_LEFT] != keystates[SDLK_RIGHT] && lastplayerupdate >= 100) {
            lastplayerupdate = ms_time();
            
            // Links
            if (keystates[SDLK_LEFT]) {
                movePlayer(g, Left);
            }
            // Rechts
            if (keystates[SDLK_RIGHT]) {
                movePlayer(g, Right);
            }
        }
        
        if (keystates[SDLK_SPACE]) {
            shoot(g);
        }
        
        // UFO
        if (ms_time() - lastufoupdate >= UFO_UPDATE) {
            lastufoupdate = ms_time();
            ufo(g);
        }
        
        // Alienposition aktualisieren?
        // Exponentialfunktion, die Level und Alienanzahl berücksichtigt
        if (ms_time() - lastenemyupdate >= ENEMY_UPDATE_BASE * pow(0.95, g->level * 3 + (ENEMY_COUNT - g->enemyContainer.aliveCount) / 4)) {
            lastenemyupdate = ms_time();
            updateBlocks(g);
            moveEnemys(g);
            alienShot(g);
        }
        
        // Schüsse aktualisieren
        if (ms_time() - lastshotupdate >= SHOT_UPDATE) {
            lastshotupdate = ms_time();
            updateShots(g);
            checkCollision(g);
            movePlayer(g, None);
        }
        
        usleep(20000); // begrenzt CPU Last
        // Nächster Grafikzustand
        SDL_Flip(g->screen);
    }
    
    SDL_Quit();
    return 0;
}
Пример #8
0
 void AbstractView::livesChanged(const Event& event)
 {
     updateLives(event.lives);
 }