Ofcourse, I amtalkingclassicretrosnakereallyhereintheconsolesoyoucansee a snakehereon I'm stealingfromthesnakesperspective, whichcouldbequite a controversialwaytodosnake.
Yetonthetitlegameontheplayerscurrentscore, thislawsuitwas a littleboundaryofthetopofthescreen.
Thenextthing, ofcourse, istodrawthissnake, andthisisquiteeasywiththealsokeyword, becausethesnakeis a littlelistorwedoisliteratethroughthelist, takingthecoordinatesofeachbodysegmentondrawingitaccordingly.
Now, inthiscase, I'm usingthebedeadflagtodraweithertheskeleton, whichisgoingtoplussymbolor a segmentofthesnakebody, whichisgoingtobe a capitalin a verysimilarstyle.
I'm goingtodrawthesnake's headonforthis.
I justtakethefrontelementsoffthelinguistusingfrontmethodhereonthe X and Y coordinatesonin a similarway, I usedtobedeadvariabletotellme, Shoulditbe a capitalexploringthesnakeisdead?
Wetakefood X and Y coordinatestranslatethem, aswe'vedonewithallofthesedrawingmethods, from a twodimensionalcornersysteminto a onedimensionalforthescreen.
Likeallofmyothercounselapplications, I liketomakeliberaluseoftheGet a sinkkeystatekeyWordisthiswillretrievetheimmediatestateofftheleftandrightarrowkeys.
Thesearethecodesforitontheseotherconditions I justtalkedabout.
Ifthesnakeisgoinginthedirection, I wanttotakeonefromthe Y coordinatesofthecurrentfrontofthesnakeandyoucanseehere I'm usingtheinitializinglistasonargumenttokeepthecoatconcise.
Sothisiswherewe'recheckingIftheheadofthesnakewhichremember, isalwaysthefrontofthelittlelistiswithintheboundariesthatwe'vedefinedasbeingthegamingarea, inthiscase, the X axis.
It's justbetweenzeroandthescreenwetsuits.
Thewholeweightoftheconsulonforthe Y axisisbetweenthreeandthescreenheight.
That's because I'vegottheborderandinformationonthetopofthescreen.
I don't wantThioallowedthesnaketogoontopofthatinformation.
Thisiswherewehavetothink a littlebitaboutthegamedesignhere.
Wecan't justrandomlychooseanywordtoputthefood, becauseifweputitinsidethesnakesbody, well, I guessit's a philosophicaldebatehereastowhetherthegameisrelevanttotall.
Butifyoucanimagine a playerhasbeenplayingforfiveorsixminutesofsolaris a verylongsnakenowthatplacingthefoodwithinsidethesnakewouldbeveryinfirstplace.
I guessonesolutioniswecouldalwaysputthefoodwherethesnakehadlastbeenbecauseweknowthatitstailwillleaveanemptyspace.
Ofcourse, thiswouldlooklikethesnakeisgoingtobeeatinghisownfecesonprobablydoesn't make a veryclevergame, becauselateron, whenthesnakeismany, manyloopswereprobablyguaranteeingthatwe'reputtingthefoodinthespaceofthesnake.
Neveraccess.
Regardless, whatevertheapproachofchoosingwheretoputthefood, thenextthingweneedtodoisgrowthesnakebecauseit's a littlelist.
All I'm goingtodoisduplicatetalebyanotherfivesegments.
wegetondhewhilst I'm basicallycreating a timepointhere.
T oneGettingtheimmediatetypeontheconditionfrommywalletisgoingtobethat a durationcreatedbysubtractingthecurrenttimebytheonethat I'vestoredislessthan 200 millisecondswiththenextnicebracket.
Itdoeslooklikeit's controllingnormally, andif I rapidlydoubletap, I couldgetthesnaketoimmediatelygoback.
Soand, ofcourse, if I rapidlytripletap, thesnakewillcompletelycrushintoitself.
That's okay.
I thinkthisrewardstheplayerwouldbeprecisewiththeirinputs.
Thereisonefinalthing, which I thinktheplayermightbe a littlebitwaryoff, andthatisthegameishardthatwhenthesnakeismovingopendownratherthanleftrightbecauseoftheaspectratioofcommandproblems, wecanseethatmovingvertically, thesnakemovesmuchfasterthisgivestheplayertheperception, havinglesstimetomake a decision.