I've decided to come back to DBPro after 8 years and have a mess around with it, trying to write a game {i won't go into details here} but I've always been the type of person who tries to get the program/routine to work for me.. So here is my dilema..
a simple 1024 by 768 screen, with a .x logo spinning the middle of the screen, mp3 playing and I wanted to anticipate early on possible screen resolutions, so I wrote a function that allows me to pass over things about the line of text I want to display on the menu, pass over the x the y, the string, the font and whether it's center'd on the screen. all I wanted to display was 'Start Game' 'Options' and 'Quit', so I had my game loop
gosub rotatelogo
mylinetext (x,y,"text","arial black",fontsize,r,g,b,r,g,b,centered)
now just the rotatelogo, I get 250+fps, I add one line to display text and it drops down to 128+, with just 4 lines of text I'm getting 15fps.
So, I don't know if I've got my sync, sync rate, etc all that setup wrong, whether functions dont work too well for what I want, whether pulling the 'font' each time is slowing it down..
I'm stumped, just a simple front end, but with reusable code (for within the game) is all I need..
Any tips and/or pointers would be appreciated.
and I'm sorry for the way I lay out mycode, I know it will probably be criticized, but it's my style..
gosub setup_variables
root$ = "F:\The !£$%^& Game\MyGame\"
sync on
rem sync rate 60
rem set window on
set display mode 1024,768,32
rem backdrop on
Rem Load any required media
gosub _load_game
Rem Setup all objects for game
gosub _setup_game
rem Front End
do
gosub _timer_events
gosub _rotate_emblem
rem gosub drawline1
rem gosub drawline2
rem gosub _display_text
rem displaylinetext(0,1,"MyGame The Game","arial black",50,255,0,0,255,0,0,1)
displaylinetext(0,20,"Start Game","arial black",fontsizemax,255,255,255,255,255,255,1)
rem displaylinetext(0,21,"Options","arial black",fontsizemax,255,255,255,255,255,255,1)
rem displaylinetext(0,22,"Quit","arial black",fontsizemax,255,255,255,255,255,255,1)
fps$ = str$(screen fps())
displaylinetext(0,23,"FPS:"+fps$,"arial black",fontsizemax,255,255,255,255,255,255,1)
sync
loop
Rem Game Loop
do
Rem Control game elements
gosub _control_player
gosub _control_surrounding
gosub _control_enemies
Rem update screen
loop
Rem End program
stop music MyGame_tune
show mouse
end
_setup_game:
hide mouse
color backdrop rgb(0,0,0)
make light MyGame_emblem_light
color light MyGame_emblem_light,255,255,255
set light to object position MyGame_emblem_light, MyGame_emblem
randomize timer()
move camera cam_pos
play music MyGame_tune
return
_load_game:
load object root$+"MyGame Emblem\MyGame Emblem.x", MyGame_emblem
load music root$+"MyGame Theme Tune\MyGame - Theme Song.mp3", MyGame_tune
return
_timer_events:
timer_a = timer_a + 1
if timer_a > 2000
timer_a = 0 : timer_b = timer_b + 1 : time_taken = start_time-timer()
endif
if timer_b > 2000
timer_b = 0 : timer_c = timer_c + 1
endif
if timer_c > 2000
timer_c = 0 : timer_d = timer_d + 1
endif
return
_display_text:
ink rgb(255,255,255),rgb(255,255,255)
set text font "arial"
set text size 14
text 10,10,str$(timer_a)
text 10,20,str$(timer_b)
text 10,30,str$(timer_c)
text 10,40,str$(timer_d)
if time_taken <> 0
text 10,50,(str$(time_taken/1000))
endif
return
_rotate_emblem:
Rem rotate the Y axis of the triangle
zROTATE OBJECT MyGame_emblem, OBJECT ANGLE z(MyGame_emblem) + 0.6
yROTATE OBJECT MyGame_emblem, OBJECT ANGLE y(MyGame_emblem) + 1.6
xROTATE OBJECT MyGame_emblem, OBJECT ANGLE x(MyGame_emblem) + 0.2
move camera cam_pos
cam_pos = cam_pos + 0.1
if cam_pos <= -10
cam_pos = -10
endif
return
drawline1:
rem ********************************
rem *line fade above MyGame emblem*
rem ********************************
if timer_a =>400 or timer_b =>1
ink rgb(line_1_fade_red,line_1_fade_green,line_1_fade_blue),rgb (0,0,0)
for lines = 0 to 5
line 0,220+lines,screen width(),220+lines
next lines
line_1_fade_red = line_1_fade_red + 1
if line_1_fade_red >= 255
line_1_fade_red = 255 : lr1 = 1
endif
line_1_fade_green = line_1_fade_green + 1
if line_1_fade_green >= 103
line_1_fade_green = 103 : lg1 = 1
endif
line_1_fade_blue = line_1_fade_blue + 1
if line_1_fade_blue >= 11
line_1_fade_blue = 11 :lb1 = 1
endif
endif
return
drawline2:
rem ********************************
rem *line fade below MyGame emblem*
rem ********************************
if timer_a =>500 or timer_b =>1
ink rgb(line_2_fade_red,line_2_fade_green,line_2_fade_blue),rgb (0,0,0)
for lines = 0 to 5
line 0,520+lines,screen width(),520+lines
next lines
line_2_fade_red = line_2_fade_red + 1
if line_2_fade_red >= 255
line_2_fade_red = 255 : lr2 = 1
endif
line_2_fade_green = line_2_fade_green + 1
if line_2_fade_green >= 103
line_2_fade_green = 103 : lg2 = 1
endif
line_2_fade_blue = line_2_fade_blue + 1
if line_2_fade_blue >= 11
line_2_fade_blue = 11 : lb2 = 1
endif
endif
return
rem **************************
rem * not use below here yet *
rem **************************
_control_player:
return
_control_surrounding:
return
_control_enemies:
return
Function displaylinetext(x,y,string$,font$,fontsize,RF,GF,BF,RB,GB,BB,center)
SET TEXT FONT font$
SET TEXT SIZE fontsize
xscreen = screen width()
yscreen = screen height()
len_of_string = (text width (string$)/2)
ink rgb(RF,GF,BF),rgb(RB,GB,BB)
text_pos_x = x * fontsize
text_pos_y = y * fontsize
center_x_text = (xscreen / 2)
if center = 1
text center_x_text-len_of_string,text_pos_y,string$
else
text text_pos_x,text_pos_y,string$
endif
endfunction
setup_variables:
global font$ as string
global fontsize as integer
global xscreen as integer
global yscreen as integer
global len_of_string as integer
global RF as integer
global GF as integer
global BF as integer
global RB as integer
global GB as integer
global BB as integer
global text_pos_x as integer
global text_pos_y as integer
global center_x_text as integer
global center as integer
global root$ as string
MyGame_emblem = 1
MyGame_tune = 1
MyGame_emblem_light = 1
start_time = timer()
time_taken = 0
cam_pos = -100
timer_a = 0
timer_b = 0
timer_c = 0
timer_d = 0
line_1_fade_red = 0
line_1_fade_green = 0
line_1_fade_blue = 0
line_2_fade_red = 0
line_2_fade_green = 0
line_2_fade_blue = 0
if screen width() = 800 then fontsizemax = 20
if screen width() = 1024 then fontsizemax = 30
if screen width() = 1280 then fontsizemax = 40
return
Don't jump, if you do you will only fall, and hurt yourself