Author Topic: 3D in 2D Starfield  (Read 5662 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
3D in 2D Starfield
« on: January 03, 2007 »
This was made using the demo version of Cobra; download information is available in the useful links section of this board,

My first attempt with the language. It's nothing jaw dropping, but gives an idea of the program structure / syntax.

Code: [Select]
///////////////////////////////////
// 3D Starfield With Cobra Demo  //
// In January '07                //
// By Clyde Based on Shockwave's //
// BB Tutorials                  //
///////////////////////////////////
program uses pure2d,keyset

Const XRES=640
Const YRES=480

Const XRES2=320
Const YRES2=240

Const MAXSTARS=1000

Var
    StarX:Array[MAXSTARS] Of Integer
    StarY:Array[MAXSTARS] Of Integer
    StarZ:Array[MAXSTARS] Of Real


Procedure SetupStars()

  Var a

    Begin
       
        For a=0 To MAXSTARS-1
          StarX[ a ]=Rand(-30000,30000)
          StarY[ a ]=Rand(-30000,30000)
          StarZ[ a ]=Rnd(1,30)
        Next
   
    End
//
// End Of Procedure SetupStars()
//


Procedure UpdateStars()
 
  Var TX, TY, a
 
 
  Begin
   
    For a=0 To MAXSTARS-1
       
     
        If Starz[ a ]>1 Then   
   
          TX=( StarX[ a ] / StarZ[ a ])+( XRES2 )
          TY=( StarY[ a ] / StarZ[ a ])+( YRES2 )
       
        EndIf
       
        If (TX>0) And (TX<XRES-1) And (TY>0) And (TY<YRES-1) Then

                PixelFast( TX, TY, $FFFFFF )
           
                StarZ[ a ] = StarZ[ a ] - 0.25
        Else
           
            StarX[ a ]=Rand(-30000,30000)
            StarY[ a ]=Rand(-30000,30000)
            StarZ[ a ]=30
       
        Endif           
       

    Next
   
End
//
// End Of Procedure UpdateStars()
//



Procedure Main()
Begin
 
    OpenScreen( XRES, YRES, 16, TRUE )
 
    SetupStars()


    While Not KeyDown(VK_Escape)
    Cls
   
        UpdateStars()
   
    Flip
    Wend
   
    CloseScreen()
   
End
//
// End Of Procedure Main()
//

Begin
  Main()
End

There's some pretty funky gfx effects in the examples directory too.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Cobra - 3D Starfield
« Reply #1 on: January 03, 2007 »
Looks a little bit like Pascal :) +Karma for posting the first Cobra listing in this board.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Cobra - 3D Starfield
« Reply #2 on: January 03, 2007 »
Hey well done! I'm still trying to get my first function to work o_0. 

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Cobra - 3D Starfield
« Reply #3 on: January 03, 2007 »
Hehe, Cheers Mike_G :)
I've been baffled by what flags to use for fullscreen displays. As it defaults to a window area.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Ghost^BHT

  • Clueless and Happy
  • ^GVY
  • Pentium
  • ******
  • Posts: 931
  • Karma: 49
  • BYTE ME!
    • View Profile
Re: Cobra - 3D Starfield
« Reply #4 on: January 03, 2007 »
the demo version only runs in a window Clyde  :(

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Cobra - 3D Starfield
« Reply #5 on: January 08, 2007 »
nice and neat Coding there  :clap:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Cobra - 3D Starfield
« Reply #6 on: January 08, 2007 »
@Wham: Cheers mate.
@Hotshot: Thanks, basically it's a conversion of Shockwave's Starfield tutorial / code.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: