Got another problem with my Allegro scrolling shooter

This is a discussion on Got another problem with my Allegro scrolling shooter within the Game Programming forums, part of the General Programming Boards category; I'm trying to get the background to scroll upwards in a smooth way. I was originally trying to get the ...

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    Got another problem with my Allegro scrolling shooter

    I'm trying to get the background to scroll upwards in a smooth way. I was originally trying to get the picture to loop round on itself (once i've got that going, i want to make it so that it can string together different pictures in a sequence to make things more interesting, but thats later). Anyway, I can get it to move the picture forward, although getting the looping to look 'smooth' is proving to be a little harder.

    My idea was to use allegros blit function to put the picture in a buffer, the picture was longer vertically than the screen, and so for the first part, it would just 'print' the bottom section, slowly moving up until the top of the screen got to the top of the picture and then it switchs over and a 2nd part that prints the bottom of the picture to the top portion of the screen and the top portion of the picture to the bottom portion of the screen. then, as one part increases, the other part decreases and at a critical point when whats on the screen becomes the bottom of the picture, it reverts back to the initial part. and so splitting it up into two parts. Thing is, there must be an easier way of doing it than that. its really complicated. lol. How would you guys do it?

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Ok, been thinking. This is what I've got:

    Code:
    k0 = (cgraphics.p_current_background->h - SCREEN_DIMX)/SCROLL_RATE;
                                   
                                   /* Add Background to the screen buffer */
                                   
                                   
                                   if( k <= k0)
                                   {
                                       // Draw Background as normal
                                       blit(cgraphics.p_current_background, cgraphics.p_screen_buffer1, 0, (int)(cgraphics.p_current_background->h - SCREEN_DIMY - (SCROLL_RATE*k)),0,0,
                                                     cgraphics.p_current_background->w, cgraphics.p_current_background->h);
                                   }
                                   
                                   if( k > k0)
                                   {
                                       // Draw bottom 1/2 of picture on top 1/2 of screen
                                       blit(cgraphics.p_current_background, cgraphics.p_screen_buffer1, 0, (int)(cgraphics.p_current_background->h - (SCROLL_RATE*(k-k0))),0,0,
                                                     cgraphics.p_current_background->w, (k-k0)*SCROLL_RATE);
                                       
                                       // Draw top 1/2 of picture on bottom 1/2 of screen
                                       blit(cgraphics.p_current_background, cgraphics.p_screen_buffer1, 0, 0,0,(k-k0)*SCROLL_RATE,
                                                     cgraphics.p_current_background->w, SCREEN_DIMY - ((k-k0)*SCROLL_RATE));
                                       
                                       // Reset k
                                       if( k >= ((2*cgraphics.p_current_background->h/SCROLL_RATE) - k0 ) )
                                       {
                                           k = 0;
                                       }
                                   }
    k0 is basically the 'critical value' for the scrolling stuff, which happens when the scrolling gets to the top of the page. ofcourse, at the end of game refresh part of the code, there is a line like 'k++;' so that the value of k changes. Problem is, it still doesnt give a very smooth 'swap over'.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Why is it not very smooth? Is it too slow, or messing up graphically?

    Anyway, I don't know about Allegro, but the SDL ignores you when you try to blit pixels outside the screen. :P So if you wanted to, you could paint the entire image at the top and at the bottom. I'd still do it the way you have it, though, for efficiency reasons.

    Also:
    Code:
    if( k >= ((2*cgraphics.p_current_background->h/SCROLL_RATE) - k0 ) )
                                       {
                                           k = 0;
                                       }
    Why not just something like this?
    Code:
    k %= MAX_K;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Loading Bitmaps in Allegro
    By LiNeAr in forum Game Programming
    Replies: 1
    Last Post: 08-15-2005, 04:12 PM
  2. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  3. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  4. problem in allegro with sprite leaving trail
    By Leeman_s in forum C++ Programming
    Replies: 18
    Last Post: 09-13-2002, 03:04 PM
  5. Allegro Problem
    By Xterria in forum Game Programming
    Replies: 6
    Last Post: 08-30-2001, 02:32 PM

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