Example #1
0
/**
 * The main loop of the jukebox. Waits for the end of the song (while updating
 * the timer) and then returns an indicator that we need the next song.
 * Also waits for keypresses; the user can press ESC, left arrow or right arrow
 * to trigger appropriate return codes.
 */
int jukebox_loop() {
    int key_p;
    while (TRUE) {
        while (keypressed()) {
            key_p = readkey() >> 8;
            if (key_p == KEY_ESC) {
                return JUKEBOX_EXIT;
            }
            if (key_p == KEY_LEFT) {
                return JUKEBOX_PREV_SONG;
            }
            if (key_p == KEY_RIGHT) {
                return JUKEBOX_NEXT_SONG;
            }
        }
        clear_bitmap(buffer);
        update_starfield(buffer);
        update_track_data();
        update_song_data();
        draw_help();
        vsync();
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

        // When we're at the end of the file, midi_pos will be set to
        // the negative number of beats in the song.
        if (midi_pos < 0) {
            rest(TRACK_CHANGE_WAIT);
            return JUKEBOX_NEXT_SONG;
        }
    }
}
Example #2
0
void update()
{
    update_starfield(stars, get_ship_rotation(ship));
    update_ship(ship);
}