I am working on a simple 3D shooter. I have simulated a 3D starfield using the 2D dot command. And I have a couple HUD’s. The problem is I cannot seem to get the 3D object drawn in front of the starfield while having it drawn behind the HUD’s. I have tried DRAW TO FRONT, DRAW SPRITE LAST and every combination there of. I have tried making the HUD’s an image or a sprite. I have tried with backdrop on and off. With backdrop off I had to use CREATE BITMAP and draw the starfield to it then copy to the screen. I have tried every combination of these things and the opposite with no luck. If there is some way, any way to pull this off, I would be grateful for your help.
Main Source:
REM ***** Main Source File *****
Gosub Data_Setup
Gosub Enviroment
LoadMedia("Files")
SetupStars()
` main loop
repeat
plrControl()
UpdateStars()
Paste Image 1, 0, 0
Paste Image 2, 0, 24, 1
Text 0, 0, "SCORE:"
Move Object Up 1, 0.5
sync
until escapekey()
` end main loop
end
Rem ***** End Main Source *****
Initialization:
Data_Setup:
` user defined types
Type star
xpos# as float
ypos# as float
zpos# as float
Endtype
` global variables
Dim star() as star
Global numStars as integer
Global starSpeed# as float
Global starSpeedX# as float
Global starSpeedY# as float
Global cx as integer
Global cy as integer
Return
Enviroment:
Sync On
Sync Rate 60
Backdrop On
Color Backdrop 0
Autocam Off
Set Text Font "Computerfont"
Set Text Size 32
Set Text Transparent
Return
Functions:
Function SetupStars()
` Setup stars array
numStars = 1000
starSpeed# = 1.0
cx = screen width()/2
cy = screen height()/2
For starcount = 1 To numStars
array insert at bottom star()
star().xpos# = Rnd(320) - 160
star().ypos# = Rnd(200) - 100
star().zpos# = Rnd(256)
Next
Endfunction
Function LoadMedia(FName as string)
CD FName
if not FontLoaded ("Computerfont")
LoadFont("Computerfont.ttf")
endif
Load Image "hud.jpg", 1, 1
Load Image "shiphud.png", 2, 1
Load Object "attack.x", 1
CD ".."
Position Object 1, 0, -500, 500
Endfunction
Function UpDateStars()
array index to top star()
` Lock buffer
lock pixels
` Output frame
repeat
dec star().zpos#, starSpeed#
inc star().xpos#, starSpeedX#
inc star().ypos#, starSpeedY#
If star().zpos# < 0 Then star().zpos# = 256.0
` y axis movement check
If star().ypos# < -100 Then star().ypos# = 100 + (star().ypos# + 100)
If star().ypos# > 100 Then star().ypos# = -100 + (star().ypos# - 100)
` x axis movement check
If star().xpos# < -160 Then star().xpos# = 160 + (star().xpos# + 160)
If star().xpos# > 160 Then star().xpos# = -160 - (star().xpos# - 160)
` convert to 2d
sx = ((star().xpos# * 256) / star().zpos#) + cx
sy = ((star().ypos# * 256) / star().zpos#) + cy
starcolour = 256-star().zpos#
dot sx, sy, rgb(starcolour, starcolour, starcolour)
next array index star()
until array index valid( star() ) = 0
` unlock buffer
unlock pixels
Endfunction
Function plrControl()
if Joystick Fire D() = 1 and starSpeed# < 5
inc starSpeed#, 0.1
endif
if Joystick Fire C() = 1 and starSpeed# > 1
dec starSpeed#, 0.1
endif
if Joystick Y() < -500 or Joystick Y() > 500
if Joystick Up() = 1
if starSpeedY# > (-starSpeed# - 1) Then dec starSpeedY#, 0.1
endif
if joystick Down() = 1
if starSpeedY# < (starSpeed# + 1) Then inc starSpeedY#, 0.1
endif
else
starSpeedY#=0
endif
if Joystick X() < -500 or Joystick X() > 500
if Joystick Left() = 1
if starSpeedX# < (starSpeed# + 1) Then inc starSpeedX#, 0.1
endif
if Joystick Right() = 1
if starSpeedX# > (-starSpeed# - 1) Then dec starSpeedX#, 0.1
endif
else
starSpeedX# = 0
endif
Endfunction
Function LoadFont(FontFile as string)
Load Dll "gdi32.dll", 1
result = Call Dll(1, "AddFontResourceA", FontFile)
Delete Dll 1
Endfunction result
Function FontLoaded(FontName as string)
local i as integer
FontName = upper$(FontName)
Perform Checklist For Fonts
for i = 1 to Checklist Quantity()
if upper$( Checklist String$(i) ) = FontName then Exitfunction 1
next i
Endfunction 0
Thank you.