REM Street Racing
REM Done by Krzysk (krzysk@wp.pl)
REM This game is a re-write of an Game Maker 4 demo (http://www.cs.uu.nl/people/markov/gmaker/)
 
open window 640,512
mlives = 3
mcars = 10
bonus = 5000
background_speed = 3
room_height = 512
true = 1
false = 0

dim car_status(mcars)
dim car_dead(mcars)
dim car_x(mcars)
dim car_y(mcars)
dim car_speed(mcars)
dim car_image(mcars)
main()

rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub main()
repeat
setdrawbuf dw
dw = 1 - dw
setdispbuf dw
draw_background()
if room=0 then
if room_created=false room0_game_start()
room0_step()
room0_keyboard()
room0_draw()
room1_draw()
elsif room = 1 then
if room_created=false room1_create()
room1_step()
room1_draw()
if lives = 0 room1_NoMoreLives()
fi

if police_status = true then
police_y = police_y + police_speed
police_step()
if police_y < -80 or police_y > room_height police_status = false
fi
if gas_status = true then
gas_y = gas_y + gas_speed
if gas_y > room_height gas_status = false
fi
for i = 0 to mcars
if car_status(i) = true then
car_y(i) = car_y(i) + car_speed(i)
if car_y(i) > room_height car_status(i) = false
fi
next i
if racer_status = true then
racer_y = racer_y + racer_speed
racing_step()
racing_keyboard()
racing_outside()
racing_collisions()
fi
if police_status = true police_collision()
for i = 0 to mcars
if car_status(i) = true car_collision(i)
next i
updategame()
' if sirens_play = true beep
until (1 = 2)
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub updategame()
bg_scroll = bg_scroll - background_speed
if bg_scroll < 0 bg_scroll = bg_scroll + 120
if gas_status = true draw_gas(gas_x, gas_y)
if racer_status = true draw_car(1, racer_x, racer_y, racer_dead, racer_image)
if police_status = true draw_car(2, police_x, police_y, police_dead, police_image)
for i1 = 0 to mcars
if car_status(i1) = true draw_car(3, car_x(i1), car_y(i1), car_dead(i1), car_image(i1))
next i1
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub draw_background()
clear window
setrgb 1,150,150,20
fill rectangle 0,0 to 30,512
fill rectangle 398,0 to 640,512
setrgb 1,250,250,250
fill rectangle 32,0 to 36,512
fill rectangle 212,0 to 217,512
fill rectangle 392,0 to 396,512
for i=0 to 4
fill rectangle 92,86 - bg_scroll + i*120 to 97,115 - bg_scroll + i*120
fill rectangle 152,86 - bg_scroll + i*120 to 157,115 - bg_scroll + i*120
fill rectangle 272,86 - bg_scroll + i*120 to 277,115 - bg_scroll + i*120
fill rectangle 332,86 - bg_scroll + i*120 to 337,115 - bg_scroll + i*120
next i
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub draw_car(typ,x,y,dead,col)
if typ = 1 then
setrgb 1,200,0,0
elsif typ = 2 then
setrgb 1,0,0,210
else
if col = 1 or col = 5 then
setrgb 1,0,150,0
elsif col = 2 or col = 6 then
setrgb 1,200,200,100
elsif col = 3 or col = 7 then
setrgb 1,150,0,0
elsif col = 4 or col = 8 then
setrgb 1,250,100,100
fi
fi
fill rectangle x+2,y+2 to x + 38,y + 78
setrgb 1,0,0,0
if typ=3 and col < 5 then
line x+40-8,y+80-26 to x+40-10,y+80-12
line x+40-10,y+80-12 to x+40-30,y+80-12
line x+40-30,y+80-12 to x+40-32,y+80-26
line x+40-7,y+80-39 to x+40-8,y+80-55
line x+40-33,y+80-39 to x+40-32,y+80-55
line x+40-6,y+80-69 to x+40-9,y+80-61
line x+40-34,y+80-69 to x+40-31,y+80-61
setrgb 1,255,255,0
fill circle x+40-9,y+80-6,3
fill circle x+40-31,y+80-6,3
setrgb 1,250,0,0
fill circle x+40-10,y+80-76,3
fill circle x+40-30,y+80-76,3
setrgb 1,0,200,250
fill rectangle x+40-9,y+80-58 to x+40-31,y+80-62
fill rectangle x+40-7,y+80-26 to x+40-33,y+80-36
else
line x+8,y+26 to x+10,y+12
line x+10,y+12 to x+30,y+12
line x+30,y+12 to x+32,y+26
line x+7,y+39 to x+8,y+55
line x+33,y+39 to x+32,y+55
line x+6,y+69 to x+9,y+61
line x+34,y+69 to x+31,y+61
setrgb 1,255,255,0
fill circle x+9,y+6,3
fill circle x+31,y+6,3
setrgb 1,250,0,0
fill circle x+10,y+76,3
fill circle x+30,y+76,3
setrgb 1,0,200,250
fill rectangle x+9,y+58 to x+31,y+62
fill rectangle x+7,y+26 to x+33,y+36
fi
if dead <> 0 then
setrgb 1,0,0,0
line x+2, y+2 to x + 38,y + 78
line x+2, y+78 to x + 38,y + 2
elsif typ = 2 then
setrgb 1,150,0,110
if col < 3 then
fill circle x + 10, y+ 43, 5
else
fill circle x + 30, y+ 43, 5
fi
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub draw_gas(x,y)
setrgb 1,150,0,0
fill rectangle x+2,y+2 to x + 38,y + 38
setrgb 1,250,250,250
text x+5, y+25, "GAS"
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub  room0_step()
if (int(ran(50))+1) = 1 car_create("D")
if (int(ran(100))+1) = 1 car_create("U")
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room0_keyboard()
if and(peek("port1"),8)>0 then
room = 1
room_created = false
score = 0
lives = mlives
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room0_game_start()
if score > bestscore bestscore = score
clear_objects()
room_created = true
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room0_draw()
text 455,455, "Press Start", "lc"
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room1_create()
global_petrol = 1000
alarm0 = 300
clear_objects()
if lives <> 0 racing_create()
room_created = true
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub gas_create()
gas_status = true
gas_speed = background_speed
gas_x = 40 + int(ran(320)+1)
gas_y = -40
alarm0 = 300 + score/100
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room1_step()
alarm0 = alarm0 -1
if alarm0 <= 0 gas_create()
score = score + 1
if mod(score,bonus)=0 then
lives = lives +1
beep
fi

if (int(ran(70 - score/200))+1) = 1 car_create("D")
if (int(ran(200 - score/200))+1) = 1 car_create("U")
if score > 3000 and police_status = 0 then
if (int(ran(800 - score/30))+1) = 1 police_create()
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room1_NoMoreLives()
room = 0
room_created = false
pause 0.5
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub room1_draw()
text 450,20, "Street Racing", "lc"
text 420,120, "Score: " + str$(score), "lc"
text 420,150, "Cars: " + str$(lives), "lc"
text 420,200, "Petrol: ", "lc"
text 420,250, "Bestscore: " + str$(bestscore), "lc"
setrgb 1,250,250,250
fill rectangle 500,200 to 500+100,220
setrgb 1,250,0,0
if global_petrol > 300 setrgb 1,250,200,0
if global_petrol > 700 setrgb 1,0,250,0
fill rectangle 500,200 to 500+max(0,min(100,global_petrol/10)),220
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub car_create(ch$)
for  i = 0 to mcars
if car_status(i) = false goto jump1
next i
if i > mcars return
label jump1
if car_status(i) = true return
car_status(i) = true
car_dead(i) = false

if ch$ = "D" then
car_image(i) = int(ran(4)+1)
car_x(i) = 44 + 120
car_y(i) = -80
car_speed(i) = 6
if int(ran(2)+1) = 1 then
car_x(i) = 44 + 60
car_speed(i) = 5
if int(ran(3)+1) = 1 then
car_x(i) = 44
car_speed(i) = 4
fi
fi
else
car_image(i) = 4 + (int(ran(4)+1))
car_x(i) = 44 + 300
car_y(i) = -80
car_speed(i) = 2
if int(ran(2)+1) = 1 then
car_x(i) = 44 + 240
car_speed(i) = 1
if int(ran(3)+1)= 1 then
car_x(i) = 44 + 180
car_speed(i) = 0.5
fi
fi
fi
if collision(car_x(i), car_y(i), 1)<>0 car_status(i) = false
if collision(car_x(i), car_y(i), 3)<>0 car_status(i) = false
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub car_destroy(i)
car_status(i) = false
if car_dead(i) = truereturn
beep
car_speed(i) = background_speed
car_dead(i) = true
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub car_collision(i)
if collision(car_x(i), car_y(i), 1)<>0 or collision(car_x(i), car_y(i), 2)<>0 or collision(car_x(i), car_y(i), 3)<>0 then
if car_dead(i) = true return
beep
car_speed(i) = background_speed
car_dead(i) = true
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub police_create()
police_status = true
beep
sirens_play = true
police_dead = false
police_speed = - 1.5
police_x = racer_x
police_y = room_height
if collision(police_x, police_y, 1)<>0 police_destroy()
if collision(police_x, police_y, 3)<>0 police_destroy()
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub police_destroy()
police_status = false
sirens_play = false
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub police_step()
if police_dead = truereturn
police_image = police_image + 1
if police_image = 6 police_image = 0
if racer_x < police_x then
if collision(police_x - 1, police_y, 3) = false police_x = police_x-2
fi
if racer_x > police_x then
if collision(police_x + 1, police_y, 3) = false police_x = police_x+2
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub police_collision()
if police_dead = true return
if collision(police_x, police_y, 3)<>0 then
sirens_play = false
beep
police_speed = background_speed
police_dead = true
fi
if collision(police_x, police_y, 1) <>0 then
sirens_play = false
police_speed = background_speed
police_dead = true
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub racing_create()
racer_status = true
racer_dead = false
racer_speed = 0
racer_x = 194
racer_y = 246
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub racing_step()
if racer_dead = true return
if global_petrol <= 0then
racer_speed = background_speed
else
global_petrol=global_petrol-1
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub racing_collisions()
if racer_dead = true return
if collision(racer_x, racer_y, 4)<>0 then
beep
global_petrol = global_petrol+400
if global_petrol > 1000 global_petrol = 1000
gas_status = false
fi
if collision(racer_x, racer_y, 2)<>0 or collision(racer_x, racer_y, 3)<>0 then
beep
racer_speed = background_speed
racer_dead = true
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub racing_keyboard()
if global_petrol > 0 and racer_dead = false then
if and(peek("port1"),128)>0 then
if racer_x > 32 racer_x=racer_x -2
fi
if and(peek("port1"),16)>0 racer_y=racer_y -3
if and(peek("port1"),32)>0 then
if racer_x < 360 racer_x=racer_x +2
fi
if and(peek("port1"),64)>0 racer_y=racer_y +3
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub racing_outside()
if racer_y<-80 or racer_y>room_height then
sirens_play = false
pause 1
room1_create()
lives=lives -1
fi
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub clear_objects()
racer_status = false
police_status = false
gas_status = false
for i = 0 to mcars
car_status(i) = false
next i
end sub
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub collision(x1,y1,z1)
if z1=1 then
if racer_status = true then
if abs(x1 - racer_x) >= 36 return false
if abs(y1 - racer_y) >= 72 return false
return true
else
return false
fi
elsif z1=2 then
if police_status = true then
if abs(x1 - police_x) >= 36 return false
if abs(y1 - police_y) >= 72 return false
return true
else
return false
fi
elsif (z1=3) then
for i1 = 0 to mcars
if car_status(i1) = true then
if abs(x1 - car_x(i1)) >= 36 goto jump2
if abs(y1 - car_y(i1)) >= 72 goto jump2
if x1 = car_x(i1) and y1 = car_y(i1) goto jump2
return true
fi
label jump2
next i1
return false
elsif (z1=4) then
if gas_status = true then
if abs(x1 - gas_x) >= 39return false
if abs(y1 - gas_y) >= 39 and abs(y1 - gas_y + 40) >= 39 return false
return true
else
return false
fi
fi
end sub
rem +++++++++++++++++++End of file+++++++++++++++++++++++++++++++++++++++++++




