Code:
#include <allegro.h>
#include <string>
void myAllegroSetup()
{
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 600, 400, 0, 0);
}
void displayIntro()
{
BITMAP *introImage;
introImage = load_bitmap("bg/open.bmp",NULL);
stretch_blit(introImage, screen, 0, 0, introImage->w, introImage->h, 0, 0, 600, 400); // Draws the stretched image onto the screen
textout_ex(screen, font, "Press any key to continue", 380, 380, makecol(255, 255, 255), -1);
readkey();
stretch_blit(introImage, screen, 0, 0, introImage->w, introImage->h, 0, 0, 600, 400); // Draws the stretched image onto the screen
textout_ex(screen, font, "How to play", 400, 220, makecol(255, 255, 255), -1);
textout_ex(screen, font, "___________", 400, 223, makecol(255, 255, 255), -1);
textout_ex(screen, font, " z = Talk/Action", 300, 247, makecol(255, 255, 255), -1);
textout_ex(screen, font, " x = Cancel", 300, 257, makecol(255, 255, 255), -1);
textout_ex(screen, font, "Arrow Keys = Move/Navigate Menus'", 300, 267, makecol(255, 255, 255), -1);
textout_ex(screen, font, "Press any key to continue", 380, 380, makecol(255, 255, 255), -1);
readkey();
}
void movePlayer(){
int playerX;
int playerY;
int abc;
BITMAP *walk_left = load_bitmap( "sprite/walk_left.bmp", NULL);
BITMAP *walk_right = load_bitmap( "sprite/walk_right.bmp", NULL);
BITMAP *walk_up = load_bitmap( "sprite/walk_up.bmp", NULL);
BITMAP *walk_down = load_bitmap( "sprite/walk_down.bmp", NULL);
BITMAP *walk_none = load_bitmap( "sprite/walk_none.bmp", NULL);
while(!key[KEY_ESC]) {
if( key[KEY_LEFT]){
playerX - 20;
draw_sprite( screen, walk_left, playerX, playerY);
} else if( key[KEY_RIGHT]){
playerX + 20;
draw_sprite( screen, walk_right, playerX, playerY);
} else if( key[KEY_UP]){
playerY + 20;
draw_sprite( screen, walk_up, playerX, playerY);
} else if( key[KEY_DOWN]){
playerY - 20;
draw_sprite( screen, walk_down, playerX, playerY);
}
else draw_sprite( screen, walk_none, playerX, playerY);
}
}
int main(){
myAllegroSetup();
displayIntro();
rectfill( screen, 0, 0, 600, 400, makecol( 0, 0, 0)); // Temporary background
movePlayer();
return 0;
}
END_OF_MAIN();
I know I need to say where playerX and playerY should go but I cant include this in the function as it is repeated, So where would I declare them?