aUCBLogo Demos and Tests / carrace2
be carrace2
roadnr=1
; setUpdateGraph false
setProcessIdleInterleaving 1
unperspective
clearScreen
hideTurtle
setLightAmbient RGB .5 .5 .5
size=1
white=RGB 1 1 1
black=RGB 0 0 0
green=RGB 0 1 0
red=RGB 1 0 0
red2=RGB .9 0 0
blue=RGB 0 0 1
perspective
;ignore
;[
planesize=1000
PenUp
back .1
down 90
fd planesize/sqrt 2
rt 135
grass=loadImage "grass.jpg
grasstex=Texture grass
setTexXY 0 0
PolyStart
setPenColor white
PenDown
setTexXY 200 0 fd planesize rt 90
setTexXY 200 200 fd planesize rt 90
setTexXY 0 200 fd planesize rt 90
setTexXY 0 0 fd planesize rt 90
PolyEnd
PenUp
Home
;]
fd 10 right 90 fd 10
disableTexture
setLabelSize [5 5]
setPenColor red
Label [Start]
setPenColor white
setPenSize [0 0]
width=20
rocks=loadImage "rockbricks.jpg
rockstex=Texture rocks
texy=0
texo=0
Home
down 90
road
rampHeight=width
rampAngle=10
p0=PosXYZ
o0=Orientation
PenUp
case roadnr
[[1
setXYZ -166.57 0 20
fd width*2
right 180
p1=PosXYZ
o1=Orientation
up rampAngle
PenDown
PolyStart
setTexXY 1 0 fd width*2 right 90
setTexXY 1 1 fd width right 90
setTexXY 0 1 fd width*2 right 90
setTexXY 0 0 fd width right 90
PolyEnd
down rampAngle
PolyStart
setTexXY 1 0 fd width*2*cos rampAngle up 90
p2=PosXYZ
o2=Orientation
setTexXY 1 1 fd width*2*sin rampAngle
setTexXY 0 0 setPosXYZ p1 setOrientation o1
PolyEnd
PenUp
right 90
fd width
left 90
p1=PosXYZ
o1=Orientation
PenDown
PolyStart
setTexXY 1 0 fd width*2*cos rampAngle up 90
setTexXY 1 1 fd width*2*sin rampAngle
setTexXY 0 0 setPosXYZ p1 setOrientation o1
PolyEnd
PenUp
setTexXY 0 0 setPosXYZ p2 setOrientation o2
PenDown
PolyStart
setTexXY 1 0 fd width*2*sin rampAngle right 90
setTexXY 1 1 fd width right 90
setTexXY 0 1 fd width*2*sin rampAngle right 90
setTexXY 0 0 fd width
PolyEnd
PenUp
setPosXYZ p2+(list 0 .2 width*0.1) setOrientation o2
down 90 right 90
fd width*3.2 left 90
water=loadImage "water.jpg
watertex=Texture water
PenDown
PolyStart
setPenColor blue
setTexXY 2 0 fd width*2 left 90
setTexXY 2 4 fd width*4 left 90
setTexXY 0 4 fd width*2 left 90
setTexXY 0 0 fd width*4 left 90
PolyEnd
]
[2
]]
PenUp
setOrientation o0
setPosXYZ p0
p0=PosXYZ
setPenSize [5 5]
PenDown
bricks=loadImage "bricks.png
brickstex=Texture bricks
walls "Line3 white
PenUp
maingraph=GraphCurrent
roadframe=Frame [][Roadmap]
wxdefault_frame_style
[0 530][400 300]
roadgraph=(Graph roadframe wxfull_repaint_on_resize [][400 300])
; GraphSetCurrent roadgraph
WindowSetClientSize roadframe 400 300
perspective
setEye {0 0 600}{0 0 0}{0 1 0}
hideTurtle
clearScreen
disableLighting
setPenColor green
road
;stop
setPenSize [4 4]
PenDown
enableCylinderLines
walls "Line red
disableCylinderLines
p0=PosXYZ
o0=Orientation
case roadnr
[[1
PenUp
setXYZ -166.7 -20 0
PenDown
PolyStart
setPenColor blue
fd width*2 left 90
fd width left 90
setPenColor black
fd width*2 left 90
fd width left 90
PolyEnd
PenUp
back width*2.1
right 90
fd width*0.8 left 90
PenDown
PolyStart
setPenColor red2
fd width*2 left 90
fd width*4 left 90
fd width*2 left 90
fd width*4 left 90
PolyEnd
]
[2
]]
PenUp
setOrientation o0
setPosXYZ p0
; showTurtle
updateGraph
;rotatescene
;stop
dispatchMessages
; FrameIconize roadframe true
GraphSetCurrent maingraph
WindowSetFocus maingraph
;updateGraph
;stop
;rotateScene
;stop
MidiOpen 0
MidiProgramChange 0 117
MidiProgramChange 1 81
MidiProgramChange 2 125
MidiProgramChange 3 122
motornote=40
besttime=99999999
running=true
while [running]
[
PenUp
Home
setXYZ 0 0 0
;setXYZ -186 0 0
;right 180
fd 5
down 90
fly_around
if wxNO==(MessageBox
[Do you want be play again?][Again?] wxYES_NO)
[ running=false
]
]
GaugeDestroy speedgauge
FrameDestroy roadframe
OnChar []
OnKeyDown []
OnKeyUp []
MidiAllSoundsOff
MidiClose
if Key? [ignore readChar]
be road
case roadnr
[[1 f 50
r 45 50
f 50
l 180 30
f 50
l 45 100
f 50
r 180 30
f 50
l 135 100
l 45 30
f 50
l 180 30
r 180 30
f 150
l 90 60
r 180 30
r 30 100
l 180 20
l 30 120
f 64.7
l 90 100
l 45 30
r 45 100
f 59
]
[2 r 90 50
r 180 50
f 81.5
r 200 100
f 140
r 200 100
setY YCor-0.05
r 50 100
]]
end
be Line3 p c
setPenColor c
PenUp
setXYZ (p.1).1 0 -(p.1).2
PenDown
PolyStart
local "len
len=Norm p.2-p.1
setTexXY 0 1 setXYZ (p.1).1 3 -(p.1).2
setTexXY len/10 1 setXYZ (p.2).1 3 -(p.2).2
setTexXY len/10 0 setXYZ (p.2).1 0 -(p.2).2
setTexXY 0 0 setXYZ (p.1).1 0 -(p.1).2
PolyEnd
PenUp
end
be walls Lin c
case roadnr
[[1 run (list
Lin [[-30 -230][ -30 90]] c
Lin [[-30 90][ 30 150]] c
Lin [[-30 -230][ 20 -150]] c
Lin [[-85 0][ -85 300]] c
Lin [[-30 -60][-150 -60]] c
Lin [[-150 -60][-150 110]] c
Lin [[-150 110][-200 140]] c
Lin [[-270 120][-200 140]] c
Lin [[-270 120][-270 40]] c
Lin [[-205 55][-300 -300]] c
Lin [[-260 -150][-110 -185]] c
Lin [[ -30 -230][-180 -220]] c
Lin [[ 40 -50][ 40 70]] c
Lin [[ 40 0][ 400 0]] c
)
]
[2 run (list
; Lin [[-30 -240][ -30 90]] c
)
]]
end
be f len
; PenUp fd len*size setTexXY xCor/10 zCor/10 back len*size PenDown
texo=texy
texy=texy+len*size/10
local [p0 ori]
p0=PosXYZ ori=Orientation
left 90 fd width/2 right 90
PenDown
PolyStart
setTexXY 0 texy fd len*size right 90
setTexXY 1 texy fd width right 90
setTexXY 1 texo fd len*size right 90
setTexXY 0 texo fd width right 90
PolyEnd
PenUp
setPosXYZ p0 setOrientation ori
fd len*size
end
be r angle radius
arc2t angle radius*size
end
be l angle radius
arc2t -angle -radius*size
end
be arc2t angle radius
local [w p0 p1 p2 p3 p4]
w=-width ;*signum radius
PenUp right 90 fd radius left 180
fd radius+w/2 p1=PosXYZ
back w p4=PosXYZ
back radius-w/2
for [phi angle/20 angle angle/20]
[ right angle/20
; fd radius setTexXY xCor/10 zCor/10 back radius
texo=texy
texy=texy+abs (pi/180)*(angle/20)*radius/10
fd radius+w/2 p2=PosXYZ
back w p3=PosXYZ
back radius-w/2
p0=PosXYZ ori=Orientation
setPosXYZ p1
PenDown
PolyStart
setTexXY 1 texo setPosXYZ p1
setTexXY 1 texy setPosXYZ p2
setTexXY 0 texy setPosXYZ p3
setTexXY 0 texo setPosXYZ p4
PolyEnd
PenUp
setPosXYZ p0 setOrientation ori
p1=p2
p4=p3
]
pu fd radius rt 90 pd
end
be fly_around
local [eye realeye light center upvector eyepos eyeori]
center={0 0 0}
upvector={0 1 0}
eye=array 3
light=array 3
ang=3.6
v=0+1.0
dv=0.0
a=v/300
eyecenter=100
eyecenter2=eyecenter*2
vmax=3
Ï={0 0 0}
dÏ=0.8
PenUp
forward eyecenter
eye=Array PosXYZ
realeye=PosXYZ
lastrealeye=realeye
forward eyecenter
center=Array PosXYZ
back eyecenter
starttime=-1
speedgauge=(Gauge [] [Speed] 300 0
wxga_smooth+wxga_vertical [0 0][400 30])
dispatchMessages
WXK_A=ASCII upperCase "A
WXK_Y=ASCII upperCase "Y
; WindowOnChar maingraph [ignore readChar]
WindowOnKeyDown maingraph
[ k=KeyboardValue
case k
[ [wxk_right kright=true]
[wxk_left kleft =true]
[wxk_a kup =true]
[wxk_y kdown =true]
[wxk_escape running=false]
]
]
WindowOnKeyUp maingraph
[ k=KeyboardValue
case k
[ [wxk_right kright=false]
[wxk_left kleft =false]
[wxk_a kup =false]
[wxk_y kdown =false]
]
]
kright=false
kleft =false
kup =false
kdown =false
inwall=false
inwater=false
ongrass=false
onramp=false
lastonramp=false
lastongrass=false
inair=false
local [running]
running=true
while [running]
[ setEye eye center upvector
setLightPos {0 1000 0}
eyepos=PosXYZ
eyeori=Orientation
redraw
updateGraph
setPosXYZ eyepos
setOrientation eyeori
fd 1
eyevec=PosXYZ-eyepos
back 1
back eyecenter2
dispatchMessages
if not inair
[ if kright
[ Ï.3=Ï.3+dÏ/(1+0.1*Norm v)
]
if kleft
[ Ï.3=Ï.3-dÏ/(1+0.1*Norm v)
]
ifelse ongrass
[ Ï.3=Ï.3*0.8
][ Ï.3=Ï.3*0.9
]
right Ï.3
if kup
[ if v < vmax
[ dv+=a/(1+0.1*Norm v)
GaugeSetValue speedgauge Int v*300/vmax
]
]
if kdown
[ if v > 0
[ dv-=a/(1+0.1*Norm v)
GaugeSetValue speedgauge Int v*300/vmax
]
]
dv*=0.95
v+=dv
]
;comment [
GraphSetCurrent roadgraph
setXY realeye.1 -realeye.3
setHeading ArcTan -eyevec.3 eyevec.1 ;eyeori.3
updateGraph
p0=PosXYZ
lastinwall=inwall
inwall=false
lastongrass=ongrass
ongrass=false
hideTurtle
if not inair
[ for [i 1 10]
[ forward v/10
c=Pixel
if c==red
[ inwall=true
break
]
if c==red2
[ inwater=true
break
]
if c==white
[ ongrass=true
]
rgbc=reRGB c
redpart=rgbc.1
greenpart=rgbc.2
bluepart=rgbc.3
ifelse (redpart==0) and2 (greenpart==0)
[ ifelse bluepart>0.9
[ onramp=true
][ if (not onramp) and2 not inair
[
inwall=true
break
]
]
][ onramp=false
]
]
]
setPosXYZ p0
showTurtle
;]
GraphSetCurrent maingraph
ifelse onramp and2 not lastonramp
[ lastonramp=true
up rampAngle
][ if (not onramp) and2 lastonramp
[ lastonramp=false
inair=true
down rampAngle
]
]
if inwater and2 not inair
[ MidiAllSoundsOff
MidiNoteOn 3 50 127
waitMS 3000
MidiNoteOff 3 50 127
running=false
]
ifelse inwall
[ if not lastinwall
[ MidiNoteOn 0 50 127
waitMS 50
MidiNoteOff 0 50 127
]
v=-v*0.8
][ if ongrass
[ v*=0.97
setY 5+rnd*0.2*Norm v
]
v*=0.995
]
forward v
if inair
[ down 0.945
if YCor < 5
[ inair=false
;(pr rgbc [!inair] onramp inair)
setY 5
head=Heading
setOrientation (list 0 -90 head)
]
]
lastrealeye=realeye
realeye=PosXYZ
forward eyecenter2
eye=Array PosXYZ
forward eyecenter
center=Array PosXYZ
back eyecenter
up 90 fd 1
upvector=(Array PosXYZ)-eye
upvector/=Norm upvector
bk 1 down 90
if realeye.1 > -2*width and2 realeye.1 < 2*width
and2 realeye.3 < 0 and2 lastrealeye.3 > 0
[ ifelse starttime < 0
[ starttime=timefine
][ roundtime=timefine-starttime
kright=false
kleft=false
kup=false
kdown=false
ifelse roundtime < besttime
[ ignore MessageBox (Sentence [Best round:] roundtime [sec.])
besttime=roundtime
][ ignore MessageBox (Sentence [This round:] roundtime [sec.]
[best was:] besttime [sec.])
]
starttime=timefine
]
]
motorsound
]
be motorsound
local [note npitch]
note=40+4*Int 12*v/vmax/4
npitch=127+Int 127*(mod 12*v/vmax 4)/4
if note != motornote
[ MidiNoteOff 1 motornote 127
MidiNoteOn 1 note 16
motornote=note
]
MidiMessage (list 224+1 0 npitch)
if ongrass and2 not lastongrass
[ MidiNoteOn 2 40 64
]
if (not ongrass) and2 lastongrass
[ MidiNoteOff 2 40 64
]
end
end
end