Non-Euclidean Game Tutorial

Материал из Поле цифровой дидактики
Описание Код решений, которые используются при создании игр типа «Неевклидова игра». «Неевклидова игра» — это то, что разработчики игр часто называют игрой, в которой мировое пространство не работает так, как работает реальный мир. Например, размещение огромной комнаты в небольшом пространстве или подъем по лестнице опускает игрока на уровень ниже. Возможности безграничны.
Область знаний Информатика
Область использования (ISTE) Computational Thinker
Возрастная категория 12


Поясняющее видео https://www.youtube.com/watch?v=2It TEuDC5w
Близкие рецепту понятия
Среды и средства для приготовления рецепта: Scratch

Пример проекта

Видео

Scripting

Sprites

First, two sprites need to be created: the Player and the Walls. Make the player a 27 x 27 cube. Then, make two costumes for the wall.

Scripts

Now that these sprites have been created, there needs to be some logic. A basic scrolling engine will be used. First, create these global (for all sprites) variables:

SCROLLXSCROLLY

Then, in the Player and Walls sprite, create these variables (for this sprite only):

xy


Back to the Player sprite, create these scripts:

whenclickedThisistheonlygreenflagblockintheproject.broadcastinitandwaitThisiscompletedbeforetheprojectstarts.broadcastgameonwhenIreceiveinitThisallowstheplayertoresetthepositioningsetxto0setyto-50setSCROLLXto0setSCROLLYto-50whenIreceivegameonThisstartstheonlyloopintheproject.forevertickbroadcasttickandwaitThissendstheloopovertotheothersprites.enddefinetickRunwithoutscreenrefresh.ifkeyuparrowpressed?thenchangeyby5Thisisacustomblock.endifkeydownarrowpressed?thenchangeyby-5Thisisacustomblock.endifkeyrightarrowpressed?thenchangexby5thisisacustomblockendifkeyleftarrowpressed?thenchangexby-5thisisacustomblockendpositionchangeSCROLLXbyroundx-SCROLLX/5ThesesettheSCROLLXandSCROLLYtotheplayer'sposition,allowingtheotherspritestomovewhiletheplayerisstationary.changeSCROLLYbyroundy-SCROLLY/5definepositionRunwithoutscreenrefresh.gotox:x-SCROLLXy:y-SCROLLYdefinechangexbysxRunwithoutscreenrefresh.changexbysxpositioniftouchingwalls?thenWalldetection.repeatuntilnottouchingwalls?ifsx>0thenchangexby-1elsechangexby1endpositionendenddefinechangeybysyRunwithoutscreenrefresh.changeybysypositioniftouchingwalls?thenWalldetection.repeatuntilnottouchingwalls?ifsy>0thenchangeyby-1elsechangeyby1endpositionendend

Now, in the Walls sprite, add this local (for this sprite only) variable:

in/out?

With this variable, the non-Euclidean logic can be created:

whenIreceiveinitSetthevariablestotherightvalues.setxto0setyto0setint/out?tooutswitchcostumetoshortsetrotationstyleleft-rightpointindirection90positionx-SCROLLXy-SCROLLYwhenIreceivetickruninthelooppositionx-SCROLLXy-SCROLLYdefinepositionxyRunwithoutscreenrefresh.setsizeto200%Makingthespritebiggerwhenitmovesallowsforsmootheroffscreenscrolling.gotox:xy:yifx=xpositionandy=ypositionthenin/outdetectionshowelsehideendsetsizeto100%definein/outdetectionRunwithoutscreenrefresh.ifin/out?=outthenDetectiftheplayerisin,ONLYifitwaspreviouslyout(helpswithlag).ifxposition<145andabsofyposition<13thenswitchcostumetolongsetin/out?toinendendifin/out=inthenDetectsiftheplayerisout,ONLYifitwaspreviouslyin(helpswithlag).ifxposition<145andabsofyposition>12thenswitchcostumetoshortsetin/out?tooutendend

A non-Euclidean game has been created. This basic logic can be applied to any form changing tunnels.