WOOT Finally Feels like I did something...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

WOOT Finally Feels like I did something...

Post by davidthefat »

:lol: :lol: :lol:

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 :lol: :mrgreen:


main.cpp

Code: Select all

#include "MainGame.h"




int main(){
 

    GameLoop GL;
    GL.MainGame(10, 10);
 
    
    return 0;
    
}   
END_OF_MAIN(); 


MainGame.h

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);

    }   
}

Ewan
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 62
Joined: Mon Mar 23, 2009 11:46 am

Re: WOOT Finally Feels like I did something...

Post by Ewan »

Looks good to me, and congrats! I think for me just getting Allegro working was one the most satisfying things I've done with it :P

Oh by the way, if you get problems when alt-tabbing out of your Allegro game, put this after allegro_init():

Code: Select all

set_display_switch_mode(SWITCH_BACKAMNESIA);
Simple, but not knowing about it has caused me a lot of problems.

Good luck!
They pull out the truncheon, that's when the trouble starts.

'Cause when you've got a badge, the laws don't apply.
Post Reply