' Have fun with your new project!
' :) +++++++
' ++

print "WORK IN PROGRES..."

'select screen front

font size 10
scale screen 0, 0 to 1000, 500
fade screen 75

?zz = -1

?tile = 64
?serie = 4
?distance = ?tile * 2
?offset = 0
?sub_offset = 0
?camera_y = ?tile / 2
?camera_incline = ?tile / 2
?camera_z = 0

?shake = 0

?debug = 0

[city, z, 1] = 0
[city, z, 2] = 500

[step] = 0
[city] = 1

?vx = 0
?px = 0
?py = 1
?pz = ?distance + 15

?puissance = 0
?vitesse = 0

?arbres = 10


?flash = 0
?flash_base = 50
?mode_rapide = 0

show fog 3 to ?tile * 3


create light as "sun"
power "sun" to 100

create orb as "light-car"
color "light-car" to #ffd




goto "add_road"
goto "add_ground"
goto "add_car"
goto "add_city"
goto "add_bord"
goto "add_vent"
goto "add_arbre"

if ?debug = 1
	
	?serie = 3
	?camera_y = 200
	?camera_incline = 10
	hide fog
	
	zoom "road-1" to 1, 1, 0.9
	zoom "ground-1" to 4, 2, 0.8
	
end


for 2 to ?serie as ?n
	clone "ground-1" as "ground-?n"
	clone "road-1" as "road-?n"
	clone "bord-1" as "bord-?n"
	clone "vent-1" as "vent-?n"
next

for 2 to ?arbres as ?a
	clone "arbre-1" as "arbre-?a"
next



goto "run"


label "run"
	do
		update
		goto "manage_player"
		goto "manage_road"
		goto "manage_city"
		goto "interface"
	loop
return


label "manage_player"
	
	if ?puissance < 90
		?puissance + .05
	end
	
	?vitesse = 1 * (sin ?puissance)
	
	move "car" to ?px, ?py, ?pz
	turn "car" to 0, ?vx * -5, ?vx * -3
	
	move "light-car" to ?px, ?py + 10, ?pz + 10
	
	move "sun" to ?px + 40, ?py + 20, ?pz + 40
	target "sun" to ?px + 20, ?py + 10, ?pz + 20
	
	
	if ?px < -28
		?vx = 2
		?shake = 2 * ?vitesse
		?puissance * .9
	end
	
	if ?px > 27
		?vx = -2
		?shake = 2 * ?vitesse
		?puissance * .9
	end
	
	
	?camera_z + (?camera_incline - ?camera_z) / 90
	
	?mx = ?shake * (sin ?an)
	?an + 17
	?shake * .92
	move "camera" to ?mx, ?camera_y, ?distance
	target "camera" to ?mx, 0, ?distance + ?camera_z
	
	
	
	
	?dx = 0
	if (key "left") = 1 and ?vx > -1
		?dx = -1
	end
	if (key "right") = 1 and ?vx < 1
		?dx = 1
	end
	
	if (key "down") = 1
		?puissance * .99
	end
	
	?vx + (?dx - ?vx) / 10
	?px + ?vx / 2
	?vx * .995
return

'

label "manage_road"
	
	'print ?distance
	?avance = ?vitesse * 2
	?distance + ?avance
	?pz + ?avance
	
	
	if ?distance - ?offset > 32' ?tile
		
		?offset + ?tile
		
		[step] + 1
		
		for 1 to ?serie as ?n
			?horizon = (?n - 1) * ?tile
			
			move "road-" + ?n to 0, 0, ?offset + ?horizon
			move "ground-" + ?n to 0, -1, ?offset + ?horizon
			move "bord-" + ?n to 0, 1, ?offset + ?horizon
			
		next
		
	end
	
	'
	?sub_offset + 1.1 * ?vitesse
	
	if ?sub_offset > ?tile
		?sub_offset = 0
	end
	
	for 1 to ?serie as ?n
		?horizon = (?n - 1) * ?tile
		?y = ((?vitesse * 2) - 1) * ?tile / 2
		move "vent-" + ?n to 0, ?y, ?offset + ?horizon - ?sub_offset
	next
	
	
	'print ?offset
	'print [arbre,1]
	
	for 1 to ?arbres as ?a
		if [arbre, ?a] < ?offset
			if (dice 1 to 30) = 1
				?name = "arbre-" + ?a
				[arbre, ?a] = ?offset + 3 * ?tile + (dice 1 to ?tile) * 8
				?x = ?tile / 2 + (dice 1 to 2) * 8
				?s = (dice 1 to 2)
				if ?s = 1
					?x = -?x
				end
				move ?name to ?x, 1, [arbre, ?a]
				'print ?name + " = " + ?x
			end
		end
	next
	
	
return

'

label "manage_city"
	
	for 1 to 2 as ?c
		
		'if [city,z,?c] + ?distance > ?tile
		if [city, z, ?c] < ?distance
			?x = (dice ?tile * .9 to ?tile * 2)
			if ?c = 1
				?x = -?x
			end
			
			[city, z, ?c] + ?tile * (dice 4 to 8)
			move "city-?c" to ?x, 0, [city, z, ?c]
		end
	next
	
	
return

'
'
'

label "add_road"
	
	create sprite ?tile as "road-1"
	'zoom "road" to 100,100,95 'debug
	'hide "road"
	
	color #545450ff
	add "road-1" box 1, 1, 1 to ?tile, 1, ?tile
	
	for 32
		for 1 to 3 as ?c
			if ?c = 1
				color #505050ff
			else if ?c = 2
				color #585858ff
			else if ?c = 3
				color #5a5a5aff
			end
			
			?z1 = (dice -8 to ?tile + 8)
			?z2 = (dice -8 to ?tile + 8)
			?x = (dice 1 to ?tile)
			add "road-1" line ?x, 1, ?z1 to ?x, 1, ?z2
		next
	next
	
	color 11
	for 1 to ?tile as ?z
		'add "road-1" dot to 1,1,?z
		if (mod ?z, 16) < 6
			add "road-1" dot 18, 1, ?z
			'add "road-1" dot to 32,1,?z
			add "road-1" dot 47, 1, ?z
		end
		'add "road-1" dot to ?tile,1,?z
	next
	
	color 16
	add "road-1" line 32, 1, 1 to 32, 1, ?tile
	add "road-1" line 34, 1, 1 to 34, 1, ?tile
	
	color 1
	add "road-1" line 3, 1, 1 to 3, 1, ?tile
	add "road-1" line ?tile - 2, 1, 1 to ?tile - 2, 1, ?tile
	
	color 25
	add "road-1" line 1, 1, 1 to 1, 1, ?tile
	add "road-1" line ?tile, 1, 1 to ?tile, 1, ?tile
	
	
return

label "add_ground"
	
	?s = 16
	?ratio = 1 * (?tile / ?s)
	
	create sprite ?s as "ground-1"
	color #509020' #5b2
	add "ground-1" box 1, 1, 1 to ?s, 1, ?s
	zoom "ground-1" to ?ratio * 6, .5, ?ratio
	
	color #589828'#6c3
	for ?s * 4
		add "ground-1" dot (dice 1 to ?s), 1, (dice 1 to ?s)
	next
	
return


label "add_car"
	
	?sz = 8
	create sprite ?sz as "car"
	paint "car" to "metal"
	color 8
	add "car" box 2, 1, 1 to ?sz - 1, 3, ?sz
	color 5
	add "car" dot 3, 3, 1
	add "car" dot 6, 3, 1
	color 6
	add "car" dot 3, 2, ?sz
	add "car" dot 6, 2, ?sz
	color #000
	add "car" frame 2, 4, 3 to ?sz - 1, 4, ?sz - 1
	color 8
	add "car" box 3, 5, 4 to ?sz - 2, 5, ?sz - 2
	color 91
	
	add "car" box 2, 1, 2 to ?sz - 1, 2, 3
	add "car" box 2, 1, ?sz - 2 to ?sz - 1, 2, ?sz - 1
	center "car" to 4, 1, 4
	
	zoom "car" to 1
	
return

'

label "add_city"
	
	create sprite 9 as "city-1"
	color 1
	add "city-1" box 1, 2, 1 to 7, 9, 7
	color 91
	for 3 to 8 step 2 as ?y
		add "city-1" frame 1, ?y, 1 to 7, ?y, 7
	next
	color 1
	add "city-1" frame 1, 1, 4 to 7, 7, 4
	color 51
	add "city-1" frame 1, 1, 1 to 7, 1, 7
	
	center "city-1" to 4, 1, 4
	zoom "city-1" to 4, 1.5, 8
	paint "city-1" to "metal"
	
	clone "city-1" as "city-2"
	
	
return

'

label "add_bord"
	
	create sprite ?tile as "bord-1"
	
	color 41
	add "bord-1" line 1, 4, 1 to 1, 4, ?tile
	add "bord-1" line ?tile, 4, 1 to ?tile, 4, ?tile
	
	color 51
	'add "bord-1" line 1,3,1 to 1,3,?tile
	'add "bord-1" line ?tile,3,1 to ?tile,3,?tile
	
	for 1 to ?sz step 8 as ?z
		add "bord-1" line 1, 1, ?z to 1, 3, ?z
		add "bord-1" line ?tile, 1, ?z to ?tile, 3, ?z
	next
	
	center "bord-1" to 33, 1, 33
	
return

'

label "add_vent"
	
	create sprite ?tile as "vent-1"
	paint "vent-1" to "neon"
	
	color #00ffff18
	for 1 to 8
		for 1 to 3 as ?cote
			?u = (dice 1 to ?tile / 2)
			?v = (dice ?tile / 2 to ?tile)
			?w = (dice 1 to ?tile)
			if ?cote = 1
				add "vent-1" line 1, ?w, ?u to 1, ?w, ?v
			else if ?cote = 2
				add "vent-1" line ?tile, ?w, ?u to ?tile, ?w, ?v
			else if ?cote = 3
				add "vent-1" line ?w, ?tile, ?u to ?w, ?tile, ?v
			end
			
			
		next
	next
	
	center "vent-1" to 33, ?tile, 33
	zoom "vent-1" to 1.10, 0.50, 1.00
	
return

'
'

label "add_arbre"
	
	create sprite 15 as "arbre-1"
	color #840
	add "arbre-1" line 3, 1, 3 to 3, 5, 3
	
	?y = 6
	for 1 to 4
		color #481' #281
		add "arbre-1" frame 1, ?y, 1 to 5, ?y, 5
		?y + 1
		
		color #5a2' #3a2
		add "arbre-1" frame 1, ?y, 1 to 5, ?y, 5
		?y + 1
		
		color #8f2' #4f2
		add "arbre-1" box 1, ?y, 1 to 5, ?y, 5
		?y + 1
	next
	
	center "arbre-1" to 3, 1, 3
	
return

'

label "interface"
	
	power "glow" to ?flash
	?flash + (?flash_base - ?flash) / 40
	
	if ?mode_rapide = 0 and ?vitesse > .5
		?mode_rapide = 1
		?flash = 100
	else if ?mode_rapide = 1 and ?vitesse < .5
		?mode_rapide = 0
	end
	
	
	
	'draw clear
	?kmh = (round ?vitesse * 210)
	
	color 1
	
	create text "?kmh KM/H" as "compteur"
	paint "compteur" to "ui"
	zoom "compteur" to .40, .40, .5
	
	?fps = (round (fps))
	?km = (round ?distance / 1000 to 1)
	'create text "?km KM" as "fps"
	create text "?fps FPS" as "fps"
	paint "fps" to "ui"
	zoom "fps" to .20, .20, .05
	
	
	if (is "compteur") = 1
		move "compteur" to ?tile / 2, 20, ?distance + 40
		move "fps" to -?tile / 2, 20, ?distance + 40
	end
	
	
	info
	select screen front
	color 1
	clear screen
	draw text (calls) align to 1910 ,0
	code
	
return
x