This is my first 20 line challenge and, as the subject title suggests, has been inspired by games such as Driver.
The object of the game is to drive around the city and collect all of the spinning yellow cubes in the fastest possible time. You do not have to collect the cubes in any order and there is no fixed route through the city. The timer will start once you have collected the first cube.
Controls:
Up arrow to accelerate
Down arrow to brake
Left / right arrows to turn
Spacebar to boost (makes you go faster)
When you have collected all the cubes, you will still have full control of the car and you can press the return key to reset the cubes and timer, the car will not return to its original position but there is a green cone that marks the start point if you want to go back to it.
This was written in DBC and although the DBC code will run in DBP there was an issue with camera view (it looked as if the camera was too close to the car) so I have created a DBP version which has a few of the initial parameters changed to better suit the camera.
DBC version:
sync on : sync rate 65 : hide mouse : autocam off : randomize timer() : cls : accl# = 0.2 : brak# = 0.2 : turn# = 2.0 : max_spd# = 3.3 : cam_ran = 16 : cam_hgt = 10 : cam_tip = 10 : fric# = 0.1 : f_time# = 999.9 : o_time# = f_time# : scr = 0
sw = screen width() : sh = screen height() : do : read w,d, x,z : if w = 0 : exit : endif : inc ob : h = 2*(rnd(100)+50) : make object box ob, w,h,d : color object ob, rgb(100,h,100) : ghost object on ob : position object ob, x,h/2,z : loop
n_blk = ob : do : read x,z : if x = 0 : exit : endif : inc ob : inc m_scr : make object cube ob, 10 : color object ob, rgb(255,255,100) : xrotate object ob, 45 : zrotate object ob, 45 : fix object pivot ob : position object ob, x,5,z : loop
read xp#,zp#,face# : inc ob : make object cone ob, 100 : set object collision off ob : color object ob, rgb(50,255,50) : position object ob, xp#,50,zp# : inc ob : make object box ob,7,2,10 : position object ob, xp#,1,zp# : do
o_xp# = object position x(ob) : o_zp# = object position z(ob) : o_face# = face# : if upkey() = 1 : spd# = spd# + accl# : endif : for i = n_blk + 1 to ob - 1 : turn object left i,2 : next i : if downkey() = 1 : spd# = spd# - brak#
bst# = 0.0 : endif : if leftkey() = 1 : face# = wrapvalue(face# - turn#) : endif : if rightkey() = 1 : face# = wrapvalue(face# + turn#) : endif : if spacekey() = 1 : bst# = bst# + 0.5 : endif : spd# = spd# + bst# - fric# : bst# = bst# - fric#
bnc# = bnc# - 0.5 : if spd# <= 0.0 : spd# = 0.0 : endif : if spd# > max_spd#+bst# : spd# = max_spd#+bst# : endif : if bst# > 5.0 : bst# = 5.0 : endif : if bst# <= 0.0 : bst# = 0.0 : endif : if bnc# <= 0.0 : bnc# = 0.0 : endif
move object ob, spd# - bnc# : yrotate object ob, face# : set camera to follow object position x(ob), cam_hgt, object position z(ob), face#, cam_ran, cam_hgt, 5, 0 : xrotate camera cam_tip : ob_num = object collision(ob,0)
if ob_num > 0 and ob_num =< n_blk : bnc# = spd#*1.5 : spd# = 0.0 : position object ob, o_xp#, 1, o_zp# : face# = o_face# : endif : if ob_num > n_blk : inc scr : hide object ob_num
set object collision off ob_num : if scr = 1 : start_time# = timer() : endif : endif : if scr > 0 and scr < m_scr : time# = (timer() - start_time#)/1000.0 : endif : if scr = m_scr : if time# < f_time#
nft = 1 : f_time# = time# : endif : if returnkey() = 1 : nft = 0 : for i = n_blk + 1 to ob - 2 : show object i : set object collision on i : scr = 0 : time# = 0.0 : next i : endif : endif : set cursor 0,0
print "arrows keys to move, spacebar to boost" : print : print "CURRENT TIME : ", time# : print "FASTERT TIME : ", f_time# : print "CUBES COLLECTED : ", scr , " OF ", m_scr
if scr = m_scr : if nft = 0 : center text sw/2, sh/2-75, "FINISHED" : else : center text sw/2, sh/2-75, "!! NEW FASTEST TIME !!" : endif : center text sw/2, sh/2-50, "PRESS ENTER TO RESET CUBES" : endif : sync : loop
data 100,300,250,150, 100,300,450,150, 100,100,650,250, 100,300,850,350, 100,200,1050,300, 100,180,1250,290, 80,80,1360,340, 220,100,210,450
data 160,100,420,450, 100,100,650,450, 100,100,1250,450, 180,100,1410,450, 100,200,1050,600, 340,100,170,650, 140,100,430,650, 100,100,650,650
data 100,180,850,690, 200,100,1220,650, 260,100,1470,650, 200,100,200,850, 300,300,550,950, 100,100,850,850, 140,100,1070,850, 180,100,1250,850
data 140,100,1430,850, 100,100,50,1050, 100,100,250,1050, 100,140,850,1070, 100,160,1050,1080, 100,100,1250,1050, 100,300,1450,1150, 100,140,850,1230
data 100,120,1050,1240, 100,300,150,1350, 200,100,400,1250, 100,160,650,1280, 100,100,1250,1250, 200,100,400,1450, 100,320,650,1540, 100,200,850,1500
data 300,100,1150,1450, 200,100,400,1650, 100,100,1050,1650, 0,0,0,0, 350,250, 350,650, 350,950, 350,1350, 850,1350, 1350,1250, 1050,1170, 850,950
data 950,550, 1310,390, 0,0, 350.0,-200.0,0.0
DBP version:
sync on : sync rate 60 : hide mouse : autocam off : randomize timer() : cls : accl# = 0.2 : brak# = 0.2 : turn# = 2.0 : max_spd# = 3.0 : cam_ran = 30 : cam_hgt = 10 : cam_tip = 10 : fric# = 0.1 : f_time# = 999.9 : o_time# = f_time# : scr = 0
sw = screen width() : sh = screen height() : do : read w,d, x,z : if w = 0 : exit : endif : inc ob : h = 2*(rnd(100)+50) : make object box ob, w,h,d : color object ob, rgb(100,h,100) : ghost object on ob : position object ob, x,h/2,z : loop
n_blk = ob : do : read x,z : if x = 0 : exit : endif : inc ob : inc m_scr : make object cube ob, 10 : color object ob, rgb(255,255,100) : xrotate object ob, 45 : zrotate object ob, 45 : fix object pivot ob : position object ob, x,5,z : loop
read xp#,zp#,face# : inc ob : make object cone ob, 100 : set object collision off ob : color object ob, rgb(50,255,50) : position object ob, xp#,50,zp# : inc ob : make object box ob,7,2,10 : position object ob, xp#,1,zp# : do
o_xp# = object position x(ob) : o_zp# = object position z(ob) : o_face# = face# : if upkey() = 1 : spd# = spd# + accl# : endif : for i = n_blk + 1 to ob - 1 : turn object left i,2 : next i : if downkey() = 1 : spd# = spd# - brak#
bst# = 0.0 : endif : if leftkey() = 1 : face# = wrapvalue(face# - turn#) : endif : if rightkey() = 1 : face# = wrapvalue(face# + turn#) : endif : if spacekey() = 1 : bst# = bst# + 0.5 : endif : spd# = spd# + bst# - fric# : bst# = bst# - fric#
bnc# = bnc# - 0.5 : if spd# <= 0.0 : spd# = 0.0 : endif : if spd# > max_spd#+bst# : spd# = max_spd#+bst# : endif : if bst# > 5.0 : bst# = 5.0 : endif : if bst# <= 0.0 : bst# = 0.0 : endif : if bnc# <= 0.0 : bnc# = 0.0 : endif
move object ob, spd# - bnc# : yrotate object ob, face# : set camera to follow object position x(ob), cam_hgt, object position z(ob), face#, cam_ran, cam_hgt, 5, 0 : xrotate camera cam_tip : ob_num = object collision(ob,0)
if ob_num > 0 and ob_num =< n_blk : bnc# = spd#*1.5 : spd# = 0.0 : position object ob, o_xp#, 1, o_zp# : face# = o_face# : endif : if ob_num > n_blk : inc scr : hide object ob_num
set object collision off ob_num : if scr = 1 : start_time# = timer() : endif : endif : if scr > 0 and scr < m_scr : time# = (timer() - start_time#)/1000.0 : endif : if scr = m_scr : if time# < f_time#
nft = 1 : f_time# = time# : endif : if returnkey() = 1 : nft = 0 : for i = n_blk + 1 to ob - 2 : show object i : set object collision on i : scr = 0 : time# = 0.0 : next i : endif : endif : set cursor 0,0
print screen fps() : print "arrows keys to move, spacebar to boost" : print : print "CURRENT TIME : ", time# : print "FASTERT TIME : ", f_time# : print "CUBES COLLECTED : ", scr , " OF ", m_scr
if scr = m_scr : if nft = 0 : center text sw/2, sh/2-75, "FINISHED" : else : center text sw/2, sh/2-75, "!! NEW FASTEST TIME !!" : endif : center text sw/2, sh/2-50, "PRESS ENTER TO RESET CUBES" : endif : sync : loop
data 100,300,250,150, 100,300,450,150, 100,100,650,250, 100,300,850,350, 100,200,1050,300, 100,180,1250,290, 80,80,1360,340, 220,100,210,450
data 160,100,420,450, 100,100,650,450, 100,100,1250,450, 180,100,1410,450, 100,200,1050,600, 340,100,170,650, 140,100,430,650, 100,100,650,650
data 100,180,850,690, 200,100,1220,650, 260,100,1470,650, 200,100,200,850, 300,300,550,950, 100,100,850,850, 140,100,1070,850, 180,100,1250,850
data 140,100,1430,850, 100,100,50,1050, 100,100,250,1050, 100,140,850,1070, 100,160,1050,1080, 100,100,1250,1050, 100,300,1450,1150, 100,140,850,1230
data 100,120,1050,1240, 100,300,150,1350, 200,100,400,1250, 100,160,650,1280, 100,100,1250,1250, 200,100,400,1450, 100,320,650,1540, 100,200,850,1500
data 300,100,1150,1450, 200,100,400,1650, 100,100,1050,1650, 0,0,0,0, 350,250, 350,650, 350,950, 350,1350, 850,1350, 1350,1250, 1050,1170, 850,950
data 950,550, 1310,390, 0,0, 350.0,-200.0,0.0
Have fun and drive carefully.