Beispiel #1
0
void showTitle()
{
    bool showingTitle = true;
    while(showingTitle)
    {
        arduboy.clear();
        // X, Y, name, width, height, color
        arduboy.drawBitmap(0, 0, title, 128, 64, 1); 
        arduboy.display();
        if(arduboy.pressed(A_BUTTON))
            showingTitle = false;
        if(arduboy.pressed(B_BUTTON))
        {
            delay(200);
            bool showingHighscore = true;
            showHighscore();
            while(showingHighscore)
            {
                if(arduboy.pressed(A_BUTTON)) 
                {
                    showingTitle = false;
                    showingHighscore = false;
                }
                if(arduboy.pressed(B_BUTTON))
                    showingHighscore = false;
            }
        }
        delay(200);
    }
}
Beispiel #2
0
void ram(void)
{
    int c=0, pos=0,del=0;

    struct pos_s tail[MAX_SNAKE_LEN];
    snake.tail = tail;

    // load the highscore
    highscore = highscore_get();

    // initially reset everything
    reset();

    while (1) {
        if(!(++c % snake.speed)) {
            handle_input();

            pos = (snake.t_start+1) % MAX_SNAKE_LEN;
            snake.tail[pos].x = snake.tail[snake.t_start].x;
            snake.tail[pos].y = snake.tail[snake.t_start].y;

            if(snake.dir == 0)
                snake.tail[pos].x++;
            else if(snake.dir == 1)
                snake.tail[pos].y++;
            else if(snake.dir == 2)
                snake.tail[pos].x--;
            else if(snake.dir == 3)
                snake.tail[pos].y--;

            snake.t_start = pos;

            if (pos < snake.len) {
                del = MAX_SNAKE_LEN - (snake.len - pos);
            } else
                del = pos - snake.len;

            // remove last, add first line
            draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF);
            draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000);

            // check for obstacle hit..
            if (hitWall() || hitSelf()) {
                death_anim();
                if (showHighscore())
                    break;
                reset();
            } else if (hitFood())
                next_level();

            lcdDisplay();
        }

#ifdef SIMULATOR
        delayms(50);
#else
        delayms(3);
#endif
    }
}
Beispiel #3
0
/**
 * create the action events create the gui.
 */
void KJezzball::initXMLUI()
{
    m_newAction = KStdGameAction::gameNew( this, SLOT(newGame()), actionCollection() );
    // AB: originally KBounce/KJezzball used Space for new game - but Ctrl+N is
    // default. We solve this by providing space as an alternative key
    KShortcut s = m_newAction->shortcut();
    s.append(KKeySequence(QKeySequence(Key_Space)));
    m_newAction->setShortcut(s);

    KStdGameAction::quit(this, SLOT(close()), actionCollection() );
    KStdGameAction::highscores(this, SLOT(showHighscore()), actionCollection() );
    m_pauseButton = KStdGameAction::pause(this, SLOT(pauseGame()), actionCollection());
    KStdGameAction::end(this, SLOT(closeGame()), actionCollection());
    KStdGameAction::configureHighscores(this, SLOT(configureHighscores()),actionCollection());

    new KAction( i18n("&Select Background Folder..."), 0, this, SLOT(selectBackground()),
                       actionCollection(), "background_select" );
    m_backgroundShowAction =
        new KToggleAction( i18n("Show &Backgrounds"), 0, this, SLOT(showBackground()),
                           actionCollection(), "background_show" );
    m_backgroundShowAction->setCheckedState(i18n("Hide &Backgrounds"));
    m_backgroundShowAction->setEnabled( !m_backgroundDir.isEmpty() );
    m_backgroundShowAction->setChecked( m_showBackground );

    m_soundAction = new KToggleAction( i18n("&Play Sounds"), 0, 0, 0, actionCollection(), "toggle_sound");
}
Beispiel #4
0
// Leben verloren
void playerDead(Game *g)
{
    freeShotList(g->enemyShots);
    g->enemyShots = NULL;
    if (g->player.shot != NULL) {
        free(g->player.shot);
        g->player.shot = NULL;
    }
    
    g->player.lives -= 2; // startNewLevel erhöht um 1
    g->level--;
    g->enemyContainer.ufo.alive = false;
    g->enemyContainer.ufo.lastufo = ms_time();
    
    // Spielerposition
    g->player.rect.x = WIDTH/2 - PLAYER_WIDTH/2;
    g->player.rect.y = PLAYER_Y_POS;
    g->player.rect.w = PLAYER_WIDTH;
    g->player.rect.h = PLAYER_HEIGHT;
    
    SDL_Rect area = {0, BORDER_TOP, WIDTH, HEIGHT - BORDER_TOP};
    SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
    
    if (g->player.lives+2 == 0) {
        free(g->blocks);
        
        showGameOver(g);
        saveHighscore(g->score);
        showHighscore(g);
        
        SDL_Flip(g->screen);
        
        // Warten auf Tastendruck
        SDL_Event e;
        SDL_WaitEvent(&e);
        
        SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
        
        initGame(g);
        startNewLevel(g);
        
        return;
    }
    
    SDL_Flip(g->screen);
    usleep(100000);
    
    // Nur zeichen, daher None
    movePlayer(g, None);
    
    startNewLevel(g);
}
Beispiel #5
0
void KBlocksWin::setupGUILayout()
{
    QAction *action;

    action = KStandardGameAction::gameNew(this, SLOT(singleGame()), actionCollection());
    action->setText(i18n("Single Game"));
    actionCollection()->addAction(QStringLiteral("newGame"), action);

    action = new QAction(this);
    action->setText(i18n("Human vs AI"));
    actionCollection()->addAction(QStringLiteral("pve_step"), action);
    connect(action, &QAction::triggered, this, &KBlocksWin::pveStepGame);

    m_pauseAction = KStandardGameAction::pause(this, SLOT(pauseGame()), actionCollection());
    actionCollection()->addAction(QStringLiteral("pauseGame"), m_pauseAction);
    m_pauseAction->setEnabled(false);

    action = KStandardGameAction::highscores(this, SLOT(showHighscore()), actionCollection());
    actionCollection()->addAction(QStringLiteral("showHighscores"), action);

    action = KStandardGameAction::quit(this, SLOT(close()), actionCollection());
    actionCollection()->addAction(QStringLiteral("quit"), action);

    KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection());

    KToggleAction *soundAction = new KToggleAction(i18n("&Play sounds"), this);
    soundAction->setChecked(Settings::sounds());
    actionCollection()->addAction(QStringLiteral("sounds"), soundAction);
    connect(soundAction, &KToggleAction::triggered, this, &KBlocksWin::setSoundsEnabled);

    // TODO
    mScore = new QLabel(i18n("Points: 0 - Lines: 0 - Level: 0"));
    statusBar()->addPermanentWidget(mScore);
    connect(mpGameScene, &KBlocksScene::scoreChanged, this, &KBlocksWin::onScoreChanged);
    connect(mpGameScene, &KBlocksScene::isHighscore, this, &KBlocksWin::onIsHighscore);

    Kg::difficulty()->addStandardLevelRange(
        KgDifficultyLevel::Easy, KgDifficultyLevel::Hard
    );
    KgDifficultyGUI::init(this);
    connect(Kg::difficulty(), &KgDifficulty::currentLevelChanged, this, &KBlocksWin::levelChanged);

    setupGUI();
}
Beispiel #6
0
void KBlocksWin::setupGUILayout()
{
    QAction *action;
    
    action = KStandardGameAction::gameNew(this, SLOT(singleGame()), actionCollection());
    action->setText(i18n("Single Game"));
    actionCollection()->addAction( QLatin1String( "newGame" ), action);
    
    action = new KAction(this);
    action->setText(i18n("Human vs AI"));
    actionCollection()->addAction( QLatin1String( "pve_step" ), action);
    connect(action, SIGNAL(triggered(bool)), this, SLOT(pveStepGame()));
    
    m_pauseAction = KStandardGameAction::pause(this, SLOT(pauseGame()), actionCollection());
    actionCollection()->addAction( QLatin1String( "pauseGame" ), m_pauseAction);
    
    action = KStandardGameAction::highscores(this, SLOT(showHighscore()), actionCollection());
    actionCollection()->addAction( QLatin1String( "showHighscores" ), action);
    
    action = KStandardGameAction::quit(this, SLOT(close()), actionCollection());
    actionCollection()->addAction( QLatin1String( "quit" ), action);
    
    KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection());
    
    KAction* soundAction = new KToggleAction(i18n("&Play sounds"), this);
    soundAction->setChecked(Settings::sounds());
    actionCollection()->addAction( QLatin1String( "sounds" ), soundAction);
    connect(soundAction, SIGNAL(triggered(bool)), this, SLOT(setSoundsEnabled(bool)));
    
    // TODO
    statusBar()->insertItem( i18n("Points: 0 - Lines: 0 - Level: 0"), 0 );
    connect(mpGameScene, SIGNAL(scoreChanged(int,int,int,int)), this,  SLOT(onScoreChanged(int,int,int,int)));
    connect(mpGameScene, SIGNAL(isHighscore(int,int,int)), this,  SLOT(onIsHighscore(int,int,int)));
    
    Kg::difficulty()->addStandardLevelRange(
        KgDifficultyLevel::Easy, KgDifficultyLevel::Hard
    );
    KgDifficultyGUI::init(this);
    connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(levelChanged()));
    
    setupGUI();
}
Beispiel #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;
}
Beispiel #8
0
void ram(void)
{
    int c=0, pos=0,del=0;

    struct pos_s tail[MAX_SNAKE_LEN];
    snake.tail = tail;

    // initially reset everything
    reset();

    while (1)
    {
        if(!(++c % snake.speed)) {
            if (handle_input()){ //handle_input returns 1 to quit
                break;
            }

            pos = (snake.t_start+1) % MAX_SNAKE_LEN;
            snake.tail[pos].x = snake.tail[snake.t_start].x;
            snake.tail[pos].y = snake.tail[snake.t_start].y;

            if(snake.dir == 0)
            {
                snake.tail[pos].x++;
                if(snake.tail[pos].x*SNAKE_DIM>=MAX_X) snake.tail[pos].x=MIN_X/SNAKE_DIM+1;
            }
            else if(snake.dir == 1)
            {
                snake.tail[pos].y++;
                if(snake.tail[pos].y*SNAKE_DIM>=MAX_Y) snake.tail[pos].y=MIN_Y/SNAKE_DIM+1;
            }
            else if(snake.dir == 2)
            {
                snake.tail[pos].x--;
                if(snake.tail[pos].x*SNAKE_DIM<=MIN_X) snake.tail[pos].x=MAX_X/SNAKE_DIM-1;
            }
            else if(snake.dir == SNAKE_DIM)
            {
                snake.tail[pos].y--;
                if(snake.tail[pos].y*SNAKE_DIM<=MIN_Y) snake.tail[pos].y=MAX_Y/SNAKE_DIM-1;
            }

            snake.t_start = pos;

            del = pos - snake.len;
            if (pos < snake.len) del += MAX_SNAKE_LEN;

            // remove last, add first line
            draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF);
            draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000);

            // check for obstacle hit..
            if (hitSelf()) {
                death_anim();
                if (showHighscore())
                    break;
                reset();
            }
            else if (hitFood())
                next_level();

            lcdDisplay();
        }

#ifdef SIMULATOR
        delayms(50);
#else
        delayms(3);
#endif
    }
}