!"#$ &'() '*+ ,$-.

/$ 0(+ 1"-$2

1hese lnsLrucLlons wlll Lalk you Lhrough how Lo make your own 1emple 8un game
wlLh your puplls. 1he game ls made ln ScraLch, whlch can be downloaded here:
hLLp://scraLch.mlL.edu ?ou wlll also need Lo have downloaded Lhe lmage pack
conLalnlng all Lhe graphlcs requlred Lo make Lhe game. 1hls ls avallable from

ln maklng Lhe game, puplls wlll learn abouL conLrol lnpuLs, varlables and condlLlonal
sLaLemenLs. 1he screenshoL below ls off Lhe compleLed game wlLh Lhe 1emple 8un
characLer [umplng a hole! 1he alm of Lhe game ls for Lhe runner Lo run for as long as
posslble wlLhouL falllng down a hole and Lurnlng lnLo a ghosL!

!"#$% '(%)$ *(% (+(#,%-".* ".%/ 01#2%1- %-2% 3()'' .((4 %/ 526( %-( 7(58'( 9:.

3,45 67 Cpen ScraLch and
remove Lhe defaulL sprlLe
lellx. Choose 'SelecL new
sprlLe from flle' and choose
Lhe 'SprlLe18un' lmage from
Lhe lmage pack. LdlL Lhe
cosLume by uslng Lhe rubber
Lo remove Lhe brlcks from
where l have cropped Lhe
lmage from a screenshoL on
my lÞad (see lmage). Cnce you have done Lhls, we also need Lo lmporL Lwo
cosLumes for Lhe runner. 1hls can be done by selecLlng Lhe cosLume Lab and cllcklng
lmporL. 1he flrsL cosLume Lo add lL called SprlLe1[ump and secondly add a ghosL
cosLume from ScraLch's llbrary.

3,45 87 nexL we're golng Lo add Lhe second sprlLe, whlch ln Lhls game ls acLually Lhe
scrolllng background. SelecL add sprlLe from folder and add Scrolllng 8ackground.
Cnce Lhe scrolllng background ls also ln ScraLch lL may slL over our runner sprlLe. lf
Lhls happens aL any polnL you can rlghL cllck on Lhe runner sprlLe ln Lhe box boLLom
rlghL of Lhe screen and selecL 'show'.

39$. :7 1he flnal graphlc we wlll need ls Lhe background. 1hls mlghL seem a blL odd
aL flrsL slnce we have loaded our scrolllng background above, buL lL wlll become
apparenL why we need an addlLlonal background shorLly. 1o load Lhe background,
selecL Lhe sLage lcon, cllck backgrounds and lmporL Lhe lmage LlLled background.

<( ./3 -2+( (+(#,%-".* 3( .((4 %/ $%2#% 8#/*#255".* /:# *25(;

39$. ;7 LeL's program Lhe runner flrsL and sLarL by maklng hlm able Lo [ump Lhe holes
ln Lhe paLh ahead. ÞoslLlon your runner ln Lhe mlddle aL Lhe boLLom of Lhe screen as
shown here. 1o make hlm appear Lo [ump (each Llme Lhe spacebar ls pressed), we
are golng Lo geL hlm Lo move forward (verLlcally) brlefly and change cosLume Lo a
[umplng pose. Slnce gravlLy wlll qulckly
geL Lhe beLLer of hlm, we wanL hlm
Lhen Lo reLurn Lo hls orlglnal poslLlon
and swlLch back Lo runnlng mode. 1he
codlng blocks Lo achleve Lhls are
shown below.

Cnce you've added Lhls code, Lry presslng spacebar and your runner should look llke
he [umps! 1ry alLerlng Lhe Llme and dlsLance values. Pow does Lhls affecL hls [ump?

39$. <7 now leLs program Lhe background. 1he background ls golng Lo move ln Lwo
dlrecLlons: lL wlll move verLlcally downwards ln Lhe y dlrecLlon Lo glve Lhe llluslon
LhaL our runner ls runnlng forwards and lL wlll move ln Lhe x dlrecLlon (lefL and rlghL)
Lo glve Lhe llluslon LhaL our runner ls movlng lefL or rlghL. LeL us conslder Lhe verLlcal
movemenL flrsL.

=$)9>?"/ -'@$-$+97 Lo sLarL Lhls game a key wlll be pressed whlch wlll wlll
sLarL Lhe runner runnlng along Lhe paLh. ln acLual facL whaL wlll happen ls LhaL when
Lhe key ls pressed, Lhe background wlll sLarL scrolllng down and glve Lhe llluslon LhaL
Lhe runner ls runnlng forward. 1o achleve Lhls you need Lo creaLe a varlable called
'scroll' !"# %&& '(#)*+', 1hen *>9A>+ 9A$ B?)>.9 ")$" C') 9A$ )(++$) add Lhe blocks

1hls wlll mean LhaL once Lhe 'a' key ls pushed, Lhe varlable 'Scroll' wlll conLlnually
decrease ln -3 sLeps.

lf we now go back Lo Lhe scrlpL area for Lhe scrolllng background we can use Lhls
varlable Lo conLrol Lhe background poslLlon as shown uslng Lhe blocks below. Pere
Lhe y value of Lhe scrolllng background ls belng seL Lo Lhe varlable scroll, whlch we
have [usL seL Lo sLeadlly decrease once 'a' ls pressed.

-&+%'+ )./"#+ *0+ 1 23454 !"# *0+ 6"6+/* 7+ 7)&& 8"6+ "/*" *0)',

1he blocks on Lhe lefL are used Lo reseL Lhlngs when Lhe green flag ls cllcked. Pere
you can see Lhe scrolllng background ls seL Lo x=0 and y=0.

Cnce you have compleLed Lhls sLep, you should have a scrolllng background alLhough
Lhe background scrolls ouL of screen preLLy qulckly! We shall flx LhaL shorLly by
dupllcaLlng many more backgrounds Lo scroll Lhrough ln Lurn.

D')>E'+9"/ -'@$-$+97 As well as scroll verLlcally, we need Lhe background Lo
scroll lefL Lo rlghL (ln Lhe x axls) Lo glve Lhe llluslon LhaL our runner can move lefL or
rlghL. 1o make Lhe game more accuraLe we also need Lhls movemenL llmlLed Lo
wlLhln Lhe walls of Lhe paLh. 1he way l Lackled Lhls problem was Lo make a varlable
called x and Lhen added Lhe followlng code Lo Lhe runner's scrlpL area:

And Lhls code Lo Lhe scrolllng background scrlpL area

lf you read Lhrough Lhe code, you wlll see LhaL movemenL lefL or rlghL ls llmlLed
when Lhe x varlable exceeds cerLaln values (33<x>-33). 1hls causes Lhe runner Lo sLay
wlLhln Lhe boundarles of Lhe wall. 1he value of 33 was worked ouL Lhrough Lrlal and
error! lL should also now become apparenL why we needed LhaL second background
as when our scrolllng background moves lL would [usL leave whlLe aL Lhe end of our
screen lf we dldn'L have Lhe second background behlnd.

39$. F7 1he nexL sLep ls Lo exLend Lhe scrolllng background so our game lasLs longer
and also add some dangerous holes for Lhe runner Lo fall down. 1o do Lhls we are
golng Lo use Lhe copy sprlLe funcLlon - Lhls ls accessed by rlghL cllcklng on Lhe
scrolllng background and selecLlng 'dupllcaLe'. 1he more Llmes you dupllcaLe your
scrolllng background, Lhe longer your game wlll be! A good sLarLlng polnL ls 10

<( ./3 .((4 %/ 526( $/5( 1-2.*($ %/ (21- $1#/''".* =216*#/:.4;

llrsLly, on each one, use Lhe palnL edlLor Lo add some dangerous holes by uslng Lhe
black clrcle Lool, llke Lhe hole LhaL's shown on Lhe paLh aL Lhe very sLarL of Lhls
documenL. uon'L make Lhe holes Loo blg - abouL Lhe slze shown. 1o make your
game more Lrlcky, make Lhe holes ln dlfferenL places on all of Lhe dupllcaLes you
have [usL made of Lhe scrolllng background.

?ou now need Lo change a very small amounL of Lhe code on each scrolllng
background Lo help allgn Lhem all so Lhey scroll ln allgned and one afLer Lhe oLher.
1o achleve Lhls, on each of Lhe dupllcaLe slldes change Lhe value of Lhe number
shown ln Lhe clrcled box below Lo lncrease by 1 each Llme. So, as we have shown
above, Lhe flrsL value was 0, on Lhe second scrolllng background lL wlll be 1, Lhen 2,
Lhen 3 eLc.

AL Lhe same Llme you are maklng Lhe change above, change each of Lhe y values ln
Lhe code shown below on each background Lo lncrease by 360 each Llme. 1hls ls
because Lhe helghL of Lhe program area ls 360 plxels, so by lncreaslng Lhe value by
360 each Llme Lhen when Lhe green flag ls pushed, all Lhe backgrounds llne up one
afLer anoLher 'behlnd Lhe scenes'.

39$. G7 We are now golng Lo wrlLe Lhe code so LhaL Lhe runner ls able Lo [ump Lhe
holes. We have already wrlLLen Lhe program
for hlm Lo be able Lo [ump, so here we shall
Lell ScraLch LhaL 'lf' he ls [umplng when he
Louches Lhe colour black (whlch ls whlle we
made Lhe holes from black clrcles) Lhen
noLhlng should happen buL 'lf' he ls noL
[umplng Lhen he should Lurn lnLo a ghosL
and Lhe game sLops slnce he has fallen lnLo
Lhe hole. 1he code for Lhls ls shown here Lo
Lhe lefL.

!"#$%&'% )* + ," %&#-
!"#$%&'% )* 234 ,"
%&#- )&#./$,0"1
?ou wlll noLlce LhaL a score varlable has also been lncorporaLed.

ln Lhls game, players scores lncrease for Lhe longer Lhey can run for. 1hls was
achleved wlLh Lhls slmple codlng block below.

?ou should now have coded Lhe 1emple 8un game! l hope you have fun playlng lL !

Why don'L you Lry Lhls exLenslon?

4H9$+B>'+7 Could you develop Lhe game so Lhe runner collecLs gold colns Lo lncrease
Lhelr score llke ln 1emple 8un on Lhe lÞad?

D>+9: lf Lhe colns were a speclflc colour you could use Lhe 'when Louchlng colour'

Sign up to vote on this title
UsefulNot useful