Uh, we'regonnaneedtodraw a fewotherthingsonthescreenthatwe'llwe'llgettolater.
Okay, Sodrugraid, let's moveintothisone.
Now, whatweneedtodohereislikedraw a grid, whichisprettyeasytodo.
Sowhatwedoisweweregivenroseandsurface, soit's probably a goodideaif I actuallypassedintheroseandsurface.
So I'm justgonnaglobalthemheresothat I canreferencethem.
I thinkthisisgonnaworkwiththeglobalroseandwith, likethat.
Andherewealsoneedtomaketheseglobalbecause I don't passthem.
Andeverytime I draw a grid, we'regonnasaywithuh, andRoseAndthisheightvariableisactuallynotnecessarybecausewearejustgonnadraw a squarelike a squaresurfaceeverytime.
Sowecanjustmakethisthesame.
Wedon't needtwovariablesherewithinheight.
Doit.
We'regonnacontainthesamenumber.
Andwe'resoglobalwith.
AndRose, I gohere, drawgridgivenwithroseandsurface.
Whatwefirstneedtodowhenwe'redrawing a gridiswewanttofigureouthowbigeachsquareinthegridisgoingtobebecauseofwhatwe'regonnadoiswe'regonnajustdrawlinesgoingdownandacross, butweneedtofigureoutwheretodrawthoselines.
Sotodraw a lineinpiegame, allwehavetodoispregamedotdrawdon't wind.
Andtheargumentsthattakesis a surfaceweneed a coverinthiscaseisgonnabewhite.
Soyou 2 52 55 to 55.
Whitesweregonnadrawat X zerocomma X w and I'llgothroughthisinjustonesecondwhatthisdoes, and I'm gonnacopythisanddrawonemoreandthenexplainhowthisisgonnaworkprettywell.
I probablymistakehere, butwe'llruntheprogramtoseeifeverything's working.
NamedWinisnottofindWindowPhil s.
So I'vecalledthiswin.
Onereallyneedstobesurfacelikethat.
Soit's tryingout, andtherewego.
Weget a nicelittlegridonourscreen, likeso 20 by 20.
Great, theywere.
Sonowlet's moveintoanotherfunction.
Oractually, let's startcoatingontheclasseshere.
So, like I wastalkingaboutbefore, we'regonnahave a snakeobjectwhichisgonnacontain a bunchofcubeobjects.
Soessentially, whatwe'regonnadoiswe'regonnahave a listofcubeson, andthat's gonnabeknownasthesnakebody.
Solet's goaheadandwritethatin.
Now.
What I wanttodoforthatisjustcreate a list.
Sowe'rejustgonnasaybodyisequaltoandthen a blinklist.
I'm alsojustWell, we'realreadyuphereandcreating a classVerywell, I'm gonnacreateturnsisequaltoAndit's justgonnabethissetofsquigglybracketsherethatwillwillgetintoin a bit.
And I'm justgonnasay, if I actuallydon't evenanotherifbecausetheway I'm gonnadothisis, uh, thisotherwayyoumighthaveseeninpowergamebeforetomovethingsaround.
Ifwewanttoknowrightnow, youmakeourexpositive, whichwouldbeoneinthiscasebecausewe'regonnamoveonecubeat a timetogofurthertotheright.
Samethingwiththewhy.
It's kindofweirdinmygame, howthe y worksbecausethemorewhyyouadd, thefurtherdownyougosowe'lldothesameforexperienceitselfduring X equalsnegativeoneagainstmovingleftandwe'regoingtosetourjourney.
Whyequaltozero?
Andthisisbecauseagain, wedon't havebeenmovingintwodirectionsatonceandbegoingdagonowthisiswhat I wastalkingabout.
Um, and I canalsojustputLFhereaswellbecausewedon't wannabeabletomoveinmorethanonedirection.
We'regonnaprioritizetheleft A rakhi.
Ifthey'renotlookingleft a rookie, thenwe'llcheck.
They'redoingtheright.
Otherwise, up.
Otherwise, downbecausewedon't wantthemtobuild a clickmorethanonekeyatonce.
Sonextweneedtoactuallymoveourcube.
Andthisiswhereitgets a littlebitmoretrickyintermsoflooking, whereareCuba's?
Andifit's atthatturn, thenwe'regonnaturnit.
So I'm gonnastartcoatingthat.
I'm kindofgonnagothroughexactlywhat I do.
Sobefore I seein a numeratorand I stopthereandgetmelikethat's innovation, sayselfdoubtbody, we'regonnalookthroughthelistofpositionsthatwehaven't onsteakandsay p equalseatopposition.
And I'm justgonnacopythis, bytheway, that's whatthislittlearrowdoeshere.
Itjustmakes a copysothatwe'renotchangingthepositionofoursnakewhenwedothingswhichjustjustfollowalongwithit's notsuperimportantcase.
We'llsayif P isinselfdotturnslikethisbecauseremember, whatwedidisweaddedthepositionofourheadtoterms.
And I wasgonnasaysodon't movelikethisandturnzeroturnedonelikeSoOkay, now, next I'm goingtosayIf I equalsequalsthelengthofselftaughtbodyminusonegoose, Then I'm somethingofyourself.
I don't knowwhythat's capitalitselfturnsdotpump, so I know I justdid a lotofcodinghere, andthisprobablydoesn't make a lotofsense, youguys.
So I'm gonnakindofrunthroughexactlywhat I justdid.
I wanttocallit a snackfortheforthecubetocollectforthesnaketocollect.
Sowewanttochangethecolorwiththat.
Andyouspelleditwrong, likethreetimesduringaccent.
Andwhythereason I haveduring X you'resettoeoneinitiallyisbecause I wanttomakesurethatwestartmovingin a direction.
If I hadthisatzero, youwouldhavetoclick a keybeforethesnakesaretraining.
But I wantrightwhenweruntheprogramforthesnaketojuststartmoving.
So I'm settingitalreadywith a direction, axeandthereasontheseareoptionalagain.
It's sothatwhenwecreate a newcueobject, wedon't havetobeimplicitlysaydirectionExesonedirection y zerobecauseit's assumedthat's alwaysgonnabelikethatunlessotherwisestated.
Okay, let's have a look.
Whatelsedoweneedtodohere?
Weneedtonowcodethismovefunction.
It's actuallyreallyeasy.
Um, I'm gonnadoiswhat I say.
Sincewe'rechangingthedirectionactsinthedirectionwhyinoursnakeclass, weneedtodothatinheresothatitstayswiththeobjectduring X equalsDay X andthensomething.
Andjustincase I haven't mentionedhere, right, we'reworkingwith a gridsystemof 20 rowsinthisinstant.
Sowhen I saysomethinglike, uh, ifourselftheoppositionislike 13 or 10 10 I'm sayingwe'reinthe 10throwinthe 10thcolt.
I'm notsayingthe X valueisequalto 10 andthe Y valuesequalto 10 becauseit's notinthecaseofdrawingonthescreen, becauseourscreenisactually a widthof 500 pixels.
Butjustwhereweareinthegrade, whichismostimportanttousrightnow, isequaltolikethataboutyoulike 1435 So, justjusttomakethatclearforanyonewhomighthavebeenconfused, Okay, sonowfordrawing, um, it's a littlebitharderjustbecauseofwhat I mentionedaswellisthefactthatweneedtofigureoutthedistancebetweeneach X valueandeach y valuesWonderdrugsmeandpiegame.
Itdrawsinthetoplefthandcorneroftheobjects.
Ifwedraw a cube, we'redrawingthatinthetop.
Leftsomethingtofigureoutwhatthat x and y Buthe's gonnabeforeachcubewhenwe'redrunktothescreen.
So I'm justgonnacallthisgaphere.
Thatisgonnabeourdistanceandthesamething.
Selfdoubt.
W myselfthoughtRoseandwe'regonnachange w androwsofdowninourprogramlater.
Butweshouldjusttypeitinnowlikethis.
502 100.
Justsowehavethatscentcaseherselfthat w answer.
Youdividedmyselfthatroseagain.
That's thesamethingwedidwhenweweredrawingthegridtofigureoutthedistancebetweenour X and Y values.
I'm justgonnacopiedinbecauseit's a littlebitofmathtomakeitthem, like, perfectlyalignedonthesquare.
Um, yeah.
Soyousayif I tzeandwe'resayingourcenterisequaltodistancemodulestobecausethat's gonnabe a center, obviouslyaremuchsortofsaying, dividedbytwoisgoingtothemiddleofourcubeandwe'resayingtheradiusthatsomethingtheeyeradiusisgonnabe, Andthenwegothrough a littlebitofmathyear.
Solet's makesurethatthisworksGlobalRose, likethat's andafterthis, Wouldyousayif I don't knowhow, I justtypethat, butthelengthofand I'm doingsomefancyhereand I'llexplainwhatthisdoesin a second.
Okay, So I know I justtypedthisstuffThatprobablymakesabsolutelynosenseyouguys, ifyouhaven't beenusingpythonfor a littlebit.
Butprettymuchwhatthisisgoingtodoiswe'regonnaget a listof a filteredlist, andwe'regoingtoseeifanyofthepositionsarethesameas, um, likethecurrentpositionofthesnakeprettywell.
Sowhatwe'redoingiswe'resayingthatwewanttomakesurethatwe'renotgonnaput a snackontopofthesnakebecauseifwehave a reallylongsnake, thechanceofthathappensactuallysomewhathigh.
And I didn't dothiswhen I firstgotothegame.
Sowhathappenediswhenyouhaveyoursnakelivingonthescreenallof a sudden, thestackofpopup, butit's likeonthetailofthesnake, whichyoudon't want.
Sowhatthisisdoingandjusttypeitout?
Youdon't reallyhavetounderstand.
ItisWe'resayingthisThisroom's a functionsaidandwe'rejustcheckingifthezeddotpositioneyesequalto X y.
Soifit's equalto X y, whichisthepositionwejustgeneratedherebygettingtorandomnumbers, so x and y, thenwe'regonnahavetodothisagain.
SowesaycontinueandelsewebreaklikethatAnd I'm justgotsimplygonnareturninthetroubleor a tuba.
Larry.
Oh, Nicholas X.
Y Okay, sothisconfusing.
Butyoucandothisin, like, a muchlongerwaywiththefourloopwhereyouprettymuchloopthrougheverypositioninthislist.
Andwecangiveitthecorrectdirectiontobemovinginsoprettymuch, Um, whatwedohereiswejustsaywe'regonnaupend a newcubetoourbodyanditspositionifwe'removingtotheright, whichinherewearebecausethe X equalsoneisonelessthantheexpositionofthattail.
Sowhateverthelastcubeisonelessonthatandthat's sothatwedon't add a Q persetotherightwhenwe'removingtotherightandthenwe'rejustgonnahaveoverlappingcubesandyou'regoingtoseethem, right?
Soallweneedtodonowiswritethatresetmethodandthenweneedtojustsimplychecklikewhenwelose a greatNowthesnakecangothrougheachotherthroughitself, andyoucanseewehave a hugeairwhenthesnakecancoatthroughitself.