"Wrapping" levels
The game Im working on is similiar in look/feel to Defender: You fly a ship around a level (in either direction) and when you get to the "end" of the level, it seemlessly ties in with the beginning of the level. So if you werent paying attention to the repeating sceneray it would seem to go on for ever.
Right now Im still planning out the game code. I hacked together a quick demostration of the ship flying around an empty level. To make the background repeat itself, I said (effictively) "if the background doesnt completely cover the screen, draw a it a second time, but this time at cordinates X,Y so that it perfectly connects to the first one". and "if the background offset gets to its own length, set its offset back to 0". That worked good. The background is 1600x800 (thus, things in the world will have X,Y cordinates 0-1600,0-800)
Next I wanted to add some more sprites just to see how the engine would handle them. I took an image of a helicopter, and wrote some code to display X number of them throughout the level. I gave them each cordinates of 0-1600,0-800. That worked good... except for when I had to start drawing the background a second time (because the first one didnt cover the whole screen). Obviosuly now Im not drawing the hellocopters a second time, so I dont see them.
What Im worried is when I really code the game and have a long list of many different objects to draw. I cant think of an elequant way to do this... any suggestions?
thanks,
Ratman
---------------
http://ratfest.org
You need to render every helicopter (thats on the visible screen) every time you update the screen, as well as the player.
Edited by - Magmai Kai Holmlor on September 26, 2000 11:36:39 PM
Edited by - Magmai Kai Holmlor on September 26, 2000 11:37:08 PM
//RenderFrame()//clear screen, or primary buffer//Draw background//Add looped-around background//Draw Playerfor(i=0;i<numhelis;i++)//draw heli[ i]
Edited by - Magmai Kai Holmlor on September 26, 2000 11:36:39 PM
Edited by - Magmai Kai Holmlor on September 26, 2000 11:37:08 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
err yeah... Ive got that, thats pretty basic stuff.
Its the getting everything thats visible on the screen. Like.. heres an example.
--------[======]-------|
---off--[-visible--]--off--|
--scr--[--screen--]-screen|
--------[----------]-------|
--------[======]-------|
Thats I can do. This is the problem:
----------------[======]
-----off-------[-vis--*-empty-]
---scr--------[-scr--*-------]
---------------[------*-------]
---------------[======]
That * represents where the background image ends. But I want to tie the end of that, with the begining. So I wrote code to figure out when this was happening, and it drew the background a 2nd time where the stars out. So it tied together. I wrote some more code to "reset" the first background if it ever runs completely off the screen. So that works.
Its, when the player's X cordinate is at, say, 1500, I need to also draw objects that are at X cordinate 10, because that part of the level is now on the screen also. I can sorta see this leading to some headaches later on. Does anyone done this before or can think of a clean way to do so?
If I do what Magmai Kai Holmlor says, I'll draw that heli at X cord 10, but it wont show up on the screen, because the "real" cordinate 10 is far off the screen to the left. I need a clean way to get my program to realize that X cord 10 is now on the screen.
---------------
http://ratfest.org
Edited by - ratman on September 26, 2000 12:13:52 AM
Edited by - Ratman on September 26, 2000 12:16:27 AM
Edited by - Ratman on September 26, 2000 12:17:26 AM
Edited by - Ratman on September 26, 2000 12:18:19 AM
Edited by - Ratman on September 26, 2000 12:18:56 AM
Its the getting everything thats visible on the screen. Like.. heres an example.
--------[======]-------|
---off--[-visible--]--off--|
--scr--[--screen--]-screen|
--------[----------]-------|
--------[======]-------|
Thats I can do. This is the problem:
----------------[======]
-----off-------[-vis--*-empty-]
---scr--------[-scr--*-------]
---------------[------*-------]
---------------[======]
That * represents where the background image ends. But I want to tie the end of that, with the begining. So I wrote code to figure out when this was happening, and it drew the background a 2nd time where the stars out. So it tied together. I wrote some more code to "reset" the first background if it ever runs completely off the screen. So that works.
Its, when the player's X cordinate is at, say, 1500, I need to also draw objects that are at X cordinate 10, because that part of the level is now on the screen also. I can sorta see this leading to some headaches later on. Does anyone done this before or can think of a clean way to do so?
If I do what Magmai Kai Holmlor says, I'll draw that heli at X cord 10, but it wont show up on the screen, because the "real" cordinate 10 is far off the screen to the left. I need a clean way to get my program to realize that X cord 10 is now on the screen.
---------------
http://ratfest.org
Edited by - ratman on September 26, 2000 12:13:52 AM
Edited by - Ratman on September 26, 2000 12:16:27 AM
Edited by - Ratman on September 26, 2000 12:17:26 AM
Edited by - Ratman on September 26, 2000 12:18:19 AM
Edited by - Ratman on September 26, 2000 12:18:56 AM
I am not exactly a pro at this sort of thing, but here is my idea. Maybe you should try wrapping the level before the edge actually gets on the screen. That way, when it wraps, the objects that need to be rendered are already there. I can see a problem with objects near you when you wrap (they would dissappear) but I think that would be easier to fix than your other problem. One other solution I came up with that I plan to implement in my new game is that the coordinates are all relative to the player, and the background position is related to the players speed. Essentially the player is always at (0,0) and the rest of the things move instead of the player. Then you only need to worry about making sure NPCs don''t fly off into nothingness.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
Visit the ROAD Programming Website for more programming help.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
I''d seperate the screen coordinate system from the world coordinate system. Right now, you''re talking about both of them like they are the same.
Maybe I am missing something here, but why not just draw the background, then draw everything on top?
You can loop through your lists of "drawable" elements (helicopters, people, bullets, powerups) and find ones that are within the drawing range and then blit them over the top of the backgrounds.
You can loop through your lists of "drawable" elements (helicopters, people, bullets, powerups) and find ones that are within the drawing range and then blit them over the top of the backgrounds.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement