WOOT Finally Feels like I did something...
Posted: Sun May 03, 2009 7:44 pm
I finally installed Allegro correctly and used classes with it. Now is this a right way to use it?
BTW its from an online tutorial, I just made it with classes
Allegro is easier than I thought
main.cpp
Code: Select all
#include "MainGame.h"
int main(){
GameLoop GL;
GL.MainGame(10, 10);
return 0;
}
END_OF_MAIN();
Code: Select all
#ifndef MainGame_h
#define MainGame_h
#include <allegro.h>
class GameLoop
{
public:
void MainGame(int x, int y);
};
#endif
MainGame.cpp
Code: Select all
#include "MainGame.h"
void GameLoop::MainGame(int x, int y, int yy, int xx)
{
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
while ( !key[KEY_ESC] ){
clear_keybuf();
acquire_screen();
clear_to_color( screen, makecol( 255, 0, 255));
textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 255, 0, 255) );
if (key[KEY_UP]) y = y - 3;
else if (key[KEY_DOWN]) y = y + 3;
else if (key[KEY_RIGHT]) x = x + 3;
else if (key[KEY_LEFT]) x = x - 3;
if (key[KEY_W]) yy = yy - 3;
else if (key[KEY_S]) yy = yy + 3;
else if (key[KEY_D]) xx = xx + 3;
else if (key[KEY_A]) xx = xx - 3;
textout_ex( screen, font, "LOL THIS ROCKS", x, y, makecol( 255, 255, 255), makecol( 255, 0, 255) );
textout_ex( screen, font, ":D", xx, yy, makecol( 255, 255, 255), makecol( 255, 0, 255) );
release_screen();
rest(50);
}
}