int snd_PlaySamplesFromAtLength(int frameCount, int arrayIndex, int startIndex)
{
    if (!playState.open || frameCount <= 0)
    {
        return 0;
    }

    int available = snd_AvailableSpace();

    int bytesPerFrame = 2;
    if (playState.stereo)
    {
        // stereo
        bytesPerFrame *= 2;
    }
    int size = frameCount * bytesPerFrame;

    int framesWritten;
    if (available < size)
    {
        framesWritten = available;
    }
    else
    {
        framesWritten = size;
    }

    u8* src = ((u8*) arrayIndex + (startIndex * bytesPerFrame));
    PutSound(src, size);

    return framesWritten;
}
示例#2
0
文件: main.c 项目: theStack/bluecube
/*=========================================================================
// Name: GameOverAnimation()
// Desc: Gameover Animation!
//=======================================================================*/
static void GameOverAnimation()
{
    static int counter = 1; /* Sound counter */

    if (bExplode) {
        while (!IsBrickSet(x,y)) { /* Search for the next brick */
            x++;
            if (x == BOX_BRICKS_X) {
                x = 0;
                y++;
                if (y == BOX_BRICKS_Y) { /* End reached? */ 
                    bExplode = 0;
                    return;
                }
            }
        } /* Booooom! ;) */

        BrickExplosion(x, y, 2, 20);
        SetBrick(x, y, 0);
        counter--;
        if (counter == 0) { /* Sound will be played every six bricks */
            PutSound(&sndLine);
            counter = 6;
        }
    }
    else if (NoParticlesLeft())
        gamestate = STATE_MENU;
}
示例#3
0
SoundFile *SoundData::GetSound (const char *name)
{
    SoundFile   *sound;

    sound = soundfiles.Get(csHashCompute(name), NULL);

    // sound is null when theres no cached SoundFile
    if (sound == NULL)
    {
        // we go search the library .. maybe it has it
        if (libsoundfiles.Contains(csHashCompute(name)))
        {
            // SoundFile is in our library, copy it
            sound = new SoundFile(libsoundfiles.Get(csHashCompute(name), NULL));
            PutSound(sound);
        }
        else
        {
            // no such SoundFile ;( return NULL
            return NULL;
        }
    }

    // update lasttouch to keep that SoundFile in memory
    sound->lasttouch = csGetTicks();
    return sound;
}
示例#4
0
bool SoundData::LoadSoundFile (const char *name, csRef<iSndSysData> &snddata)
{
    SoundFile                   *snd;
    csRef<iDataBuffer>          soundbuf;

    if ((snd = GetSound(name)) != NULL)
    {
        /* Sound exists in "known or loaded state
         * get the sound with GetSound
         * check if its already loaded ..
         * return true if it is
         * if not load it and mark it loaded
         */
        if (snd->loaded == true)
        {
            snddata = snd->snddata;
            return true;
        }
    }
    else
    {
        // maybe this is a dynamic file create a handle and push it into our array
        snd = new SoundFile (name, name);
        PutSound(snd);
    }

    /* load the sounddata into a buffer */
    if (!(soundbuf = vfs->ReadFile (snd->filename)))
    {
        Error2("Can't load file '%s'!", name); /* FIXME */
        return false;
    }

    /* extract sound from data */
    if (!(snddata = sndloader->LoadSound (soundbuf)))
    {
        Error2("Can't load sound '%s'!", name);
        return false;
    }

    snd->loaded = true;
    snd->snddata = snddata;
    return true;
}
示例#5
0
文件: main.c 项目: theStack/bluecube
/*=========================================================================
// Name: Game_Loop()
// Desc: The main loop for the game
//=======================================================================*/
static void Game_Loop()
{
    if (!bPause) {
        if (!bGameOver) {
            cluster.dropCount--;  /* Decrease time until the next fall */
            if (cluster.dropCount == 0) {
                if (MoveCluster(0)) /* If cluster "collides"... */
                    NewCluster();   /* then create a new one ;) */
            }

            /* Increase Level */
            if (((level == 0) && (lines >=  10)) ||
                ((level == 1) && (lines >=  20)) ||
                ((level == 2) && (lines >=  40)) ||
                ((level == 3) && (lines >=  80)) ||
                ((level == 4) && (lines >= 100)) ||
                ((level == 5) && (lines >= 120)) ||
                ((level == 6) && (lines >= 140)) ||
                ((level == 7) && (lines >= 160)) ||
                ((level == 8) && (lines >= 180)) ||
                ((level == 9) && (lines >= 200))) {
                level++;
                PutSound(&sndNextlevel);
            }
        }
        else {
            GameOverAnimation();
        }

        if (bCrazy)        /* If crazy mode is actived... */
            BoxDrawMove(); /* ... change box settings!    */
        MoveStars();       /* Move stars */
        UpdateParticles(); /* Move particles */
    }

    DrawScene();
}
示例#6
0
文件: main.c 项目: theStack/bluecube
/*=========================================================================
// Name: Mainloop()
// Desc: the one and only mainloop ;-)
//=======================================================================*/
void Mainloop()
{
    SDL_Event event;

    while (!bDone) { /* Mainloop */
        switch (gamestate) {
        case STATE_MENU:
            MainMenu_Loop();
            SDL_Delay(TimeLeft());
            break;

        case STATE_PLAY:
            while (SDL_PollEvent(&event)) {
                switch (event.type) {
                case SDL_QUIT: bDone = 1; break;
                case SDL_KEYDOWN:
                    /* Escape can be pressed everytime to get back to the menu */
                    if (event.key.keysym.sym == SDLK_ESCAPE) 
                        gamestate = STATE_MENU;

                    if (!bPause && !bGameOver) /* Is the game active? */
                    switch (event.key.keysym.sym) {
                    case SDLK_SPACE:
                        MoveCluster(1); /* "drop" cluster...      */
                        NewCluster();   /* ... and create new one */
                        break;
                    case SDLK_DOWN:  if (MoveCluster(0)) NewCluster(); break;
                    case SDLK_LEFT:  MoveClusterLeft();  break;
                    case SDLK_RIGHT: MoveClusterRight(); break;
                    case SDLK_UP:    TurnClusterRight(); break;
                    case SDLK_p:     bPause = 1; break; /* Activate pause mode */
                    
                    case SDLK_c: /* Crazy mode... */
                        if (!bCrazy)
                            bCrazy = 1;
                        else {
                            BoxDrawInit();
                            bCrazy = 0;
                        }
                        break;
                        
#ifdef DEBUG_CHANGE_LEVEL_WITH_KEYS
                    case SDLK_w:
                        if (level < 10) {
                            level++;
                            PutSound(&sndNextlevel);
                        }
                        break;
                    case SDLK_q:
                        if (level > 0)
                            level--;
                        break;
#endif
                    default: break;
                    }
                    else if (event.key.keysym.sym == SDLK_p) /* deactivate pause mode again */
                        bPause = 0;

                    break;
                }
            }
            Game_Loop();

            SDL_Delay(TimeLeft());
            break;

        case STATE_GAMEOVER:
            break;

        case STATE_CREDITS:
            /* Credits_Loop(false); */
            SDL_Delay(TimeLeft());
            break;

        case STATE_EXIT:
            bDone = 1;
            break;
        }
    }
}