Oh, oddlyenough, fromtheplatformgamewalkingaround a mapon, wecanseeherethatDariocan't overlapwithanythingthat's inthemapthatwe'reconsideringstaticonwhatthisvideoisgoingtobeaboutisintroducingdynamicobjects I eat.
Inthemostbasicsense, anythingthatmoves, wecanconsider a dynamicobject.
But I'm goingtoextendthis a littlefurtherthatanythingthatisn't staticorbackgroundisgoingtobe a dynamicobject, andwe'llseelateronthatthiscaninvolveeventtriggers.
Soallofourdynamicobjectsaregoingtooccupy a singletileinthegame, althoughtheyarefreetomovein a continuousdomain, sothey'renotgoingtokeepthemlockedontoparticularcellboundaries.
Soit's startwiththebasics.
Weknowthatwe'regoingtohavetohave a positionforourdynamicobjects, whichisgoingtobean X and Y coordinatesfloatingpoints.
Weknowwe'regoingtoneed a velocity, whichwillupdatethepositionsdependingontheelapsedtime.
Forexample, Dariocan't walkthrough a treeor a building, However, thingslike a birdor a batmightbeabletoflyontopofthings, sowedon't alwayswantthingstobesolidagainstthemap.
Forexample, ifthedynamicobjectisfriendlyanditinteractswith a friendly, dynamicobject, thenprobablyit's a conversationorsomething.
Somethinginterestingisgoingtohappen.
However, ifoneofthemisfriendlyandoneofthemisnotfriendly, it's mostlikelytheintentionwasanattacksowellwanttohandlethisdifferently, dependingonthefriendlystateofourdynamicobjectontheway I'm goingtostriptothedynamicobjectistohave a baseclassdynamiconforthingsthatmovearoundandperhapshavetheirownbehaviorsweregoingtoinheritfromiton.
Callitdynamiccreatureonbecausewemaywanttospecifytheindividualbehaviorsof a dynamiccreature.
We'regoingtobechangingthisbecausetheplayerobjectisindeedgoingtobe a dynamicobjectto.
Sothismeanswe'llhavetomakequite a lotofchangestoourournewsupdatefunctiontoaccommodate a newarchitecture.
Thegoodnewsis, we'vealreadygotstaticcollisions.
Don't we'lljusthavetorefactorit a littlebittosuitthenewarchitecture, butwe'llalsoneedtoadddynamiccollisionsSothisiswhendynamicobjectsinteractorcollidewithotherdynamicobjects.
I'm justgoingtoprototypethefunctions, soweneedtheconstructorwe'llputin a D structureto, and I'm goingtoaddsomepublicproperties, soweknowweneedthepositionPXandwhywentafterVelocityVXon V Y.
I'm goingtohavethethreebillions I discussedearlierwhenwe'llcallthatbesolidversusmapsolidversusotherdynamicsonwhetherornotthisdynamicobjectisconsideredfriendly, I'm alsogoingtoinclude a typeofstringtonamethedynamicobject.
Anditalsobecomes a gamedesignelementbecauseitwillbeeasierforthepeoplewritingthescriptforthegametoworkwithobjectsthathavesensiblenames.
Andwe'vedonethatforthespritesalready.
Stringisn't declaredyet, butwe'llcomebacktothatin a minute.
Now I'm goingtoaddsomebassmethodsonthesearegoingtobeoverridden, sowe'regoingtoexploitinheritanceandpolymorphism a lotinordertofacilitatethedifferentbehaviorsoftheobject.
Sowe'llstartbycreating a virtualfunction, andthismeansitisourintentionthatwe'regoingtoallowthisfunctiontobeoverwrittenon.
I wanttostorepointedtothespritethatwerepassingthrough, and I alsowantsomeadditionalproperties s sowecanassessthestateofthecreatureonwillassumebecauseit's a creaturethatit's alive.
I'vegotthederivedclassdynamiccreatureandthisiswherewecanstarttohave a littlebitoffun I havedecidedinadvanceoff a formatandlayoutof a spritesheetforallcreatures, anditlookslikethishere.
We'vegotindividualsprites, whichis 16 by 16 pixelson.
I'm usingthisstrikeviewerthatthecommunitycreated.
Wecanlookatthemindividually, butwe'llsee.
Thefirstcolumnisthespritewalkingdownwards.
Youseetheanimationinthetop, rightoftheimage.
The 2nd 1 isthespritewalkingtowardstheWest, andwe'vegotnorth.
And, ofcourse, intheexdirectiononifwe'vegotah, onesheetoffsetintheUAEdirectionwithmoveddowntothenextrowofSprite, so I'lluse a switchblocktodeterminebasedonthestatehowwesetthatthesevariables.
Wejustneedtotakeintoaccountwherethecameraislookinginworldspaceonthesheetoffset X andoffsetwhyvariableswillgiveusthetopleftof a particulartileinourspitesheeton.
Andinsteadofhardcodingin a dynamicobjectlikethis, we'regoingtouseournewframework.
But I'm notgoingtocreate a creatureoutright.
What I'm goingtocreateisjust a seadynamic, and I'm goingtocallitMPplayerFornow, it's a pointerto a dynamicobjectthat's goingtorepresenttheplayerjustforthosethinkingahead.
Wewillbechangingthis a littlebitlateron.
I'm goingtousethepolymorphismnowtotakeour C dynamicplayerobjectandfromthatcreate a new, dynamiccreatureobjectwhichneeds a name, andwe'llcallthisoneplayer.
Anditalsoneeds a sprite.
Sowe'lluse R.
Singletonthat's managingtheassets.
GetSpriteondhe.
Thedespitealsocalledplayerwith a friendlyname, andyou'llseethecompilerhasnoproblemwiththis.
EventhoughMPPlayerisofType C dynamicwerebasicallytellingit.
Insteadofdrawingtheobjectusingthedrawer, partialSpriteroutinewillgettheobjecttodrawitselfusingitsdrillcellfunctionandsowejustneedtopass a pointertothecouncilgameengine.
So I usedthethiskeywordforthat, andweneedtopassinthecameraoffsets, whichismuchTidier.
Sowe'vegot a dynamicobjectwhichrepresentsourplayer.
Butlet's saywewanttomovetheplayerto a certainlocation, presentsomedialogue, movetoanotherlocation, presents a moredialogue, waitfor a minute, dosomething.
There's a sequenceofeventsthatwecanperforminordertofacilitateplotandgivethegamesomeatmosphere, sowemightwantthecharactertobeabletowalkto a differentlocation.
Soifwe'regoingtowalk, too, weknowthatwe'regoingtohavean X and A Y.
We'regoingtowait.
Weknowwe'regoingtohavesomedurationinseconds.
Let's saywewantthecharactertosaysomething.
Well, weprobablywanttoshowsomedialogue.
Therebesomesortoftext.
Whatweneedis a programwithin a programontheway I'm goingtodothisistocreateobjectswhichrepresentcommandson a queueofthesecommandsissenttowhat's oncallingthescriptprocesseron.
WheneverthescriptprocessERhassomethingtodo.
Itstopsplayerinputandsurprise.
Surprise.
We'regoingtouseobjectorientedprogrammingtoehandleallofthisforus, So I'm goingtoneed a basicclasscalledCommand, andcommandsaregoingtobetemporarilyincontrolofsomethinguntilthecommandhasbeencompleted.
So I'm goingtocreate a flagcompletedonallowedtomethods.
Thiscommandstart, whichstartstheprocessofthecommandhappeningand, asusual, willhaveupdateincasethecommandtakes a certainamountoftime.
Weneedthattimetoelapse.
Thiswillalsothentake F elapsed.
Timetoimplement a cooksequencewillqueueup a sequenceofcommands.
This Q isfedintothescriptprocess, sir, Onthescriptprocess.
Sowe'llhave a veryaccessibleflagtodenytheplayercontrolifnecessary, I'm goingtoaddtointerfacefunctions.
Thefirstisatcommand, whichissimplygoingtoaddaninstanceof a commandtothelist.
Andthesecondisprocesscommands.
Becausecommandsare a temporalthing, they'renotjust a singleevent.
Ittakestimefor a commandtowalk a dynamicobjectfromonelocationtoanother, so a commanddoesn't justhappeninstantly.
Onit's finished, ittakes a duration.
Solet's havethesimpleonesfirst.
We'vegot a constructorforourscriptprocess, sir, andwe'vegotaddcommand, whichisjustgoingtopushthepointerto a commandobjecttothebackoffthelistofcommands.
I'm goingtocallitmovetowhichisgoingtowalk a dynamicobjectfromitscurrentlocationto a targetlocationandsocreate a constructiveforthiswhichtakesinthatinformation.
Sothefirstthingwedoistake a pointertothedynamicobject.
Andjusttomakesurethattheuserdoesn't enterinappropriatedurations, I'm goingtotakethemaximumbetweenthedurationspecifiedon 0.1 of a 2nd 1 millisecond, andthisisimportanttoavoid a dividebyzeroerrorlateron.
I alsoofcourse, needtostoreappointedtotheobjectthat's beingcontrolled.
Now, whyhaven't I updatedthestartpositionshere?
Well, simplyput, I don't knowwheretheobjectwillbewhenthiscommandiscalled.
That's whywehavethisstartfunction.
If I'vegot a sequenceofmovements, I needtomakesurethatonemovementisfinishedbeforethenext.
SotheobjectslocationwillhavechangedIf I justspecifiedtheobjectsstartinglocationassoonas I createdthelistofcommands, well, itwillhavecapturedtheobjectsposition.
Atthattime.
I createdthelist, whichcouldbedifferenttowhenthiscommandiscalledduringtheexecutionofthatlist.
Sothestarcommandhappensonceandsays, Take a snapshotofwheretheobjectisnowon.
I'm goingtocreate a singleinstanceofourscriptprocessorcalled M Scripttotestthetheory I'm goingtoohardcode a littlescriptinplacewhenevertheuserpressesZedkey, sowe'lllookforthatevent.
Andbecausewe'vegot a commoninterfacebetweenthesedifferentobjects, theycanallhavedifferentbehaviors.
Nowweknowittakes a pointedto a command, so I'm goingtohavetousethenewkeywordbecauseweknowthescriptprocessalsodeletesandcleansupthecommandsonceit's donewiththem.
Sointhiscase, it's a movetocommandontheobjectthatwe'regoingtomoveistheplayeronforthefirstcommand.
I'm goingtomovetheplayerto 10 10 and I wantthattotakethreeseconds.
Soeventhoughwe'veadded a completelydifferentmethodofcontrol, thegameengineitselfissortingoutwhat's necessarybehindthescenestofacilitatethetypeofanimationswewant.
Okay, sowehave a singlecommandmove, too, andwehave a singledynamicobjectcreature.
Let's makethecodehandlemultipledynamicobjects.
I'm goingtostallmydynamicobjectsin a vectorandintheunusedcreatefunction, I'm goingtocreate a fewmore.
SoLet's giveittheSkellyAssetand I wanttomanuallyfornow, positionthesehurtsomewhereinthescene.
So I setoneatbeingat 12 12 andanotheronebeingat's fivecommaeight.
Ofcourse, thesearecalledandplayeranymore.
There's somethingelse, infact, weaken.
Temporarilycreatethemhereas a C dynamicuponeNCdynamicBob, too.
What I'm goingtodoisaddthestothevector, and I'm goingtostart a conventionthattheplayerobjectisalwayselementzerointhisfactor.
So I'm goingtopushbacktheplayerfirstandthen I'lldotheothertwo.
AndthisislittledesignConvention, whichwillseeisquiteusefullaterwhenwe'restartingtoimplement a questsystemondhehandlingmapsfullofdifferenttypesofdynamicobjects.
Ifwealwaysknowwheretheplayeris, thenthatcouldmakethings a loteasierlateron.
So, ofcourse, weneedtohandlethings a littlebitdifferentlynow.
Weneedtoputallofourupdatecodeforobjectsin a looponwilluseanautoforLukeforthis, whereeachobjectisgoingtobecalledobjectsthat's goingtogothroughourvectoroffdynamicobjects.
Wehadtodonoadditionalcode, eventhoughit's a differenttypeofobject.
Solet's wrapthisvideoitbyaddingonemorecommand, andthat's goingtobetodisplaydialogueonthescreen, and I'm notgoingtolinebylineit, but I'llexplainhowitworks.
Sowecreate a subclassoffcommandcalledshowdialogue, andthisisgoingtodisplaytexttotheuseronthewayit's goingtowork.
Well, theconstructorjusttakes a localcopyofthatvector, butthestartfunctionneedstodosomething a bitspecialbecauseit's thegameengineresponsiblefordrawingthings.
Thedialoguewasbeingshown, and I'm goingtocreate a Booleanflagthatsayswhetherthereisdialogueonthescreenatthemomentandthisisquiteimportantbecausedialogueisoneoftheonlycommandsthatwedon't don't haveanycomputercontrolover.
Soreally, allthisfunctionisgoingtodoisdraw a backgroundrectangleof a sizeappropriateforthedialoguethat's beengiventoitnowbecauseeachlineofdialogueis a separateelementinthefactorthat's passedtoit.
I canworkouthowmanylinesofdialogue a displayedonthescreenbylookingatthesizeofthevector I can.
Thenit's a ratethrougheachelementofthevectortoeworkout.