Hi, I just put in this HUD into my game (I'm quite proud of it, actually
). However, even though I put in gosubs, I still have lag problems whenever it appears.
Here's the code:
REM Project: Test4
REM Created: 6/11/2008 12:59:27 PM
REM
REM ***** Main Source File *****
REM
Rem Screen Settings
Sync On: Sync Rate 60
SET WINDOW SIZE 640, 480
rem Global data
global ambience# as integer
global blockobj as integer
dim objtype(10000)
rem Load all images being used
Load Image "OzoneSky.png",10
Load Image "Toa_mate.png",9
`This sets up the variables for the Game Timer
movespeed = 100
turnspeed = 87.5
time=timer()
`Make Object Cube 1, 50
load object "Toa_Mata.x",1
POSITION OBJECT 1, 200, 0, 200
xrotate object 1,270
fix object pivot 1
rotate object 1,0,180,0
SET OBJECT SPEED 1, 30
Texture object 1,9
make object collision box 1,-40,0,-40,40,150,40,0
load object "sky_sphere.x",3
set object light 3,0
scale object 3, 10000,10000,10000
set object cull 3,0
texture object 3,10
load object "worldthing.dbo",2
POSITION OBJECT 2, 0, 0, -3400
MAKE LIGHT 1
make matrix 1,200,200,5,5
Position Matrix 1,200,0,200
rem Setup the character stats
gosub _setup_stats
rem Declares all variables/strings in the HUD
hero1maxhealth#=0.0
hero1maxmagic#=0.0
hero1name$=""
hero1Level=0
hero1health#=0.0
hero1magic#=0.0
hero2maxhealth#=0.0
hero2maxmagic#=0.0
hero2name$=""
hero2Level=0
hero2health#=0.0
hero2magic#=0.0
hero3maxhealth#=0.0
hero3maxmagic#=0.0
hero3name$=""
hero3Level=0
hero3health#=0.0
hero3magic#=0.0
rem set up the HUD
HP$="HP: "
MP$="MP: "
slash$="/"
LV$="Level: "
rem Main Loop
Do
walk=0
gameTime=timer()-time `The time elapsed between the start of the game and the current time
MSframe#=gameTime*(movespeed/1000.0)
TSframe#=gameTime*(turnspeed/1000.0)
gosub _hud_checker
gosub _hud_display
gosub _control_player
rem Track hero with camera
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
a#= 0
d#=120.0
h#=45.0
s#=75.0
set camera to follow x#,y#,z#,a#,d#,h#,s#,1
time=timer()
sync
Loop
rem Main Loop end
end
remstart FUNCTION LukaInParty()
if hero1CharSlot=0
hero1CharSlot=1
else
if hero1CharSlot=1
hero1CharSlot=0
endif
if hero1CharSlot NOT 1
hero1CharSlot=1
endif
endif
ENDFUNCTION remend
_setup_stats:
rem Set up Character Statistics
TYPE charStats
health AS FLOAT
maxhealth AS FLOAT
Name AS STRING
level AS INTEGER
magic AS FLOAT
maxmagic AS FLOAT
experience AS INTEGER
ENDTYPE
DIM characters(6) AS charStats
hero1CharSlot=0`there is no one in the first HUD slot
hero2CharSlot=0
hero3CharSlot=0
rem Give Luka his stats
characters(1).health=100.0
characters(1).maxhealth=100.0
characters(1).Name="Luka"
characters(1).level=10
characters(1).magic=100.0
characters(1).maxmagic=100.0
characters(1).experience=1000
rem Give Kafua his stats
characters(2).health=80.0
characters(2).maxhealth=80.0
characters(2).Name="Kafua"
characters(2).level=1
characters(2).magic=50.0
characters(2).maxmagic=50.0
characters(2).experience=1000
remstart Give Lekori his stats
characters(1).health=100.0
characters(1).maxhealth=100.0
characters(1).Name="Lekori"
characters(1).level=1
characters(1).magic=100.0
characters(1).maxmagic=100.0
characters(1).experience=1000
rem Give Luka his stats
characters(1).health=100.0
characters(1).maxhealth=100.0
characters(1).Name="Luka"
characters(1).level=1
characters(1).magic=100.0
characters(1).maxmagic=100.0
characters(1).experience=1000
rem Give Luka his stats
characters(1).health=100.0
characters(1).maxhealth=100.0
characters(1).Name="Luka"
characters(1).level=1
characters(1).magic=100.0
characters(1).maxmagic=100.0
characters(1).experience=1000
rem Give Luka his stats
characters(1).health=100.0
characters(1).maxhealth=100.0
characters(1).Name="Luka"
characters(1).level=1
characters(1).magic=100.0
characters(1).maxmagic=100.0
characters(1).experience=1000
remend
return
_hud_checker:
rem Check to see if a character is in the HUD
if hero1CharSlot>0
hero1maxhealth#=characters(hero1CharSlot).maxhealth
hero1health#=characters(hero1CharSlot).health
hero1maxmagic#=characters(hero1CharSlot).maxmagic
hero1magic#=characters(hero1CharSlot).magic
hero1name$=characters(hero1CharSlot).Name
hero1Level=characters(hero1CharSlot).level
endif
if hero2CharSlot>0
hero2maxhealth#=characters(hero2CharSlot).maxhealth
hero2health#=characters(hero2CharSlot).health
hero2maxmagic#=characters(hero2CharSlot).maxmagic
hero2magic#=characters(hero2CharSlot).magic
hero2name$=characters(hero2CharSlot).Name
hero2Level=characters(hero2CharSlot).level
endif
if hero3CharSlot>0
hero3maxhealth#=characters(hero3CharSlot).maxhealth
hero3health#=characters(hero3CharSlot).health
hero3maxmagic#=characters(hero3CharSlot).maxmagic
hero3magic#=characters(hero3CharSlot).magic
hero3name$=characters(hero3CharSlot).Name
hero3Level=characters(hero3CharSlot).level
endif
return
_hud_display:
rem The first HUD
if hero1CharSlot>0
rem Show name and level
set cursor 0,0 : print hero1name$
set cursor 0,16 : print LV$+str$(hero1Level)
rem Show health
set cursor 0,32 : print HP$+str$(hero1health#)+slash$+str$(hero1maxhealth#)
if (hero1health#/hero1maxhealth#)<0.3 then rr=255 else rr=0
box 2,48,(hero1health#/hero1maxhealth#)*128,56,rgb(rr,100,100),rgb(rr,100,100),rgb(rr,255,255),rgb(rr,255,255)
rem Show magic points
set cursor 0,60 : print MP$+str$(hero1magic#)+slash$+str$(hero1maxmagic#)
if (hero1magic#/hero1maxmagic#)<0.3
yl=255
bl=0
else
bl=255
yl=0
endif
box 2,76,(hero1magic#/hero1maxmagic#)*128,84,rgb(100,yl,bl),rgb(100,yl,bl),rgb(255,yl,bl),rgb(255,yl,bl)
endif
rem The second HUD
if hero2CharSlot>0
rem Show name and level
set cursor 212,0 : print hero2name$
set cursor 212,16 : print LV$+str$(hero2Level)
rem Show health
set cursor 212,32 : print HP$+str$(hero2health#)+slash$+str$(hero2maxhealth#)
if (hero2health#/hero2maxhealth#)<0.3 then rr=255 else rr=0
box 214,48,(hero2health#/hero2maxhealth#)*340,56,rgb(rr,100,100),rgb(rr,100,100),rgb(rr,255,255),rgb(rr,255,255)
rem Show magic points
set cursor 212,60 : print MP$+str$(hero2magic#)+slash$+str$(hero2maxmagic#)
if (hero2magic#/hero2maxmagic#)<0.3
yl=255
bl=0
else
bl=255
yl=0
endif
box 214,76,(hero2magic#/hero2maxmagic#)*340,84,rgb(100,yl,bl),rgb(100,yl,bl),rgb(255,yl,bl),rgb(255,yl,bl)
endif
rem The third HUD
if hero3CharSlot>0
rem Show name and level
set cursor 424,0 : print hero3name$
set cursor 424,16 : print LV$+str$(hero3Level)
rem Show health
set cursor 424,32 : print HP$+str$(hero3health#)+slash$+str$(hero3maxhealth#)
if (hero3health#/hero3maxhealth#)<0.3 then rr=255 else rr=0
box 426,48,(hero3health#/hero3maxhealth#)*552,56,rgb(rr,100,100),rgb(rr,100,100),rgb(rr,255,255),rgb(rr,255,255)
rem Show magic points
set cursor 424,60 : print MP$+str$(hero3magic#)+slash$+str$(hero3maxmagic#)
if (hero3magic#/hero3maxmagic#)<0.3
yl=255
bl=0
else
bl=255
yl=0
endif
box 426,76,(hero3magic#/hero3maxmagic#)*552,84,rgb(100,yl,bl),rgb(100,yl,bl),rgb(255,yl,bl),rgb(255,yl,bl)
endif
return
_control_player:
If Upkey()=1
yrotate object 1,180
Move Object 1,-MSframe#
walk=1
endif
If Downkey()=1
yrotate object 1,360
Move Object 1,-MSframe#
walk=1
endif
If Leftkey()=1
yrotate object 1,90
Move Object 1,-MSframe#
walk=1
endif
If Rightkey()=1
yrotate object 1,270
Move Object 1,-MSframe#
walk=1
endif
if walk=0 then loop object 1,1,1
if walk=1 then loop object 1,2,17
position object 3,x#,y#,z#
rem add Luka to te HUD
if inkey$()="q"
hero1CharSlot=1
endif
rem add Kafua to te HUD
if inkey$()="k"
hero2CharSlot=2
endif
rem Reduce Health Points
if Spacekey()=1
Dec characters(1).health,1 : if characters(1).health<0 then characters(1).health=0.0
endif
rem Raise Health Points
if inkey$()="a"
Inc characters(1).health,1 : if characters(1).health>characters(1).maxhealth then characters(1).health=characters(1).maxhealth
endif
return
Here's the actual game itself if that'll help you more. Thanks!
a total noob.