1 Replies - 1145 Views - Last Post: 18 August 2011 - 11:20 PM Rate Topic: -----

#1 black_yurizan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 18-June 11

Moving sprites in Allegro?

Posted 18 August 2011 - 05:44 PM

Ok, I already know how to move sprites in allegro;however, I still need help in something with allegro. You see, whenever I use the x and y coordinates for the draw_sprite function I have to declare x and y. In addition, I also have to initialize them to zero. When I seen this on a video, the guy who was doing the programming never had to initialize it neither did he write it beforehand. So my question is there a reason why I have to initialize them while he doesn't? ? Were both using the same programs(dev c++), so I don't think there's anything different with my program.

#include<iostream>
#include<allegro.h>

int main()
{ int x = 0, y = 0;
    
    allegro_init();
install_keyboard();
 set_color_depth(32);
 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800,600,0,0);
 BITMAP *bmp = create_bitmap(800,600);
 clear_bitmap (bmp);
 BITMAP *character = load_bitmap("mario.bmp",NULL); //loads the mario picture
set_window_title("Game"); //puts the title on the screen

 while(!key[KEY_ESC]) // The program still runs until I press the escape key
{

if (key [KEY_LEFT]) -- x;
if (key [KEY_RIGHT]) ++ x ;
if (key [KEY_UP]) -- y ;
if (key [KEY_DOWN]) ++ y ;
draw_sprite (bmp, character, x, y); //I think this allows the picture to move freely on the bmp

blit(bmp, screen, 0, 0, 0,0 ,bmp->w, bmp->h); //loads the bitmap on the screen

  
 
 } 
 
 destroy_bitmap(bmp);
 destroy_bitmap(character);
 
 
 readkey();
 return 0;
}
END_OF_MAIN ()




Is This A Good Question/Topic? 0
  • +

Replies To: Moving sprites in Allegro?

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Moving sprites in Allegro?

Posted 18 August 2011 - 11:20 PM

You haven't copied the code correctly. If x and y are not declared in main, they must be elsewhere.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1