![]() |
|
Defining Game World and Creating Expansive Background |
Andynonomous
Member #12,867
May 2011
|
Hi all, Just getting back into programming and C++ for the first time in years. Never used allegro but so far I love it. Learning a lot. So I'm trying to make a game based within a physically modeled solar system. I've got the orbital mechanics down and have been drawing my planets as primitive circles, but I'm ready to graduate to bitmaps I think. I can't find a simple example for loading a bitmap image from a file. Am i right to assume that I create an ALLEGRO_BITMAP *someBitmap and then say Appreciate any clear and simple advice guys, like I said I'm pretty much brand new at this. Thanks! |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Andynonomous said:
Am i right to assume that I create an ALLEGRO_BITMAP *someBitmap and then say Yes, see the Allegro 5 manual. You'll need to initialize the image addon before you can load bitmaps though. Use al_init_image_addon to do this. Andynonomous said: Also, I want to define a world which will be about 12000 by 9000 pixels in dimension, and I want to create a background which will span the whole area.. what's the best way to go about that? Well, with Allegro 5 you're going to have some trouble doing that. You can either load the whole thing as a memory bitmap, which will be really slow to draw, or you can turn it into a grid of video bitmaps and then draw the appropriate sectors as you need them, which is annoying. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Walker
Member #210
April 2000
![]() |
or use a tile map engine... Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Andynonomous
Member #12,867
May 2011
|
Ok, so I dont want to use another engine as im trying to learn allegro from the bottom up before moving on to other things. I have loading and displaying bitmaps working now so im thinking i'll have to use some method like tiling bitmaps for my background. |
Audric
Member #907
January 2001
|
The tiling texture idea is a solid system. for (y=-(camera_y%texture_height); y<screen_height; y+=texture_height) for (x=-(camera_x%texture_width); x<screen_width; x+=texture_width) // draw bitmap at screen coordinates x,y
camera_x, camera_y is the coordinates (in game world) of the top left pixel shown on screen. |
Andynonomous
Member #12,867
May 2011
|
Thanks guys. Thats a great example, any links or documents that expand on that kind of thing would be great. I see whats going on but I'm not sure why it works. Also I know that y-= means |
Audric
Member #907
January 2001
|
- is simply the "make negative" unary operator foo = -bar; // Equivalent to foo = 0-bar;
I'll explain for the X axis, the logic is the same on the Y axis: If the texture has a width of 256 pixels for example, the formula that I listed will always give a starting X that is from -255 included to 0 included. |
Andynonomous
Member #12,867
May 2011
|
Thanks! This has been unbelievably helpful. I've got a scrolling star background now. Though its obvious looking at it that I'm only using one tile. This should still work if I have an array of tiles and a map structure to keep track of how the tiles are distributed in the world right? I just find out which tiles to draw based on where the viewscreen is on the world grid? The one other thing is that I seem to be having a slight problem where i see a line moving vertically up along the screen whenever there's movement. I thought allegro automatically waited for vertical re-synch so Im not sure if thats the problem. |
Audric
Member #907
January 2001
|
Andynonomous said: This should still work if I have an array of tiles and a map structure to keep track of how the tiles are distributed in the world right? I just find out which tiles to draw based on where the viewscreen is on the world grid?
Exactly |
Neil Roy
Member #2,229
April 2002
![]() |
Andynonomous said: Also, I want to define a world which will be about 12000 by 9000 pixels in dimension, and I want to create a background which will span the whole area.. what's the best way to go about that? Your universe can be really large, but the background doesn't need to be that size. The best way would be to have a black background, then have individual images like planets, galaxies, stars etc... loaded in as the player moves. You could store the positions of the planets for example then display them if they move into the player's view. You could store the center position of an image, then check if it's boundries (checking width and height) fall inside the players view then blitting it to screen as needed. In this way you could have your universe just about as large as you could imagine. Another method would be to tile space. If your individual tiles were say 64x64 pixels in size, your map array would be roughly 188 x 140 (or 12032 x 8960 pixels). For images larger than 64x64 you just divide them up into 64x64 chunks and display them that way. Or make the tile sizes larger of course. This could also make detecting where you are simple enough, if certain map locations contain a planet, than if your ship flies into tile location, you land on it (or collide). Edit: For images larger than 64x64, say a 128x128 image, you could mark the four map locations that would hold this image as containing it, then draw the upper left corner of the image in the upper left corner of the first map position (no dividing of images). Good luck with your game. --- |
Andynonomous
Member #12,867
May 2011
|
Thanks once again. I cant believe the progress I've been making. Years ago this seemed really hard, but I'm on a bit of a roll. What I do now is create an array of 4 128 by 128 bitmaps (maybe more later) and 4 more temporary bitmaps. I load images that I've found of individual stars into the temp bitmaps, then I draw a number of them on each bitmap in the array with a random distribution and a random scale (2, 4, 6, or 8 pixels). Once the array has 4 unique starfield images, I create a map of 40 by 40 tiles and randomly assign my tiles to fill it. That makes 5120 ^ 2 pixels in my world. It creates a totally unique background every time! And the scrolling is working great except for that vertical line moving across the screen. Its minor.. im hoping I can fix it.. or its just my monitor. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Try changing the settings in your graphics driver to either 'use vsync' or 'use application vsync setting'. If that doesn't work, then use al_set_new_display_option(ALLEGRO_VSYNC , 1 , ALLEGRO_SUGGEST); and see if that works. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Andynonomous
Member #12,867
May 2011
|
Awesome.. Inserting the new display option seems to have fixed things. I now have an even better solution than I was looking for. I have a randomly generated background that I can scroll around in smoothly. I much appreciate all the help. I'll probably be posting more questions in the near future. Peace! |
|