pic movement

This is a discussion on pic movement within the Game Programming forums, part of the General Programming Boards category; hi this code is to get a pic keep moving it's worked in BGI but without pictures now i tried ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    pic movement

    hi

    this code is to get a pic keep moving it's worked in BGI but without pictures now i tried it in allegro and it doesn't show a thing

    can u see what i'm doing wrong or do u know a better way to get the pic move till next keypress?

    Code:
    #include <allegro.h>
    #include <stdlib.h>
    #include<conio_mingw.h>
    
    
    
    
    int main()
    {
    char ror=30;
       quit = 0;
       allegro_init();
       install_keyboard();
    
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       BITMAP *p1 = load_bitmap( "c:\\temp\\pic1.bmp", NULL );
       BITMAP *p2 = load_bitmap( "c:\\temp\\pic2.bmp", NULL );
    
       while ( !quit )
    {
       while(kbhit())
       {
           ror==getch();
    
       }
      switch(ror)
                         {
      case 'a':
    
      ror-- ; draw_sprite( screen, p1, ror, 400 ); break;
    
        case 'd':
    
            ror++; draw_sprite( screen, p2, ror, 400 ); break;
    
        case 'q':  quit = 1; break;
    
                         }
    
    
    }
    
    
       destroy_bitmap(p1);
       destroy_bitmap(p2);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    no one knows this huh

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by pode
    no one knows this huh
    What parameters does drawsprite take? I am only familiar with OpenGL, DirectX and GDI. I have never used allegro or BGI. Tell me what the function takes and I can probably help you.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    i think your gonna need to use a time based "animation", to do this untill another key is hit.
    Last edited by no-one; 08-16-2002 at 03:40 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    here is some fact about draw sprite

    void draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y);

    Draws a copy of the sprite bitmap onto the destination bitmap at the specified position. This is almost the same as blit(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h), but it uses a masked drawing mode where transparent pixels are skipped, so the background image will show through the masked parts of the sprite. Transparent pixels are marked by a zero in 256 color modes or bright pink for truecolor data (maximum red and blue, zero green).




    got any example on a time based animation?

  6. #6
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    What is it you are trying to do? Animation? Or move the sprite around the screen?

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    how bout some pseudo-code?

    Code:
    timer = gettime() + interval; // interval represents the time to wait between drawing
    
    while ( !quit )
    {
    
        if(need_to_move && (timer < gettime()))
        {
            timer = gettime() + interval;
            set move distance, direction, ect;
            draw_sprite();
        }
    
    }
    hopefully this is helpful.

    though i don't know if it will solve the not drawing the sprite problem.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  8. #8
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    If you use allegros timer routines you set a function to be called every so often. The most common way to do it is to have counter_function() called in whatever interval you want, and you have a global variable called counter that is set to 0. The only thing in counter_function() is counter = 1; So you check to see if counter is 1, if it is you execute whatever code and set counter back to 0.

    Code:
    int quit = 0;
    
    while(!quit)
    {
      if(counter)
      {
        // Place input and drawing code here
        parse_input();
        draw_screen();
      }
    
      if(key[KEY_ESC])
        quit = 1;
    }
    I could give a better example if I understood what you are trying to do.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i want my pic to move in the direction the user chooses

    ex. user hits left key - pic moves to lef, and continues to left until
    other direction is chosen then if the user hits up - pic move up etc.
    u get my point

  10. #10
    no-one
    Guest
    this is what the ~code is intended to help you do, by timing the movement in the direction last pressed untill a new direction is pressed.

    if it is not time then the sprites will likely move to fast and be off the screen before you can get a good look at them.

  11. #11
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    If you just want to move one bitmap in the direction the user wants, why are you loading two bitmaps? Check out this code, it is not complete, but should help.

    Code:
    #include <allegro.h>
    
      void redraw();
      void setup();
      void shutdown();
    
      BITMAP *pic;
    
      int picx = 200;
      int picy = 200;
    
    int main()
    {
      int quit = 0;
    
      setup();
    
      while(!key[KEY_ESC])
      {
        if(key[KEY_LEFT])
          picx -= 4;
        if(key[KEY_RIGHT])
          picx += 4;
        if(key[KEY_UP])
          picy -= 4;
        if(key[KEY_DOWN])
          picy += 4;
    
        redraw();
      }
    
      shutdown();
       return 0;
    }
    I did not include redraw(), setup() or shutdown(). Setup will just initialize allegro and load the image, set the video mode. Redraw just redraws the sprite using picx and picy coordinates. Shutdown deletes the bitmap and if you add other stuff it does that.

    Be sure to install_keyboard(), from looking at your code it looks like you do not know how to use it.

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    wow what a timer!

    that code u gave me was just like mine, except for some small changes.

  13. #13
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Don't be an arse, that code may do the same thing that yours is *suppose* to do, but it is not like yours. It is alot cleaner and easier to read. I still don't see why you loaded two bitmaps if you just want to display one and have it move around. Why use getch() when allegro has the built in key array?

    Figure out how to use timers for yourself, I try to help you. BTW, you dont need a timer for something so simple, just change the ammount it increments and decrements the coordinates. Unless you are gonna be sending this to all your 1337 friends.

  14. #14
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    cleaner or whatever

    how would u show a moving bullet for example?
    this way u get my question right?

  15. #15
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    have variables hold the X and Y values of the bullet, and everytime you need to move the bullet, just change the X and Y variables and redraw the bullet.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get pixel values from pic
    By Leite33 in forum Windows Programming
    Replies: 4
    Last Post: 09-12-2006, 01:13 PM
  2. I need movement...
    By Finchie_88 in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2004, 03:10 PM
  3. natural leg movement
    By DavidP in forum Game Programming
    Replies: 32
    Last Post: 01-11-2004, 08:01 AM
  4. New game-Time-based movement?
    By napkin111 in forum Game Programming
    Replies: 6
    Last Post: 01-18-2003, 12:50 AM
  5. PIC Microcontrolers
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-28-2002, 11:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21