Author Topic: 3D Horizon[BB2D]  (Read 3709 times)

0 Members and 1 Guest are viewing this topic.

Offline Nightfly

  • ZX 81
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
3D Horizon[BB2D]
« 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:
« Last Edit: July 21, 2007 by Shockwave »

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D Horizon
« Reply #1 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
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17427
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: 3D Horizon
« Reply #2 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 :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Horizon[BB2D]
« Reply #3 on: June 16, 2008 »
How did you get on with this Nightfly dude?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D Horizon[BB2D]
« Reply #4 on: June 17, 2008 »
Who knows?  That was his first and last post nearly a year ago!

Jim
Challenge Trophies Won: