I had a quiet day, so took the liberty of hacking about with your code to get rid of some of the larger chunks of repetitions. This does not change any of the functionality.
As well as the changes above, I have added a user defined type array to replace your individual sprite and text definitions (sprite0 to sprite9 and text0 to text9).
All the relevant code has been modified to use the array rather than the globals, also the use of an array has allowed some of the routines to be put in loops.
Have a look and you should get an idea of how this works, if not, I'm happy to help out with any questions.
I've commented out the blocks which were replaced, but left them, in for reference.
`BeatTheClockTimes based on robslearningfun/TargetMultiply. Started writing app - 23/1/2014
`Uses text objects that follow a dummy sprite around
// TextMediaType is used as the structure for the array TextMedia[], which allows the txt and sprite objects to be kept in a single array
// this Array replaces text0 to text9 and sprite0 to sprite9
type TextMediaType
text
sprite
endtype
dim TextMedia[ 9 ] as TextMediaType
for index = 0 to 9
TextMedia[ index ].text = 0
TextMedia[ index ].sprite = 0
next index
// **** Replaces...
// global sprite0, sprite1, sprite2, sprite3, sprite4, sprite5, sprite6, sprite7, sprite8, sprite9,
// global text0, text1, text2, text3, text4, text5, text6, text7, text8, text9
global spritesum, spritecorner, spritetime
global firstnumber, secondnumber, answer, sum, close, score, textscore, sumsdone
global limit, starttime, begintime, timepassed, correct, OT, quit
Global img_font as Integer
img_font = LoadImage("Arial Narrow.png")
SetTextDefaultFontImage(img_font)
setvirtualresolution(1366,768)
EnableClearColor ( 1 )
SetClearColor ( 0, 0, 0 )
global resourcesloaded = 0
global tableschosen = 0
global spritemade = 0
global speed = 100000
dim timestable[10]
dim number[10]
SetPhysicsGravity ( 0, 0 )
`SetPhysicsDebugOn()
`score = 10000
loadresources()
intro()
choosetables()
begintime = timer()
do
playgame()
makesprites()
starttime = timer()
OT = timepassed
movenumbers()
if correct = 1 then inc sumsdone
if sumsdone >= 10 then endgame()
loop
end
function explode(X, Y)
CreateParticles ( 1, -100, -100 )
fire = 1
for n= 1 to 100
if ( fire = 1 )
playsound(1)
SetParticlesPosition ( 1, X, Y)
ResetParticleCount ( 1 )
SetParticlesFrequency ( 1, 1000 )
SetParticlesLife ( 1, 1.5 )
SetParticlesSize ( 1, 256 )
SetParticlesStartZone ( 1, -10, 0, 10, 0 )
SetParticlesImage ( 1, 3 )
SetParticlesDirection ( 1, 10, 10 )
SetParticlesAngle ( 1, 360 )
SetParticlesVelocityRange ( 1, 0.8, 1.5 )
SetParticlesMax ( 1, 250 )
`AddParticlesColorKeyFrame ( 1, 0.0, random(0, 255), random(0,255), random(0, 255), 0 )
`AddParticlesColorKeyFrame ( 1, 0.0, 255, 0, 0, 0 )
AddParticlesColorKeyFrame ( 1, 0.5, 255, 255, 0, 255 )
`AddParticlesColorKeyFrame ( 1, 2.8, 255, 0, 0, 0 )
AddParticlesForce ( 1, 2.0, 2.8, 25, -25 )
fire = 0
endif
if ( GetParticlesMaxReached ( 1 ) )
fire = 1
endif
sync ( )
next n
deleteparticles(1)
endfunction `explode
function intro
intro1 = createtext("Beat The Clock Times")
settextcolor(intro1,255, 0, 255, 255)
settextposition(intro1, 120, 100)
settextsize(intro1, 80)
intro2 = createtext("Written by Rob Somerville, 2014")
settextcolor(intro2, 0, 255, 255, 255)
settextposition(intro2, 80, 250)
settextsize(intro2, 60)
intro3 = createtext("GO")
settextcolor(intro3, 255, 0, 0, 255)
settextposition(intro3, 250, 400)
settextsize(intro3, 100)
gosprite = createsprite(0)
setspritecolor(gosprite, 0, 0, 0, 255)
setspriteposition(gosprite, 250, 400)
setspritesize(gosprite, 150, 90)
logo1 = createsprite(1)
setspriteposition(logo1, 750, 350)
setspritesize(logo1, 150,150)
sync()
repeat
if GetPointerReleased()=1
id = GetSpriteHit(GetPointerX(),GetPointerY())
if id = gosprite
introOver = 1
endif
endif
sync()
until introOver = 1
deletealltext()
deleteallsprites()
endfunction`intro
function loadresources
loadsound(299,"999.wav")
loadsound(1,"explode.wav")
loadsound(2,"miss.wav")
loadsound(3,"fail.wav")
loadimage(1,"Made-With-AGK-Black-128px.png")
loadimage(2,"close.png")
LoadImage (3,"shrapnel3.png")
resourcesloaded = 1
endfunction`loadresources
// ***************
// ** From MARL **
// ***************
function CreateTableText( String$ , Xpos , Ypos , Size )
newText = createtext( String$ )
settextcolor( newText , 255, 255, 0, 200)
settextposition( newText, Xpos , Ypos )
settextsize( newText , Size )
endfunction newText
// *******************
// ** End From MARL **
// *******************
// New Functions
function choosetables()
for n = 1 to 10
timestable[n] = 0
next n
all = 0
`print top two lines of choosetables page
title1 = CreateTableText( "Beat The Clock Times" , 230 , 0 , 64 )
// *** Replaces ***
// title1 = createtext("Beat The Clock Times")
// settextposition(title1, 230, 0)
// settextsize(title1, 64)
settextcolor( title1 , 255, 0, 255, 255)
title2 = CreateTableText( "Choose Times Tables" , 230 , 100 , 64 )
// *** Replaces ***
// title2 = createtext("Choose Times Tables")
// settextposition(title2, 230, 100)
// settextsize(title2, 64)
settextcolor( title2 , 0, 0, 255, 255)
`print text describing check box to choose tables
table2 = CreateTableText( "2 times table-" , 50 , 200 , 60 )
// *** Replaces ***
// table2 = createtext("2 times table-")
// settextposition(table2, 50, 200)
// settextsize(table2, 60)
timestable[2] = 1
table3 = CreateTableText( "3 times table-" , 50, 300 , 60 )
// *** Replaces ***
// table3 = createtext("3 times table-")
// settextposition(table3, 50, 300)
// settextsize(table3, 60)
table4 = CreateTableText( "4 times table-" , 50, 400 , 60 )
// *** Replaces ***
// table4 = createtext("4 times table-")
// settextposition(table4, 50, 400)
// settextsize(table4, 60)
table5 = CreateTableText( "5 times table-" , 50, 500 , 60 )
// *** Replaces ***
// table5 = createtext("5 times table-")
// settextposition(table5, 50, 500)
// settextsize(table5, 60)
table6 = CreateTableText( "6 times table-" , 650, 200 , 60 )
// *** Replaces ***
// table6 = createtext("6 times table-")
// settextposition(table6, 650, 200)
// settextsize(table6, 60)
table7 = CreateTableText( "7 times table-" , 650, 300 , 60 )
// *** Replaces ***
// table7 = createtext("7 times table-")
// settextposition(table7, 650, 300)
// settextsize(table7, 60)
table8 = CreateTableText( "8 times table-" , 650, 400 , 60 )
// *** Replaces ***
// table8 = createtext("8 times table-")
// settextposition(table8, 650, 400)
// settextsize(table8, 60)
table9 = CreateTableText( "9 times table-" , 650, 500 , 60 )
// *** Replaces ***
// table9 = createtext("9 times table-")
// settextposition(table9, 650, 500)
// settextsize(table9, 60)
table10 = CreateTableText( "10times table" , 650, 600 , 60 )
// *** Replaces ***
// table10 = createtext("10times table")
// settextposition(table10, 650, 600)
// settextsize(table10, 60)
tableall = CreateTableText("All the tables-" , 33, 600 , 60 )
// *** Replaces ***
// tableall = createtext("All the tables-")
// settextposition(tableall, 33, 600)
// settextsize(tableall, 60)
settextcolor(tableall, 255, 0, 0, 200)
tablego = CreateTableText( "GO" , 1050 , 60 , 120 )
// *** Replaces ***
// tablego = createtext("GO")
// settextposition(tablego, 1050, 60)
// settextsize(tablego, 120)
settextcolor(tablego, 255, 0, 0, 255)
`create checkboxes for tables
tt2box = createsprite(0)
setspritecolor(tt2box, 0, 255,0,255)
setspriteposition(tt2box, 520, 210)
setspritesize(tt2box, 40,40)
tt3box = createsprite(0)
setspritecolor(tt3box, 255,255,0,255)
setspriteposition(tt3box, 520, 310)
setspritesize(tt3box, 40,40)
tt4box = createsprite(0)
setspritecolor(tt4box, 255,255,0,255)
setspriteposition(tt4box, 520, 410)
setspritesize(tt4box, 40,40)
tt5box = createsprite(0)
setspritecolor(tt5box, 255,255,0,255)
setspriteposition(tt5box, 520, 510)
setspritesize(tt5box, 40,40)
tt6box = createsprite(0)
setspritecolor(tt6box, 255,255,0,255)
setspriteposition(tt6box, 1120, 210)
setspritesize(tt6box, 40,40)
tt7box = createsprite(0)
setspritecolor(tt7box, 255,255,0,255)
setspriteposition(tt7box, 1120, 310)
setspritesize(tt7box, 40,40)
tt8box = createsprite(0)
setspritecolor(tt8box, 255,255,0,255)
setspriteposition(tt8box, 1120, 410)
setspritesize(tt8box, 40,40)
tt9box = createsprite(0)
setspritecolor(tt9box, 255,255,0,255)
setspriteposition(tt9box, 1120, 510)
setspritesize(tt9box, 40,40)
tt10box = createsprite(0)
setspritecolor(tt10box, 255,255,0,255)
setspriteposition(tt10box, 1120, 610)
setspritesize(tt10box, 40,40)
ttallbox = createsprite(0)
setspritecolor(ttallbox, 255,255,0,255)
setspriteposition(ttallbox, 520, 610)
setspritesize(ttallbox, 40,40)
gosprite = createsprite(0)
setspritecolor(gosprite, 0, 0, 0, 255)
setspriteposition(gosprite, 1050, 70)
setspritesize(gosprite, 175, 100)
sync()
`respond to checkboxes being clicked
repeat
if GetPointerReleased()=1
id = GetSpriteHit(GetPointerX(),GetPointerY())
if id = tt2box
if timestable[2] = 0
timestable[2] = 1
setspritecolor(tt2box, 0, 255, 0, 255)
else
timestable[2] = 0
setspritecolor(tt2box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt3box
if timestable[3] = 0
timestable[3] = 1
setspritecolor(tt3box, 0, 255, 0, 255)
else
timestable[3] = 0
setspritecolor(tt3box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt4box
if timestable[4] = 0
timestable[4] = 1
setspritecolor(tt4box, 0, 255, 0, 255)
else
timestable[4] = 0
setspritecolor(tt4box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt5box
if timestable[5] = 0
timestable[5] = 1
setspritecolor(tt5box, 0, 255, 0, 255)
else
timestable[5] = 0
setspritecolor(tt5box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt6box
if timestable[6] = 0
timestable[6] = 1
setspritecolor(tt6box, 0, 255, 0, 255)
else
timestable[6] = 0
setspritecolor(tt6box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt7box
if timestable[7] = 0
timestable[7] = 1
setspritecolor(tt7box, 0, 255, 0, 255)
else
timestable[7] = 0
setspritecolor(tt7box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt8box
if timestable[8] = 0
timestable[8] = 1
setspritecolor(tt8box, 0, 255, 0, 255)
else
timestable[8] = 0
setspritecolor(tt8box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt10box
if timestable[10] = 0
timestable[10] = 1
setspritecolor(tt10box, 0, 255, 0, 255)
else
timestable[9] = 0
setspritecolor(tt10box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = tt9box
if timestable[9] = 0
timestable[9] = 1
setspritecolor(tt9box, 0, 255, 0, 255)
else
timestable[9] = 0
setspritecolor(tt9box, 255, 255, 0, 255)
setspritecolor(ttallbox, 255, 255, 0, 255)
endif
endif
if id = ttallbox
for n = 1 to 10
timestable[n] = 1
next n
setspritecolor(tt2box, 0, 255, 0, 255)
setspritecolor(tt3box, 0, 255, 0, 255)
setspritecolor(tt4box, 0, 255, 0, 255)
setspritecolor(tt5box, 0, 255, 0, 255)
setspritecolor(tt6box, 0, 255, 0, 255)
setspritecolor(tt7box, 0, 255, 0, 255)
setspritecolor(tt8box, 0, 255, 0, 255)
setspritecolor(tt9box, 0, 255, 0, 255)
setspritecolor(tt10box, 0, 255, 0, 255)
setspritecolor(ttallbox, 0, 255, 0, 255)
endif
if id = gosprite
NoOfTables = 0
for n = 2 to 10
if timestable[n] = 1 then NoOfTables = 1
next n
if NoOfTables = 0 then timestable[1] = 1
tableschosen = 1
endif
endif
sync()
until tableschosen = 1
DeleteAllSprites()
DeleteAllText()
endfunction`choosetables
function playgame()
repeat
oldno =firstnumber
firstnumber = random(0,10)
until firstnumber <> oldno
`firstnumber = 10
repeat
secondnumber = random(1,10)
until timestable[secondnumber] = 1
`secondnumber = 10
answer = firstnumber * secondnumber
number[0] = answer
number[1] = firstnumber + secondnumber
number[2] = answer - 4
number[3] = answer - 3
number[4] = answer - 2
number[5] = answer - 1
number[6] = answer + 1
number[7] = answer + 2
number[8] = answer + 3
number[9] = answer + 10
for n = 1 to 9
if number[n] < 0 then number[n] = abs(number[n])
if number[n] = answer then number[n] = number[n] + 5
next n
gameplayed = 1
endfunction`playgame
function showscore()
if gettextexists(textscore) then deletetext(textscore)
textscore = createtext(str(sumsdone+1))
settextcolor(textscore, 0, 255, 0, 255)
settextposition(textscore, 50, -10)
settextsize(textscore, 100)
spritescore = createsprite(0)
setspriteposition(spritescore, 50, 0)
setspritephysicson(spritescore, 1)
setspritesize(spritescore, gettexttotalwidth(textscore), 65)
setspritecolor(spritescore, 255, 0, 0, 0)
timepassed = timer() - begintime
if correct = 1 then texttimepassed = createtext(str(timepassed) + "secs")
if correct = 0 then texttimepassed = createtext(str(OT) + "secs")
settextcolor(texttimepassed, 0255, 255,0,255)
settextposition(texttimepassed, 800, -10)
settextsize(texttimepassed, 100)
spritetime = createsprite(0)
setspriteposition(spritetime, 800, 0)
setspritephysicson(spritetime, 1)
setspritesize(spritetime, gettexttotalwidth(texttimepassed), 65)
setspritecolor(spritetime, 255, 0, 0, 0)
endfunction : `showscore
function changescore(up)
if up = 0
if score < 0 then score = 1
correct = 0
else
correct = 1
endif
endfunction `changescore
// ***************
// ** From MARL **
// ***************
function CreateTextObject( Index , thisRestitution as float )
if Index >=0 and Index <=9
thisString$ = str( number[ Index ] )
thisText = createtext( thisString$ )
SetTextColor(thisText,random(100,255),random(100,255),random(100,255), 255)
SetTextSize(thisText,100)
thisSprite = createsprite(0)
SetSpritePosition (thisSprite, random(50,1000), random(90, 600))
setspritesize(thisSprite, GetTextTotalWidth(thisText), 65)
setspritecolor(thisSprite, 0, 0, 0, 0)
SetSpritePhysicsOn (thisSprite, 2 )
SetSpritePhysicsCanRotate(thisSprite, 0)
SetSpritePhysicsVelocity ( thisSprite, random(-10,10), random(-10,10) * speed)
SetSpritePhysicsRestitution (thisSprite, thisRestitution )
TextMedia[ Index ].text = thisText
TextMedia[ Index ].sprite = thisSprite
endif
endfunction
// *******************
// ** End From MARL **
// *******************
function makesprites()
addvirtualbutton(1,1330,34,80)
SetVirtualButtonImageUp(1,2)
spritecorner = createsprite(0)
setspriteposition(spritecorner,1292, -6)
setspritephysicson(spritecorner,1)
setspritesize(spritecorner, 80, -1)
setspritecolor(spritecorner, 255, 0, 0, 0)
showscore()
createtext(sum, str(firstnumber) + "x" + str(secondnumber) + "=")
settextcolor(sum,255,0,255,255)
settextposition(sum,400,-10)
if answer = 100
SetTextSize(sum,100)
else
settextsize(sum,100)
endif
spritesum = createsprite(0)
setspriteposition(spritesum,420, 10)
setspritephysicson(spritesum, 1)
setspritesize(spritesum, GetTextTotalWidth(sum), 65)
setspritecolor(spritesum, 255, 0, 0, 0)
// Text0 an Sprite0 , Moved to Array TextMedia[].text and TextMedia[].sprite
CreateTextObject( 0 , 0.75 )
// *** Replaces...
// text0 = createtext(str(number[0]))
// SetTextColor(text0,random(100,255),random(100,255),random(100,255), 255)
// SetTextSize(text0,100)
// sprite0 = createsprite(0)
// SetSpritePosition (sprite0, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite0, 2 )
// SetSpritePhysicsCanRotate(sprite0, 0)
// setspritesize(sprite0, GetTextTotalWidth(text0), 65)
// setspritecolor(sprite0, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite0, random(-10,10), random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite0, 0.75 )
CreateTextObject( 1 , 1.0 )
// *** Replaces...
// text1 = createtext(str(number[1]))
// SetTextColor(text1,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text1,100)
// sprite1 = createsprite(0)
// SetSpritePosition (sprite1, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite1, 2 )
// SetSpritePhysicsCanRotate(sprite1, 0)
// setspritesize(sprite1, GetTextTotalWidth(text1), 65)
// setspritecolor(sprite1, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite1, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite1, 1.0 )
CreateTextObject( 2 , 1.0 )
// *** Replaces...
// text2 = createtext(str(number[2]))
// SetTextColor(text2,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text2,100)
// sprite2 = createsprite(0)
// SetSpritePosition (sprite2, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite2, 2 )
// SetSpritePhysicsCanRotate(sprite2, 0)
// setspritesize(sprite2, GetTextTotalWidth(text2), 65)
// setspritecolor(sprite2, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite2, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite2, 1.0 )
CreateTextObject( 3 , 1.0 )
// *** Replaces...
// text3 = createtext(str(number[3]))
// SetTextColor(text3,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text3,100)
// sprite3 = createsprite(0)
// SetSpritePosition (sprite3, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite3, 2 )
// SetSpritePhysicsCanRotate(sprite3, 0)
// setspritesize(sprite3, GetTextTotalWidth(text3), 65)
// setspritecolor(sprite3, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite3, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite3, 1.0 )
CreateTextObject( 4 , 1.0 )
// *** Replaces...
// text4 = createtext(str(number[4]))
// SetTextColor(text4,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text4,100)
// sprite4 = createsprite(0)
// SetSpritePosition (sprite4, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite4, 2 )
// SetSpritePhysicsCanRotate(sprite4, 0)
// setspritesize(sprite4, GetTextTotalWidth(text4), 65)
// setspritecolor(sprite4, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite4, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite4, 1.0 )
CreateTextObject( 5 , 1.0 )
// *** Replaces...
// text5 = createtext(str(number[5]))
// SetTextColor(text5,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text5,100)
// sprite5 = createsprite(0)
// SetSpritePosition (sprite5, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite5, 2 )
// SetSpritePhysicsCanRotate(sprite5, 0)
// setspritesize(sprite5, GetTextTotalWidth(text5), 65)
// setspritecolor(sprite5, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite5, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite5, 1.0 )
CreateTextObject( 6 , 1.0 )
// *** Replaces...
// text6 = createtext(str(number[6]))
// SetTextColor(text6,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text6,100)
// sprite6 = createsprite(0)
// SetSpritePosition (sprite6, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite6, 2 )
// SetSpritePhysicsCanRotate(sprite6, 0)
// setspritesize(sprite6, GetTextTotalWidth(text6), 65)
// setspritecolor(sprite6, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite6, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite6, 1.0 )
CreateTextObject( 7 , 1.0 )
// *** Replaces...
// text7 = createtext(str(number[7]))
// SetTextColor(text7,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text7,100)
// sprite7 = createsprite(0)
// SetSpritePosition (sprite7, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite7, 2 )
// SetSpritePhysicsCanRotate(sprite7, 0)
// setspritesize(sprite7, GetTextTotalWidth(text7), 65)
// setspritecolor(sprite7, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite7, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite7, 1.0 )
CreateTextObject( 8 , 1.0 )
// *** Replaces...
// text8 = createtext(str(number[8]))
// SetTextColor(text8,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text8,100)
// sprite8 = createsprite(0)
// SetSpritePosition (sprite8, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite8, 2 )
// SetSpritePhysicsCanRotate(sprite8, 0)
// setspritesize(sprite8, GetTextTotalWidth(text8), 65)
// setspritecolor(sprite8, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite8, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite8, 1.0 )
CreateTextObject( 9 , 1.0 )
// *** Replaces...
// text9 = createtext(str(number[9]))
// SetTextColor(text9,random(100,255),random(100,255),random(100,255),255)
// SetTextSize(text9,100)
// sprite9 = createsprite(0)
// SetSpritePosition (sprite9, random(50,1000), random(90, 600))
// SetSpritePhysicsOn (sprite9, 2 )
// SetSpritePhysicsCanRotate(sprite9, 0)
// setspritesize(sprite9, GetTextTotalWidth(text9), 65)
// setspritecolor(sprite9, 0, 0, 0, 0)
// SetSpritePhysicsVelocity ( sprite9, random(-10,10) * speed, random(-10,10) * speed)
// SetSpritePhysicsRestitution (sprite9, 1.0 )
endfunction`makesprites
function movenumbers
hitanswer = 0
repeat
starttime = timer()
hit = 0
if GetVirtualButtonPressed(1)=1
quit = 1
closegame = 1
endgame()
endif
// Make Text Match Sprite Positions
for index = 0 to 9
thisText = TextMedia[ index ].text
thisSprite = TextMedia[ index ].sprite
x1 = getspritex( thisSprite )
y1 = getspritey( thisSprite ) - 20
settextposition( thisText , x1, y1)
next index
// *** Replaces (and extends to remove dupe operation later) ...
// x0 = getspritex(sprite0)
// y0 = getspritey(sprite0) - 20
// settextposition(text0, x0 , y0)
changevelocity = random(1, 1000)
if changevelocity = 4
// *** Loop replaces individual assignments
for index = 0 to 9
thisSprite = TextMedia[ index ].sprite
SetSpritePhysicsvelocity( thisSprite , random(-100, 100), random(-100,100))
next index
// *** Replaces...
// SetSpritePhysicsvelocity( sprite0, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite1, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite2, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite3, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite4, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite5, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite6, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite7, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite8, random(-100, 100), random(-100,100))
// SetSpritePhysicsvelocity( sprite9, random(-100, 100), random(-100,100))
endif
// **** Only need to do these once
X = getpointerX()
Y = getpointerY()
if GetPointerPressed() = 1
// *** Loop to replace individual checks
for index = 0 to 9
thisText = TextMedia[ index ].text
thisSprite = TextMedia[ index ].sprite
// Check for hit
if GetTextHitTest( thisText , X , Y )
hit = 1
// Find if text 0
if index = 0
playsound(1)
explode(X, Y)
deletetext( thisText )
TextMedia[ 0 ].text = 0
changescore(1)
hitanswer = 1
else
changescore(0)
showscore()
playsound(3)
endif
endif
next index
endif
// *** Replaces...
// if GetTextHitTest(text0, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// playsound(1)
// `deletetext(text0)
// explode(X, Y)
// deletetext(text0)
// changescore(1)
// hitanswer = 1
// endif
// x1 = getspritex(sprite1)
// y1 = getspritey(sprite1) - 20
// settextposition(text1, x1, y1)
// if GetTextHitTest(text1, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x2 = getspritex(sprite2)
// y2 = getspritey(sprite2) - 20
// settextposition(text2, x2, y2)
// if GetTextHitTest(text2, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x3 = getspritex(sprite3)
// y3 = getspritey(sprite3) - 20
// settextposition(text3, x3, y3)
// if GetTextHitTest(text3, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x4 = getspritex(sprite4)
// y4 = getspritey(sprite4) - 20
// settextposition(text4, x4, y4)
// if GetTextHitTest(text4, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x5 = getspritex(sprite5)
// y5 = getspritey(sprite5) - 20
// settextposition(text5, x5, y5)
// if GetTextHitTest(text5, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x6 = getspritex(sprite6)
// y6 = getspritey(sprite6) - 20
// settextposition(text6, x6, y6)
// if GetTextHitTest(text6, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x7 = getspritex(sprite7)
// y7 = getspritey(sprite7) - 20
// settextposition(text7, x7, y7)
// if GetTextHitTest(text7, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x8 = getspritex(sprite8)
// y8 = getspritey(sprite8) - 20
// settextposition(text8, x8, y8)
// if GetTextHitTest(text8, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
// x9 = getspritex(sprite9)
// y9 = getspritey(sprite9) - 20
// settextposition(text9, x9, y9)
// if GetTextHitTest(text9, GetPointerX(), GetPointerY()) = 1 and GetPointerPressed() = 1
// hit = 1
// changescore(0)
// showscore()
// playsound(3)
// endif
if getpointerstate() = 1 and hit = 0
`playsound(2)
hit = 0
endif
sync()
if hitanswer = 1
deletevirtualbutton(1)
deleteallsprites()
deletealltext()
for n = 0 to 9
number[n] = 0
// Additional
TextMedia[ n ].text = 0
TextMedia[ n ].sprite = 0
//
next n
endif
until hitanswer = 1
clearscreen()
swap()
sync()
endfunction `movenumbers
function endgame()
timepassed = timer() - begintime
deleteallsprites()
deletealltext()
deletevirtualbutton(1)
clearscreen()
if quit = 0
bye = createtext("Well done! You finished in ")
settextcolor(bye,255,0,255,255)
settextposition(bye,80,200)
SetTextSize(bye,70)
bye2 = createtext(str(timepassed) + "seconds")
settextcolor(bye2, 255, 255, 0, 255)
settextposition(bye2, 80,300)
settextsize(bye2, 70)
else
bye = createtext("Please try again!")
settextcolor(bye, 162,162,162,255)
settextposition(bye,80,300)
settextsize(bye,70)
endif
sync()
sleep(1000)
bye2 = createtext("Now Click or Tap to Exit")
settextcolor(bye2,255,0,0,255)
settextposition(bye2, 80,400)
settextsize(bye2, 70)
sync()
do
if getpointerpressed() = 1
exit
endif
sync()
loop
end
endfunction `endgame
I've also attached the main.agc to save the massive copy/paste.
Edit: With commented out code removed, it is down to 600 lines.