Esempio n. 1
0
/*
 * (2,5) --> (5,5)
 *   ^         |
 *   |         |
 *   |         V
 * (2,2) <-- (5,2)
 */
void pause_screen(void) {
    uint8_t shift, c;
    key_t keyp = 0;
    status_lights = LED_NONE;
    while (!keyp) {
        for (shift = 16; shift > 0; --shift) {
            /* Glowing square */
            rgb_screen[3][3] = (pixel_t) pulse[shift & 0xf];
            rgb_screen[4][3] = (pixel_t) pulse[shift & 0xf];
            rgb_screen[3][4] = (pixel_t) pulse[shift & 0xf];
            rgb_screen[4][4] = (pixel_t) pulse[shift & 0xf];
            /* Top row */
            for (c = 0; c < 4; c++) {
                rgb_screen[2+c][5] = (pixel_t) colour_cycle[(c+shift) & 0xf];
            }
            /* Right column */
            for ( ; c < 8; c++) {
                rgb_screen[5][5-c+4] = (pixel_t) colour_cycle[(c+shift) & 0xf];
            }
            /* Bottom row */
            for ( ; c < 12; c++) {
                rgb_screen[5-c+8][2] = (pixel_t) colour_cycle[(c+shift) & 0xf];
            }
            /* Left column */
            for ( ; c < 16; c++) {
                rgb_screen[2][2+c-12] = (pixel_t) colour_cycle[(c+shift) & 0xf];
            }
            for (c = 0; (c < 10) && !keyp; c++) {
                keyp = get_key_down();
                delay(100);
            }
        }
    }
}
Esempio n. 2
0
bool Input::get_qualifier_down(KeyboardQualifier qualifier) const
{
    bool result = true;
    if( value(qualifier & KeyboardQualifier::SHIFT) )
        result &= (get_key_down(KeyboardCode::LSHIFT) || get_key_down(KeyboardCode::RSHIFT));
    if( value(qualifier & KeyboardQualifier::CTRL) )
        result &= (get_key_down(KeyboardCode::LCTRL) || get_key_down(KeyboardCode::RCTRL));
    if( value(qualifier & KeyboardQualifier::ALT) )
        result &= (get_key_down(KeyboardCode::LALT) || get_key_down(KeyboardCode::RALT));
    return result;
}
Esempio n. 3
0
void play_breakmeggy(void) {
    uint8_t i;
    uint8_t tick;
    uint8_t lives = 3;
    key_t keyp, lastp = 0;
    /* - 0 1 2 3 4 5 - */
    uint8_t pos = 2;
    uint8_t ball_x = 3, ball_y = 1;
    uint8_t ball_v = STOP;
    /* XXX: This could be packed if space becomes a serious issue */
    uint8_t blocks[4][4] = {
        { 1, 1, 1, 1 },
        { 1, 1, 1, 1 },
        { 1, 1, 1, 1 },
        { 1, 1, 1, 1 },
    };

    /* 3 lives = 3 aux LEDs */
    status_lights = LED_2 | LED_1 | LED_0;
    draw_pixel(ball_x, ball_y, BALL_COLOUR);

    for (;;) {
        draw_paddle(pos);
        draw_blocks(blocks);
        draw_pixel(ball_x, ball_y, BALL_COLOUR);
        /*
         * Paddle movement and time delay
         */
        for (tick = 0; tick < TICKS; tick++) {
            keyp = get_key_down();
            if (keyp != lastp) {
                switch (keyp) {
                    case D_LEFT:
                        pos = (pos > 0) ? pos - 1 : 0;
                        if (ball_v == STOP) {
                            draw_pixel(ball_x, ball_y, c000000);
                            ball_x = (ball_x > 1) ? ball_x - 1 : 1;
                            draw_pixel(ball_x, ball_y, BALL_COLOUR);
                        }
                        draw_paddle(pos);
                        break;
                    case D_RIGHT:
                        pos = (pos < 5) ? pos + 1 : 5;
                        if (ball_v == STOP) {
                            draw_pixel(ball_x, ball_y, c000000);
                            ball_x = (ball_x < 6) ? ball_x + 1 : 6;
                            draw_pixel(ball_x, ball_y, BALL_COLOUR);
                        }
                        draw_paddle(pos);
                        break;
                    case B_RIGHT:
                        if (ball_v == STOP) {
                            ball_v = RIGHT | UP;
                        }
                        break;
                    default:
                        delay_us(2);
                        break;
                }
            }
            lastp = keyp;
            delay(20);
        }
        /*
         * Update world if ball is moving
         */
        if (ball_v != STOP) {
            /*
             * Clear old ball position
             */
            draw_pixel(ball_x, ball_y, c000000);
            /*
             * Apply standard ball velocity
             */
            ball_x = (ball_v & RIGHT) ? ball_x + 1 : ball_x - 1;
            ball_y = (ball_v & UP) ? ball_y + 1 : ball_y - 1;
            if (ball_x == 7) {
                ball_v &= ~RIGHT;
            }
            if (ball_x == 0) {
                ball_v |= RIGHT;
            }
            if (ball_y == 7) {
                ball_v &= ~UP;
            }
            /*
             * Check paddle hit
             */
            if (ball_y == 1 && (ball_x >= pos && ball_x <= pos + 2)) {
                ball_v |= UP;
            }
            /*
             * Collision detection
             */
            if (ball_y > 3) {
                /* Check block rows */
                for (i = 0; i < 4; i++) {
                    if (blocks[i][ball_y - 4] &&
                            (ball_x == 2*i || ball_x == 2*i+1)) {
                        blocks[i][ball_y - 4] = 0;
                        ball_v &= ~UP;
                        play_tone(tCs2, 100);
                        break;
                    }
                }
            }
            /*
             * Ball missed
             */
            if (ball_y == 0) {
                die_anim(75);
                if (--lives == 0) {
                    break;
                }
                /*
                 * Re-initialise game state
                 */
                pos = 2;
                ball_x = 3, ball_y = 1;
                ball_v = STOP;
                status_lights = LED_0;
                if (lives == 2) {
                    status_lights |= LED_1;
                }
            }
            draw_pixel(ball_x, ball_y, BALL_COLOUR);
        }
    }
    /*
     * Game over... ;_;
     */
}