🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How do you create a side scrolling game?

Started by
14 comments, last by C++ Freak 24 years, 6 months ago
Sorry, I''m not real good with the blitter. I haven''t really used it just read about it. So could you help me out and save me the trouble of spending 3 days trying to iron out all my errors could you help me out and tell me what I''ve done wrong?

int xtoblitfrom=1200;
int ytoblitfrom=1200;
// did you mean this to be the size of the bitmap?
int sizeofview=//what goes here?
int y=10;
//how many (pixels?) it will move up\down
int x=10;
// how many (pixels) it will move left\right

RECT source_rect, dest_rect;
source_rect.left = xtoblitfrom;source_rect.top =ytoblitfrom;
source_rect.right=x+sizeofview;source_rect.bottom=y+sizeofview;

dest_rect.left=\\what would go here?
dest_rect.top= \\what would go here?
dest_rect.right= \\what would go here?
dest_rect.bottom= \\what would go here?
lpddsprimary->Blt(or do I need Bltfast?)(&dest_rect, lpddsback, &source_rect, DDBLT_WAIT, NULL);

As you can see I''m a newbie at using the blitter. Thanks for the help. If you could show me where I could find a blitting tutorial that would also help a lot. I want to write my own game engine and knowing how to use the blitter will be very helpful.

Thanks A Lot
Visit http://members.xoom.com/ivanickgames
Advertisement
Ok ill elaborate a bit more. The xtoblitfrom is like what x postion of your bitmap to blit from. A example
say your screen resolution is 640x480 ok? Now you have say a 2000x2000 bitmap for a level of something. Now if you wanted to start showing the bitmap from the top left (0,0) your ytoblitfrom and xtoblitfrom would be 0 and 0.The sizeofview is how much of the bitmap you want to show on the screen.Like if you want the whole screen to be filled with your bitmap ,and you were in 640x480 it would be 640 and 480.

A example of the above.

int drawbitmap(int xtoblitfrom, int ytoblitfrom LDIRECTDRAWSURFACE *bitmap){
RECT source_rect;
source_rect.left = xtoblitfrom;
source_rect.top = ytoblitfrom;
source_rect.right=xtoblitfrom+640;
source_rect.bottom=ytoblitfrom+480;
RECT source_rect2;
source_rect2.left = 0;
source_rect2.top = 0;
source_rect2.right = 480;
source_rect2.bottom = 640;
lpddsback->Blt(&source_rect,bitmap,&source_rect2,DDBLT_WAIT ,NULL);}

This function would draw the surface passed to it(the surface holding your large bitmap.),and draw it to backbuffer. You would then just use the flip command to flip it to the screen. The parameters for the function above are from what spot on the bitmap to blit from. Example:
drawbitmap(400,0,&level);
Would draw the bitmap contained in the surface called level from 400,0. To have the view move down you would just increase the toblitfromy.

I hope this helps somemore if not email me and ill write up a example and send it to you. As far as tutorials on blitting go i really don't know of any.



Edited by - Zenroth on 1/6/00 7:44:22 PM
Actully i just remembered a site that did help me some when i was starting out with directdraw.

http://www.geocities.com/SiliconValley/Way/5233/index.htm

It has alot of directdraw info(mostly from ddutil.cpp),but includes stuff like a scrolling backround,sprites,ect.



Thanks a lot, I finally get it.
Visit http://members.xoom.com/ivanickgames
Here it is. The finished product. Mostly thanks to Zeneroth. Feel free to use it in any of your games. I set it up to be used with the BOB game engine. It took me about two minutes to make after I found out how to do it. I just went and edited the Draw_BOB function because I knew that function used the blitter correctly and could display BOBs. I replaced most of the code with the code Zeneroth gave me. With this new code I created a function that scrolls and displays a BOB at the same time.(pretty nifty eh).

Here it is:

int Scroll_BOB2(BOB_PTR bob, // bob to draw
LPDIRECTDRAWSURFACE dest) // surface to draw the bob on
{
// draw a bob at the x,y defined in the BOB
// on the destination surface defined in dest

RECT dest_rect, // the destination rectangle
source_rect; // the source rectangle

// is this a valid bob
if (!bob)
return(0);

// is bob visible
if (!(bob->attr & BOB_ATTR_VISIBLE))
return(1);

// fill in the destination rect
dest_rect.left = 0;
dest_rect.top = 0;
dest_rect.right = 640;
dest_rect.bottom = 480;

// fill in the source rect
source_rect.left = xtoblitfrom;
source_rect.top = ytoblitfrom;
source_rect.right = xtoblitfrom+640;
source_rect.bottom = ytoblitfrom+480;

// blt to destination surface
if (dest->Blt(&dest_rect, bob->images[bob->curr_frame],
&source_rect,(DDBLT_WAIT / DDBLT_KEYSRC),
NULL)!=DD_OK)
return(0);
// return success
return(1);
} // end Scroll_BOB


Instead of having the function take xtoblitfrom and ytoblitfrom as parameters you make them globals. So then its easy to scroll.

//if player presses right key
{
xtoblitfrom=xtoblitfrom+15
}
//do other if statements

Scroll_BOB2(&Background, lpddsback);

Note(1) You need the BOB game engine for this code to work
Note(2) You must follow all the steps needed to create a BOB before you use this function

Edited by - C++ Freak on 1/8/00 5:08:00 PM
Visit http://members.xoom.com/ivanickgames
Just got back from the weekend. Glad I could be of help

This topic is closed to new replies.

Advertisement