Post by Rod on Dec 23, 2019 14:46:55 GMT
If you have any time over the holidays help me sort this out. You can get the tutorial here www.extentofthejam.com/pseudo/
I open this old project up every year and every year so far I have failed. It is a classic raster drawn road, it recedes into the distance and should curve gracefully towards you as you drive into the curves. Its the curves I can't get right. The straight road and banding work, Cundo showed us a curve last year but I need eventually to have flowing curves, straights and hills. But lets get the curves right first.
The idea is that there is a "segment" of road that may be curved or straight and as you move forwards it falls down the screen towards you. You should always be in the middle of the road and the change of "segment" should fall down the screen towards you moving seamlessly from curve to straight or curve to curve. Mine kinda jump about and surprise me. Not good.
I open this old project up every year and every year so far I have failed. It is a classic raster drawn road, it recedes into the distance and should curve gracefully towards you as you drive into the curves. Its the curves I can't get right. The straight road and banding work, Cundo showed us a curve last year but I need eventually to have flowing curves, straights and hills. But lets get the curves right first.
The idea is that there is a "segment" of road that may be curved or straight and as you move forwards it falls down the screen towards you. You should always be in the middle of the road and the change of "segment" should fall down the screen towards you moving seamlessly from curve to straight or curve to curve. Mine kinda jump about and surprise me. Not good.
'nomainwin
rasterlines = 260 'how many raster lines make up the road
speed = 10 'speed in raster lines
cameray = -100 'arbitrary camera height
width = 800 'screen width
height = 600 'screen height
rasterplayer = 10 'player sprite's raster line
midx = 400 'middle of the road
'precalculate the 3d distance each rasterline represents
'this is for the banded shading
'note that we end up drawing 260 rasterlines because
'the road becomes too small to draw after that
'also store the flat road width at any point in the distance
dw=(800-10)/rasterlines
w=800
dim zmap(rasterlines,2)
for raster=1 to rasterlines
zmap(raster,1) = cameray / (raster - (height / 2))
zmap(raster,2) = w/2
w=w-dw
'print raster,zmap(raster,1),zmap(raster,2)
next
'normalise the 3d distance value so that player sprite line is 100%
'we are not there yet but we will have a player sprite
b = 1 / zmap(rasterplayer,1)
b = b * 100
for raster=1 to rasterlines
'print raster,zmap(raster,1),
zmap(raster,1)=zmap(raster,1)*b
'print zmap(raster,1)
next
WindowWidth = 800 : WindowHeight = 660
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
Open "Road Race" for graphics_nsb_nf as #main
#main "trapclose [quit]"
#main "down;fill white;flush"
'we only need to draw the whole sky once
#main "fill blue"
texturepos = 0
segmentpos = rasterlines
DX = 0
DDX = 0
[draw]
scan
'set everything to mid, bottom of screen no curve
DX = 0
X= midx
screenpos = height-1
FOR raster = 1 TO rasterlines
'decide if we need to draw a light or a dark line
IF (zmap(raster,1) + texturepos) MOD 100 > 50 THEN
GrassColor$ = "green"
RoadColor$ = "darkgray"
ELSE
GrassColor$ = "darkgreen"
RoadColor$ = "lightgray"
END IF
'get the width of the road at this distance
roadw=(zmap(raster,2))
'draw the grass then the road on top
#main "color ";GrassColor$
#main "line ";0 ;" ";screenpos;" ";width;" ";screenpos
#main "color ";RoadColor$
#main "line ";X - roadw;" ";screenpos;" ";X + roadw;" ";screenpos
screenpos=screenpos - 1
if raster<segmentpos then DDX=DDXX
DX=DX+DDX
X=X+DX
next
'advance the texture position so that the banding scrolls
texturepos = texturepos + speed
if texturepos>100 then texturepos=texturepos-100
'drop the segment (curve) down the screen
segmentpos = segmentpos - speed
'choose a new segment right left curved or straight
if segmentpos<0 then
segmentpos = segmentpos + rasterlines
segment=rnd(0)
if segment>.6 then DDXX=.01
if segment<.3 then DDXX=-.01
if segment >.3 and segment<.6 then DDXX=0
end if
goto [draw]
[quit]
timer 0
close #main : end