All pastes #525800 Raw Edit

Something

public text v1 · immutable
#525800 ·published 2007-05-31 14:51 UTC
rendered paste body
#include <allegro.h>
#include <iostream>

BITMAP *buffer = NULL; //buffer
BITMAP *playerSprite = NULL; //playersprite

class sprite {
    protected:
        int x,y;
    public:
        sprite() {x=y=0;}
        sprite(int _x, int _y) {x = _x; y = _y;}
        virtual ~sprite() {}
        virtual void draw(BITMAP *dest) {draw_sprite(buffer, dest, x, y);}
};

class paddle : public sprite {
    public:
        paddle() : sprite() {}
        paddle(int _x, int _y) : sprite(_x,_y) {}
        void control();
        /*virtual void draw() {
            rectfill(buffer, x-5, y+50, x+5, y-50, makecol(255,0,255));
        }*/
};

void paddle::control() {
    if (key[KEY_UP]) --y;
    if (key[KEY_DOWN]) ++y;
}

int main(int argc, char *argv[])
{
    allegro_init();
    install_keyboard();
    buffer = create_bitmap(640,480);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
    playerSprite = load_bitmap("test.bmp",NULL);
    paddle *myPlayer[1];
    myPlayer[0] = new paddle(20,240);
    myPlayer[1] = new paddle(620,240);
    //the game loop
    while (!key[KEY_ESC]) {
         for(int i=0;i<2;i++) {
            myPlayer[i]->draw(playerSprite);
            myPlayer[i]->control();
        }
        blit(buffer, screen, 0,0,0,0,640,480);//Draw the buffer to the screen
        clear_bitmap(buffer); // Clear the contents of the buffer bitmap
    }
    destroy_bitmap(playerSprite); // Release the bitmap data
    destroy_bitmap(buffer); // Release the bitmap data
    return 0;
}
END_OF_MAIN(); //yah, finishin' it up