Sowecanassumethatsell X isequaltothemouse's location.
X interviewdividedbythetileswidthandit's theinterviewdivide.
That's importantbecausethatwillgiveus a wholenumberanddiscardanyremainderispartofthedivision, sothatwillalwaysgiveus a locationthatrepresentsthecellconvenientlyweaken.
Sothiswillgiveus a offsetinscreenpixelsofhowfarthemousecoordinatesisintothetile.
Andnaturally, wehave a correspondingforwhy.
Sometimesit's helpfultonormalizethisvaluebydividingaswellbytilewhippedandtellheighttogiveus a valuebetweenzeroandonetorepresentwherethemouseiswithinthecell.
Andifweknowtheoverallwidthofourworld, thenwecaneasilytakeourcells X and Y locationandconvertthatinto a onedimensionalindexintoanarraythatrepresentsthisworld.
I'm justgoingtodraw a rectangleatthecell's location, multipliedbythesizeofthetile, and I'm alsogoingtothrowinsomeonscreentextsowecanvisualizethecoordinates.
Sohereyoucanseeas I movethemousearound, a screamcellisselected, andif I movedtothetopleft, itevensayssell 00 Thisissomethingwe'vedonemany, manytimes.
As I moveuponeinworldspace, I havedeckremittedinboththe X onDwightaxesandas I movedownwards, I'veincriminatedinboththe X and Y axesinworldspace.
As I moveleft, I haveDeckermintedinthe X axis, butincrementIDinthe Y axis, andas I movedright.
I'veincrementIDinthe X axis, butdeckremittedinthe Y axisasbefore, we'regoingtoneed a transformationthattakesournowscreencellspacecoordinateandtransformsitinto a worldcoordinate.
Andagain, it's a multicomponentequationasboth X andwindscreenspacefactorintotheIndividual X's and y's inourworld.
WecanseethatourWorld X coordinatedirectlyalignswithourcell.
Whycoordinatesotakingtheoriginintoaccountaswell?
WeknowthatWorld X isgoingtobereliantonSeewhy, minusoriginwhywealsoseethatourworldexcornetdirectlyalignswithourscreen X coordinate, whichisveryconvenient.
Sowecansimplyaddthataswell, andin a similarfashionwillcalculatethetransformationforwhy, injustthesameways X, weseethatourworldswhyvaluesaredirectlyinlinewithourscreencell.
Coordinateaccordinglytoeitherincrementordecklamentalongthe X axisor Y axis.
Thereareseveralapproachestothis, andyoumayexpect, becauseofthenatureofthischannelthatwillnowdosomegeometryandlookatlineintosectionequationsandwhichsideoftheline a pointlies.
Butno, I'm goingtoreallybruteforcethis, and I doitbycreating a cheatingtile.
Sohere I'vecreated a solidtileisthesamedimensionsasmyotherisometrictiles.
Buttheregionsinthetopcornersareidentifiablebyuniquecolor, andsincethistilerepresentsanonscreencellon, I knowtheoffsetofthemouseintothiscell, I candeterminequiteeasilywhichcornerofthecellmymouseliesinjustbylookingatthecolorbysamplingthatspriteatthatlocation, we'vealreadygottheoffsetintothecellofthemouse, so I'm justgoingtocallthegetpixelfunctiononthesource.
Spiteatthatlocation.
It's offset a littlebitbecausethiswas a spikecontainingallofthesprites, butit's samplingfromtherightlocationtogiveme a pixelvalue.
Andthenonce I'veworkedoutwhatmyselectedcellis, I'm goingtomodifythatlocationbylookingatthereturnedpixelcoloronadjustingthe X and Y valueaccordingly.
Let's take a look.
Sonowwecanseeasmymousegoesintothecornerofthescreencell, it's selectingtheappropriateworldcellunderneathit, andtherefore I canputmymouseoveranywhereintheisometrictilearrayondhe.
There's nothingespeciallyclevergoingonhere, but I willdrawyourattentiontothespritesthatexistalongthebottomoffTheimagethesspritesareeffectivelytoisometrictileshigh, so I needtooffsetitbythatbefore I drawittomakesurethattheydrawitinthecorrectlocation.
Because I don't wanttojustdrawthetophalfofthistreewherethetileshouldbe.
Andso, ifthetileit a particular I d hasheight, I'm takingthatintoaccount.
Andso, finally, wecannowclickon a particularcelltocoloritinonthemoretimesweclickon a cell, weincrementthecells.