Andas I'm justabouttocrossthestart, finishstraight, wecanseewhatlaptime I clockedinthistimewas 42.8 seconds.
I'm surewecandomuchbetterthanthatif I attempttogotoofastaroundthecornerandpushedouttotheside, so I havetousetheacceleratorquitecarefully, likesomeofmyothercodedyourselfvideos.
Thisonelookslikethere's a lotgoingon, butactuallythereisn't.
And I thinkthisisreallywhatthisvideoisaboutiswecantake a reallymundane, simplemathematicalconcept.
Butifwepresentitinaninterestingway, becomes a playablegay.
I needtobreakuptherowintowhetherit's, ah, grassclippingboardallroad, soeachcharactergoingacrosstheconsolewe'regoingtoclassifyasoneoftheother.
Tomakethings a littlesimpler, I'm goingtoassumethatthewidthofthescreenisgoingtobe a normallifeSpecsorzerofortheleft, ononefortherightsothemiddleofthescreenwillbe 10.5.
Thisisusefulbecausewe'llprobablywanttoscalethingsup, dependingonthesizeofscreen, butitalsomakessomeofthemathematics a littlesimplerlateron, too.
So I needtoworkoutwherethoseboundariesareintheexdirection.
So, forexample, I knowthatmygrassbeginsatzero, butitwillstopwhenwegettothemiddlepointofthetrack, minustheroadwithwhichisnohalfonminustheclippingboardwith.
I canthenscalethatintothescreenspaceforthecouncilin a similarmanner.
I canworkoutwheremyleftclippingboardis.
Soit's exactlythesamecalculation.
But I don't needtoincludetheclipwidththistimeonbecausewehavetheroadwithbeforeDoingtherightinsideisthesamenow, exceptwe'redoingplusesinsteadofminuses.
Soweknowthatif X isgreaterthanzeroondheexesleftthanourendleftgrassvariablethatwe'regoingtoshadethatcharactergreen, and I'm goingtousethedrawerfunctions.
ThisisprovidedbytheoneloneKodaclass, andallitdoesistakethe X and Y coordinates, andwecanusethesolidcharactertobasicallyfake a pixelonwillusetheconstant F G green, thegrass.
Soweneedtodosomescalingtoeworkoutwherethatisinconsolespacescreenwithdividedbytwowillgiveusthemiddleoffthetrack, and I wanttooffsetfromthemiddleofthetrackwherewe'regoingtoputitinthecar.
I'm alsogoingtocuriouslyadbecause I'veseenintothefuture, ofcourse, a minussevenhere, and I knowthat's goingtobethewidthofthespiteofthecar.
Positwe'vejustworkedoutonthewhitepositionisgoingtobefixedonthescreen, solet's take a quicklookatthis.
Brilliant.
Wecanseewe'venowgot a carinthemiddleoftheroad, butsomethingdoesn't lookquiteright.
We'relackingperspective.
Perspectiveisn't ascomplicatedasyoumightthinktoimplementwhatwe'regoingtodoistakethecurrentrowanddivideitbyhalfofthescreensThatbasicallygivesus a percentageonthere, fortheperspectivetendstowardzerowhen, whysmallandittendstowardsonewhenwiselargein a linearfashion.
Wecanachievethislinepositioningbyusingsomesimplemathshere, usingtheDesmondStarcomplatform, I'm graphing a sinewave, butit's a sinewavehasbeenmodifiedbytwothings.
Well, inmostmoderngames, ofcourse, thetrackis a three D model, anditmaybetemptingtodosomethingsimilar, forexample, having a wholeloadofnodesondefiningsomepropertiesbetweenthenodesinthree D space.
I knowwhichsection I'm in, and I canworkouthowmuchmycarisoffsetintothetrack.
Once I knowthisindex, I canworkoutthetargetcurvatureforthatsectionoftrack, and I candisplaythatnowonthescreendisplayingcurve, actually, simplyanglingthetrackoffat a particularradius.
It's a goodjobwehavethismiddlepointvariablebecauseallweneedtodoischangethemiddlepoint.
Sohowdoweturnthisinto a game, andthisisthebitwhere I saidatthestartofthevideo, wecanactuallymakesomethingreallymundaneintosomethingfunjustbyhowwepresentitonthescreen.
Sohereis a trackbrokenintwosectionsonAsthecarmovesalongthetrack.
Let's considerthisfrom a slightlydifferentperspective.
Let's assume, wouldplayin a gamewhere a pathisbeingpresentedtowardstheplayerandtheplayerhastopresstheleftandrightkeytomakesurethattheirpointremainsonthatpathasthepathismovingtowardsthem.
Andifthetrackcurvatureandtheplayercurvaturearedifferentby a certainamount, wewanttoartificiallyslowdownthecarbecausethismeansthey'llhavegoneoffthetrack.
Wemightneedtofind, too, inthisvalue, but I'veused a higherdecelerationrateherethannormal, notjustacceleratingtomakeitfeelasifthatthegrassisisgripherethantheroad.
Weshouldnowdrawthecarin a differentplace, dependingonthediscrepancybetweenthetwo.
Weshoulddrawthisinformationontheplayersscreen, but I justhave a floatingpointfilledwithfloatingpointseconds.
I'm goingtocreate a littlelambdafunctiontohelpmeout.
SotheLambdaFunctiontakes a floatingpoint t parameter, whichisthetimeinseconds, andit's goingtoreturn a W string, whichisthestreetequivalentofthattimeinminutes, secondsandmilliseconds.
Sotocalculatethenumberofminutes.
Ofcourse, I justtaketeaonDividedby 60.
Thefactthatitgetscasttointerviewhealthisouthere.
Itgetsridofallofthecrowdattheendofthatremainder.
Once I knowhowmanyminutes I cansubtractthatfromthetimeandcalculatethenumberofsecondsthatleftoverandinthesameway I cancalculatethenumberofmilliseconds.
But I needtomultiplythisby 1000 attheendbecausethiswillbe 0.111 whatever, butwedon't wanttodisplay 0.0 point 0111 Sowe'regoingtomultiplyby 1000 togiveus.
Ah, nicenumberfordisplayingis a stringandthenwithliberaluseoffthetwo W stringfunction.
I canglueallofthistogetheronce I'vegotmylittlelambtofunction.
Drawingthetimetothescreeniseasy.
I couldjustusethedrawstringcommand, whichispartofthecouncilgameengineslibrarydrawingutilities.
Therewas a droidto a fixedposition 10 columnsinbyeightrowsdownthistime F currentlaptime.
Let's notforget, I wanttostorethatmostrecentfivelaptimessotheplayercanseeifthey'reimprovingornot.
I'm justgoingtoinclude a listofffloatsforthis.
I'm goingtoinitializethelistwith 50 laptimes, andthereason I'm choosing a listinsteadof a vectorforthisis I likethepushfromthefrontandpopfromthebackfunctions, So I'm justgoingtopushthecurrentlasttime.
Thisisourlittlelapcheckingfunction, remember?
Sooncewe'vedone a lap, I'm goingtopushtothefrontofthelistthecurrentlaptime, and I'm goingtopopfromthebackofthelist.
Whateverwastherebefore, weshouldalsodisplaythesetimestotheplayeronhavingourlittleLambdafunctionhasmadethismuchsimplernowbecauseall I needtodoiscreateanautotooliteratethroughthelaptimes, and I drawthemalltothescreen.
I got a littletemporaryvariable J herebecause I wantthemtodrawthemlinebyline.
I needtoincrementthat.
Let's have a look.
Wecanseeinthetopleftthatthereis a timeofaccumulatingthecurrentlaptimeonjustabouttocrossthefinishline.
Butinsteadofjusthaving a leftorrightarrowappearonthescreen, I thoughtitwouldbenicetohavethecartryingtopointinthedirectionthatthey'restaringorespeciallycandowithoutasking.