Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Blitz => Topic started by: Nightfly on July 04, 2007

Title: 3D Horizon[BB2D]
Post by: Nightfly on July 04, 2007
Hi, I am looking for some example code that shows how to create a 3D scrolling horizon in 2D, as seen in such games as Space Harrier. I am also in need of code that would scale an object properly as it comes closer to the player. Here is what I have so far:

Code: [Select]
Graphics 320, 240, 16, 2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Color 0, 255, 0

tmpZ = 0
Repeat

tmpZ2 = 1
For y = 120 To 320
Line 0, y + tmpZ2, 320, y + tmpZ2
tmpZ2 = tmpZ2 + (tmpZ2 * .8)
Next

Color 0, 0, 0
Rect 180, 90, 25, 55, 1
Color 0, 255, 0
Rect 181, 91, 23, 53, 0

Flip: Cls
Until KeyDown(1)

now I just need help making it move forward when the user holds up. Thank you  :carrot:
Title: Re: 3D Horizon
Post by: Jim on July 04, 2007
What people usually do is pretend the object is in 3d, so it has a screen position (x and y) and a 'z' position, where the z is the distance away from the viewer.  Then one simple way to make the thing look smaller as it is further away is to divide x and y by z, and scale it to fit the screen, so

screenx = scale * x / z
screeny = scale * y / z

Jim
Title: Re: 3D Horizon
Post by: Shockwave on July 04, 2007
Welcome to the board Nightfly. :welcome:
Learning something like a 3D starfield would establish the principles that Jim has talked about.

Shout if you need help :)
Title: Re: 3D Horizon[BB2D]
Post by: Clyde on June 16, 2008
How did you get on with this Nightfly dude?
Title: Re: 3D Horizon[BB2D]
Post by: Jim on June 17, 2008
Who knows?  That was his first and last post nearly a year ago!

Jim