There's a maximumoff 20 nonplayerunitswanderingaroundonthemap, andtheyspawnand d spawn.
We'renotinviewofthecamera.
20 is a ratherarbitrarynumber, but I feelitgives a goodlevelofdensitybecausedon't forget, we'vegottoallowtheplayersspacetoactuallydrivethecararoundwithouthittingeveryobstacleinsight.
Nowthefirstthing I willsayisthateverythinghasbeenoverhauledfromthefirstvideo.
Andif I gointoeditmodenowintheeditor, wecanseethere's quite a greatdealofcomplexityregardinghowthenonplayercharactersmanipulatethemselvesaroundthemapon.
I shouldalsopointoutthebuildingshavechanged.
Yes, thetextureis a bithighfrequency.
I appreciatethat, andwemayconsiderfilteringlateron.
Butwhat I wantedtogetacrosshereisthatallofthemodels, includingthecar, arenowassetsgeneratedbytheonelonecodercommunity.
Sozoominonthecarfor a second.
Wecanseeit's actually a three D model, andhe's gotsomedirectionallightingappliedtoit, too, isverysubtle.
I'lljustgobackintoeditmodeon.
Wecanseethatthenodesand a networkthatthenonplayingcharactersthatfollowaroundOndathegreennodesmeantheytheycanpassthroughit, andtherednodesmadethattheycan't.
Sointhisway I canemulatesortof a trafficlightsequence.
Theeditorhasn't changed a greatdealintermsofhowitfunctions.
Johnsonrodehereon a loopofroad, butwe'llseethatthere's nononplayercharactersontheInfact, they'reallclusteredaroundthecurrentcenterofthecamerasviewingpointthatwego.
Sowhen I zoomout, wecanseethempopinandoutofexistence.
If I moveddownhere, wecanseenowthatwithcamerasfocusediswherethenonplayercharacterentitiesappear.
I'm justgoingtofollowtheseround a littlebit, soexcusethesilentpauses.
Butitdoestake a bitoftimeforthingstohappennow.
Theplayer, duringnormalgameplay, wouldn't seetheunit's popinandoutofexistencethatsimplybecausethecameraisrestrictedto a fairlylocalfieldofviewontheboundaryforspawningand D sportingofthenonplayerentitiesisbeyondthatfieldofview.
A particularsequenceinthissequenceisishighlymodifiableeso.
Rightnowit's completelydumb.
Anytrafficcominginfromonesidecompletelyprohibitstrafficcominginfromtheothertwosidesofthis T junctionsowecanseethatthequeueisforming.
Butoncethetrafficlightstakeovertoallowthiscuetoenterthe T junction, therewego.
Perfecttiming.
Wecanseethatthecar's choose a particularpathon.
Theyfollowtherulesoftheroad.
Thecommunityresponsetothefirstvideowasfargreaterthan I everanticipatedonassumesthatvideowentoutonquite a lotofrequestsforpeopletostartgeneratingbuildingsandvehiclesandcreatingallsortsofassets.
Theyreallylatchedontothemodifiablepropertiesoffthegame, andso I thought, Well, hangup.
Let's let's actuallypursuethat.
Afterall, thisis a communityfocuschannel, and I wantedtobe a sortof a communityprojectandpeoplemightwanttomodelthisprojectatdifferentlevelsofcomplexitywillbethosethatcan't waittodigintothesourcecodestartpokingaround, butwillalsobethosethataremoreinterestedinthecreativesideofit.
Because I'verestructuredtheprojectquitesignificantly, I'm goingtostartbuildingitfromscratch.
However, a lotoftheideasweusedinpartonearegoingtocomeoverto, solet's getstarted.
TheprototypedevelopedinpartoneoftheSiri's wasmytypicalsinglefileapproachtodeveloping a quickgame.
Andsincetherewas a greatdealofenthusiasmfromthecommunity, I thoughtitbettertostarttorestructuretheprojectinsuch a waythatitcanbeeasilymaintaineduneasilymodit.
Consequently, I'vedecidedtocreate a newproject, solet's dojustthat.
Hereis a blankvisualstudioWindowsConsulapplicationprojectonAll I'vegotsofaris a maindot C P p, with a blankintomainfunction.
I knownowthat I'm goingtowanttosplittotheprojectacrossmultiplesourcefilesongoingtoabuseobjectorientedprogrammingtohelpmeout.
Butthatmeanswehavetousethepixelgameengineinobjectorientedprogrammingmodeonbecausethepixelgameengineis a singlehad a solution.
Thiscanaddadditionalcomplexity.
Theeasiestwaytouseitinmultiplefilesistocreate a singleCPPfile.
I'llcallitOLCpixelgameenginedot c, p.
P.
Andinthatfile, I'm goingtoincludetheheadtofile.
Thisgivesthecompilerlongtranslatableuniton.
ThismeanswecanincludetheOLCpixelgame.
Enginedot h fellfromanyotherfile, andwewon't haveanymultipleinstancesproblemsinthesamefather.
I'm alsogoingtoincludethegraphicsthree D extensiontothepixelgameengineon.
It's goingtoalsocontaininformationthatdefinesthescreenresolutionandhowthewindowappearstotheuseronas I didwithcodeityourselfroleplayinggame, I'm goingtocreate a singletonobjectthat's loadedoncewithallofthisinformation, I'm goingtoadd a classcalledGameSettingsontothisclass.
I'm goingtoaddthenecessarycodetoincludeLeuer.
Thisclassisgoingtostoreinformationabouthowtodisplaythingstothescreen, andit's goingtogetthatinformationbyloading a Louiefileandexecutingitinthegame, settingCPPfarwithlotsofstaticvariables.
So I'm goingtoinitializethosetwosomedefaultvaluesincasetheLouisfilecan't befound.
Thissetupbluefileisnotgoingtobepersistent.
It's goingtobeloadedandexecutedonceonthisgame.
Settingsclasswillthencontainalloftherelevantinformation, so I'm goingtocreatetheLouisST I'm goingtoattempttoopenthefileandthen I'm goingtoattempttoexecutethefile.
Ifanyofthesefail, itwilldisplay a messageinthecouncilwindowattachedtothegamewindow, whichisveryusefulfordebugging.
Once I'vegottheinformation I need, I'm goingtoclosetheloopfileonreturn.
Now I cangobacktomymainCPPfileonincludethecarcrimecityclassonthegamesettingsclassthegamesettingsisthefirstthing I wanttoload.
So I'm goingtocreateaninstanceofmygamesettingSingletononCalltheloadconflictfilefunctionpassingtoittheparticularfilepath.
Once I'veloadedthesettings, I canthencreateaninstanceofthecouncilgameengineon.
I'llstartthecouncilgameengineinthewaythat I usuallydo, butnow I'm goingtousetheparametersstoredinthesingleton.
I'llcalltheconstructfunction, and I'llusethepropertiestoconfigurehowthescreenlookswhenwespecifythewidth, theheight, thepixelwiththepixelheightandfinally, a mysterybonusparameter, whichnotmanypeopleknowabout.
Butifyouspecify a Booleanvalueas 1/5 perimetertotheconstructfunction, youcanforcethepixelgameenginetouse a fullscreenmode.
Ifitsuccessfullyconstructs, thenstartthegame.
I'veaddedtheconflictLouiefiletomysolutionso I caneasilyfinditandchangeit.
Andthenicethingis, visualstudio.
Willsyntaxhighlightthelowercorrectlyonrightnowall I haveinmyLouiefileotherparametersthatwewerelookingforalongsidethesemechanicalvalues.
I alsowantthesettingsclasstocontainotherinformationabouttheobjects I needtoloadintothegames, suchastexturesonMashisthisway.
So I'm goingtoneedtocountthroughthemtoknowwhattheyarehere.
I'm goingtocreateanobjectofthetextureon a stagecounterondependingonthisstage.
I knowwhetherit's thenameofthetextureorthefile.
Eitherway, forthatparticularreturnedobject, I wanttopopitoffthetopofthestackandincreasemystagecounterandlikewisewithmyparenttablecontainingallofthetextures I wanttopopthemostrecentoneoffthestackandstorethattextureinmyvectoroftextures.
I getthatinthisbriefdescription, thismightseemquitecomplicated, buttorecap, wefindtheparenttablecalledtextures, andthenweiteratedthroughthattableelementbyelement.
Theelementsthemselveshappentobetablesonthosetablescontainmultipleelementsthroughwhichweiteratedonidentifywhichelementiswhichbymaintaining a counter.
B J filesthatrepresentthebuildingsinthecarsfortheseassetsonstorywho's createdthemand a descriptionofwhatitis a pathtotheobjectfileon a pathto a singletextureusedtotexturethatobjectfile.
Afterstartingthisprojectandpeoplecontributingmodels, I realizedthatmostofthemodelsaregoingtocomebackinallsortsofshapesandsizes, notnecessarilyhow I wanttousetheminthegame.
And I'm goingtostorethesetwotypesofassetsagaininvectorsoneforbuildingsononeforvehicles, theloo.
If I'llworksin a similarway, wecanseethenameofthecreatorofthatobject, whatit's called a pathtotheobjectfileon a pathtoitstexture, alongwithninepiecesofinformationtodescribehowtotransformit.
Loadthoseresources, so I'llgotoourcarcrimecityclass, and I'm goingtoadd a loadAssetsfunctiononthreestandardmaps.
Themapsallowmetoassociatethenameoftheassetwithaninstanceoftheacid, and I havethreedifferenttypes, onewhichis a maptoe.
HoldallthetextureswhichOLCspritesone, whichis a maptoholdthemess.
She's, whicharepartofthethree D extension, nodifferentfromthecodeityourselfthroughtheengineSirisonwhatweusedinPartoneon 1/3 map, whichstores a matrixthatcontainsthattransformation.
Informationfortheredinobjects.
So I'm goingtogiveourcarcrimecityclassaccesstothethree D graphicsextensionontothegamesetting.
Nowthey'regoingtohavethreetypesofdrawing, sowe'regoingtohave a functioncalleddrawerbaseandthat's responsiblefordrawingthecontentsofthecellforreasonsthatwillbecomeapparentlaterintheseries.
I'm alsogoingtohave a drawerAlfa.
It's importantthatwedrawtransparentobjectsafterwe'vedrawnthebaseobjectson, becausethisis a bigprojectandit's goingtogetcomplicatedveryquickly.
WiththeLinkassetsfunction, wecanseewe'rejustpassingreferencestothemapsoftheassetswecreatedearlierfortextures, meshesandtransforms a cellonitsownismeaningless.
Itneedstobelongto a collectionofcellswhich, fortunatelyforus, definesthecity.
So I'm goingtocreateanotherclassthat's actuallydefinesourcity.
I'm goingtocallit C Citymap, andit's importantthatthecellknowswhichmapitbelongsto.
So I'm goingtocreate a secondconstructor, whichisgoingtotake a pointertothecitymaponitslocationwithinthatmaponourforwarddeclarecitymapbecausethecitymapisgoingtocontaincellswhichcontainpointerstothecitymap.
Sowe'vegot a bitof a circularreferencegoingout, and I wantthepointertothecitymaptobeaccessibletoderivedobjectsofthisclassbecauseotherwisewewon't beabletocalculatetheadjacencycellexistinisolation.
So I'vechangedtheconstructortopassinthewidthandtheheight, but I'm alsogoingtopassinthemapstoourassets, andit's goingtoneedaccesstothesemapsbecauseit's goingtoconstruct a defaultcitywhichmeansitneedstoconstructallofthecellsandthecellsneedaccesstothesemapsinordertodrawthemselvesandbehaveappropriately, I'm goingtohavesomerathermundanefunctionssuch a savingandloadingcities, gettingthewidthandheight, getting a specificcellonreplacing a specificcell.
I'm notgoingtogointodetailonhowthoseoperate, butfundamentallywemaintainthearrayof P cells.
Here.
I'llhavetwomoremethodstocreatethecity, whichisreally a mirroroftheconstructorondestroythecitytofreeupallofthememorythatwe'veallocatedinthecitymapCPPfile.
I'm notbotheringwithsavingorloadingcitiesjustyet, butherewecanseethereisanerrortoseecellplane, andthat's becausewe'venotcreated a derivedcelltypecalledPlain.
Solet's dothat.
That's at a newclasscellplaneonitsgoingtoinheritfromthebaseclass.
Justseecell.
Sincethisclassdoesinheritfrom C cell, I'm goingtoimplementthefunctions I wanttooverride, whichinthiscaseislinkassetsupdatingon a coupleofthedrawingfunctions, andit's taken a longtimegettinghere.
Butnowwecanseewhylinkingtheassetsis a goodidea.
Thiscellplanerequires a certainsetofassetsinordertodrawitselfappropriately.
What I'vedoneisaddedtheMountSelectionfeatureherewith a functioncalledGetMouseongroundoninUnusualupdate, dependingonwhetherthetabkeyhasbeenpressed, wereineditmodeornotbeforeaneditmode.
Nowthat I'vegotthemousewillso I canholddownthemousewheeltomovethescenearoundandzoominandoutbyscrollingitinmuchthesameway.
Inthepreviousvideo, I workoutwhatthevisibleextentoftheuniverseison.
I updatethecellsforthatvisibleextent, andthen I starttorenderthescene, create a renderingpipelineononelittlenewfeature I'veaddedtothethree D graphicsengine, which I willgointo a fewmorevideosaboutindetail, whichisthelightingenginethat's beenaddedtothat.
Sonowyoucanaddinseverallightsourcesaswell.
Andthen I starttorendertheobjects.
Remember, I havethreedifferenttypesofrenderingcallforanobject.
So I scrollthroughthevisibleobjectsandrenderthebasepassingalongreferencestothepixelgameengineonthepipelineuseforthethree D rendering.
Then I renderobjectsthatmaycontainsomeAlfacomponentsbecausetheyneedtobedrawnontopofexistingobjectsonifwe'reineditmodeexclusively, I'm alsogoingtocallthedrawerdebugfunctionforthecell, sotheseareallfourloopsdoingexactlythesamething.
Thisistheonecreatedfromtheparametersintheloofile, withthenapplythatcombinedtransformationtotherenderingpipelineonifithas a textureornot, wedecidedontheappropriaterenderingmethod, andthat's it.
ButwaterdoesinvolvedrawingintheAlfafacebecausethesearethewallsofthewaterandthewaterlevelitselfsitshalfwayupthewallsonitstransparent, sowecansee a littlebitoftheworldbeneaththewater.
I wrotedetailedlist, but I willhighlightitjustsoyoucangoandhave a lookatityourself.
Andso, given a setofselectedsells, theusercompress a keytodeterminewhatthosecellsbecauseinthiscase, iftheypress G, wegothroughallofthecellsintheselectedcellsetonreplacethemwithgrasscellsrememberingtolinktheassetstothenewcell, weflaggedthatthemaphaschangedbecausewemayneedtogetthecellstoupdatethemselvesbasedontheirneighbors.
We'lldraw a testpatternthatwillchoosealloftheroadsectionsfivebyfivegridSowegetalltheTIjunctions, allthecorners, verticalhorizontalon a crossroad, notpressthe R keyonit.
I'm goingtoassumethatanythingthatmovesaroundisgoingtostayon a trackthatfollowstheprofileoftheroad.
I'm goingtoassumethatallthethingsthatmovearoundaregoingtofollow a tracklike a railway, socarsandpedestrianswillfollow a particularpatharoundeachroadsection.
Soforthiscornersection, we'vegot a pieceoftrackthatbehaveslikethison a pieceoftrackbutbehaveslikethis.
That's thehandle.
Thecars.
Wealsohaveadditionaltracktoehandlethepedestrianson a smalloneinthiscorner.
Sofarforthiscorner, we'vegoteightpiecesoftrackbecause I'm goingtodefine a trackasbeing a straightlinebetweennodes.
Andsowhatweseehereforthispedestrian.
Wehave a notehereand a noteherefortheroadandnoteherefortheotherlaneand a noteforthepedestrianinthatcorner.
But I'm alsogoingtohave a notethatthecellboundariesstrangesectionsofroad a bitsimpler.
Theyhave a singlepieceoftracklinkingoneedgetotheother.
T junctionsofferseveralpossibilitiesforthecarsonthepedestrians.
Inthisinstance, however, justgivingitfreereinlikethiswouldbecatastrophicbecausecarswouldbecominginontheirwouldbecirclingaroundhereandmovingupdifferentroads.
Since I'm Britishand I driveontheleftoftheroad, if I havecomeinfromthissideofthejunction, theonlyoptionsavailabletomearetoimmediatelyturnleftortokeepgoingstraighton.
If I wantedtodo a cuter, I couldturndownwards.
But I'm not.
That's goingtobebreakingtherules.
So I needsomethingtotellmethatthisparticularrouteisinvalid.
Likewise, let's say I havenowtravelledtothisparticularnote.
I can't turnleft, sothatrouteisinvalid.
I cangostraightonor I canturnright.
Well, let's suppose I chosetoturnrightatthisnote.
Theonlyoptionavailabletomeistocontinuegoingdown.
I don't wanttoturnintotheopposinglaneoftraffic, sothatisaninvalidoptionsetting