Qbasicnews.com

Full Version: Greenboxes in c++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've remade my qbasic 9-line-screensaver
in c++ with allegro (not 9 lines anymore...):
Code:
#include "allegro.h"
int main()
    {
    PALETTE palette;
    int c,x,y;

    srand(time(NULL));
    allegro_init();
    install_keyboard();
    set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 320, 200, 0, 0);
    set_display_switch_mode(SWITCH_PAUSE);


    for (c=0; c<32; c++)
        {
        palette[c].r = 0;
        palette[c].g = c;
        palette[c].b = 0;
        palette[63-c].r = 0;
        palette[63-c].g = c;
        palette[63-c].b = 0;
        }

    set_palette(palette);

    while (!keypressed())
        {
        x=(rand()%32)*10;
        y=(rand()%20)*10;
        acquire_screen();
        c=getpixel(screen,x,y);
        if(c==63)
            {
            c=0;
            }
        else
            {
            c++;
            }
        rect(screen, x, y, x+9, y+9, c);
        release_screen();
        }
    remove_keyboard();
    return 0;
    }

END_OF_MAIN();
is this possible, though?

Code:
#include "allegro.h" int main() {PALETTE palette; int c,x,y;
srand(time(NULL)); allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 320, 200, 0, 0); set_display_switch_mode(SWITCH_PAUSE); for (c=0; c<32; c++) { palette[c].r = 0; palette[c].g = c; palette[c].b = 0; palette[63-c].r = 0; palette[63-c].g = c; palette[63-c].b = 0; } set_palette(palette); while (!keypressed()) { x=(rand()%32)*10; y=(rand()%20)*10; acquire_screen(); c=getpixel(screen,x,y); if(c==63) { c=0; } else { c++; } rect(screen, x, y, x+9, y+9, c); release_screen(); } return 0; } END_OF_MAIN();
When you do it like that but in the qb contest you had not to
use colon joined lines and semicolon is the equal in c/c++ :wink:
but the problem is that in qb you can have quite a lot of IF..else statements in one line without colons. In C you need a colon for each statement I think. (or is it just colons before brackets?) Bah.