level = 1 function on.create() if not highscore then highscore = 0 end game = true angle = 0 score = 0 color = math.random(1,3) nextcolor = math.random(1,3) balltable = {0,0} row = 0 column = 0 even = 0 xmouse, ymouse = 0, 0 new=0 ballnrs=13*4*2+4*13*level for i=1,ballnrs,4 do if row/2==math.floor(row/2) and column==13 then row=row+1 column=0 even=1 end if row/2~=math.floor(row/2) and column==13 then row=row+1 column=0 even=0 end balltable[i] = even*10+4+column*20 balltable[i+1] = 9+row*20 balltable[i+2] = math.random(1,3) balltable[i+3] = 1 column=column+1 end visibletable = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} newcoord = {} end function on.mouseMove(x,y) --crosshair, excel plus if x<=270 and y>=1 and y<=175 then cursor.set("crosshair") end angle = math.atan((136-x)/(197-y))*360/(2*math.pi) if angle>=75 then angle = 75 end if angle<=-75 then angle = -75 end cursor.show() xmouse = x ymouse = y if x<=4 then xmouse=4 end if x>=270 then xmouse=270 end platform.window:invalidate() end function on.paint(gc) cursor.show() gc:setFont("sansserif","r","9") ----------------------------------------- -- ----------drawing background------- -- ----------------------------------------- gc:setColorRGB(56,160,248) gc:fillRect(0,0,318,220) gc:setColorRGB(0,0,0) gc:drawLine(0,0,0,160) gc:drawLine(0,0,272,0) gc:drawLine(272,0,272,160) gc:drawArc(0,130,272,60,180,180) gc:drawArc(115,178,42,32,0,360) gc:setColorRGB(56,160,248) gc:fillRect(116,178,41,14) --gc:fillRect(1,130,271,30) --gc:drawImage(shadeUp,0,0) --gc:drawImage(shadeLeft,0,0) --gc:drawImage(shadeRight,268,0) --gc:drawImage(shadeBottom,0,160) gc:setColorRGB(0,0,0) ----------------------------------------- -- ----------drawing sidebar---------- -- ----------------------------------------- --gc:drawLine(271,0,271,220) gc:drawString("LEVEL",275,0,"top") gc:drawString(level,288,18,"top") gc:drawString("SCORE",274,50,"top") gc:drawString(score,278,68,"top") gc:drawString("HIGH",279,100,"top") gc:drawString("SCORE",273,112,"top") gc:drawString(highscore,278,130,"top") gc:setFont("sansserif","r","6") gc:drawString("Nick Steen",272,200,"top") ----------------------------------------- -- ----------drawing Shooter---------- -- ----------------------------------------- -- pointer -- ----------------------------------------- theta = angle/360*2*math.pi gc:drawLine(135,197,135-22*math.sin(theta),197-22*math.cos(theta)) ----------------------------------------- -- ball -- ----------------------------------------- if color == 1 then ballimage = image.new(redball) end if color == 2 then ballimage = image.new(greenball) end if color == 3 then ballimage = image.new(blueball) end gc:drawImage(ballimage,129,190) if nextcolor == 1 then gc:setColorRGB(255,0,0) end if nextcolor == 2 then gc:setColorRGB(0,255,0) end if nextcolor == 3 then gc:setColorRGB(0,0,255) end --gc:fillArc(5,203,250,250,0,180) ----------------------------------------- -- ----------drawing ballfield-------- -- ----------------------------------------- for i=1,ballnrs,4 do if balltable[i+2] == 1 then ballimage = image.new(redball) end if balltable[i+2] == 3 then ballimage = image.new(blueball) end if balltable[i+2] == 2 then ballimage = image.new(greenball) end if balltable[i+3] == 1 then gc:drawImage(ballimage,balltable[i],balltable[i+1]) end end gc:setColorRGB(0,0,0) gc:fillArc(128,326,4,4,0,360) i=1 new=0 for i=1,level+3 do if i/2==math.floor(i/2) then even=1 else even=0 end --newcoord = {((i*20+9)-197)/((ymouse-197)/(xmouse-136))+136,(i-1)*20+9} --newcoord = {xmouse+(i*20-ymouse+2*(i+level+2))*math.tan(theta),i*20+9} --rechte door (135,197) en (135-22*math.sin(theta),197-22*math.cos(theta)) newcoord[2] = (i-1)*20+9 newcoord[1] = (newcoord[2]-197)/((197-22*math.cos(theta)-197)/(135-22*math.sin(theta)-135))+135 if newcoord[1]>=273 then newcoord[1]=272-(newcoord[1]-272) end if newcoord[1]<=0 then newcoord[1]=math.abs(newcoord[1]) end for k=0,12 do if math.abs(newcoord[1]-(even*10+7+(4+20*k)))<=10 then if on.checkifvisible(even*10+4+20*k,newcoord[2])~=1 and on.checkiffree(newcoord[1],newcoord[2])==0 then newcoord[1] = even*10+4+20*k new = newcoord[1] else --newcoord[2] = newcoord[2]+20 i = i+1 on.checkifburst(newcoord[1],newcoord[2]) end end end if i>=14 then new=newcoord[1] end end gc:fillRect(newcoord[1]+4,newcoord[2],4,4) timer.start(0.1) end function on.checkifvisible(xcoord,ycoord) for l=1,ballnrs/4 do if balltable[4*l-3]==xcoord and balltable[4*l-2]==ycoord and balltable[4*l]==1 then return 1 end end end function on.checkiffree(x,y) return 0 end function on.checkifburst(x,y) nr=0 for m=0,ballnrs/4 do if newcoord[1]==balltable[ballnrs-3]-20 and color==balltable[ballnrs] then nr=nr+1 end end end function on.mouseDown() if new==newcoord[1] then ballnrs = ballnrs+4 table.insert(balltable,ballnrs-3,newcoord[1]) table.insert(balltable,ballnrs-2,newcoord[2]) table.insert(balltable,ballnrs-1,color) table.insert(balltable,ballnrs,1) color = nextcolor nextcolor = math.random(1,3) end platform.window:invalidate() end function on.timer() cursor.show() end function on.charIn(char) if char=='+' and level<=4 then level = level+1 on.create() end if char=='-' and level>=2 then level = level-1 on.create() end if char=='r' then on.create() end cursor.show() platform.window:invalidate() end function on.save() return highscore end function on.restore(data) if type(data) == "number" then highscore = data end end redball = "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\179\201\145\205O\213.\209N\205\143\201\000\000\000\000\000\000\000\000\000\000\000\0005\222+\217\007\245\196\252@\248 \244\000\232\000\216\131\208M\201\000\000\000\000\000\000\024\214\144\209m\221r\254P\254\006\253a\240@\236@\220B\196e\180o\197\000\000\000\000\147\221o\221\216\250y\255N\234\008\245\130\240@\240 \232C\200\034\196C\208\000\000\019\238\202\212m\237s\254\204\249\006\229\132\240b\248`\240 \228B\204B\200!\192\166\188k\229\231\228j\245(\253\195\244\164\252\132\252C\252`\240@\228\002\212 \200 \196\161\180\164\216I\245\148\254\239\253\162\248a\248b\252A\248a\236a\220@\196 \192!\200\196\196@\216\006\249\148\254\206\233@\248`\252@\252 \252\034\228@\208\160\188@\184!\200\197\200\132\208\165\216&\229\163\216@\232`\236@\228@\224A\216 \200a\188!\184#\208\133\200I\225\131\200`\208@\220`\228@\224A\216@\208A\212!\196!\180\002\184E\216\133\204\000\000\170\176A\192c\212D\216C\212B\204\000\196!\196\000\188 \188c\204e\200\000\000\000\000\147\185b\192!\200\004\204\003\200\000\184\001\188\001\188\001\188b\208\164\216d\200\000\000\000\000\000\000o\189\134\176c\204\131\208\131\204b\204c\208\164\212\163\184\133\168\000\000\000\000\000\000\000\000\000\000\000\000a\204`\204@\204@\204 \208@\204\000\000\000\000\000\000\000\000" blueball = "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\156\1819\169\247\156\246\1527\161\185\177\000\000\000\000\000\000\000\000\000\000\000\000\252\189\222\160\188\152\186\148<\132\030\128\026\128\020\128r\140\184\181\000\000\000\000\000\000\253\193\247\156\188\181\223\214\255\185~\140\029\132\025\132\019\128\016\128r\144\152\181\000\000\000\000\254\160\157\177}\231\029\215<\153]\136\029\132\024\1283\1284\132\019\132o\144\000\000\187\185x\144\191\185>\194;\157{\128]\132\029\132\026\132\022\128\018\1281\132\013\128\020\169:\169\216\156\223\185\254\160\092\132\127\128^\132\029\132\029\128\025\128\017\128.\128\016\132V\148\213\156\219\189\255\226\030\169<\132^\128\029\128\028\132\026\128\022\1281\128\013\128R\1366\144\178\152\184\185>\202\189\156\029\128?\128\030\128\027\132\025\128\021\128\015\128\011\128R\1367\144\244\160\150\152\217\1608\140\025\132\025\128\025\128\025\132\021\128\016\128/\128.\128P\132T\1447\169\023\1369\1447\140\023\132\022\128\023\128\024\132\018\128\013\128\013\128P\132P\132\148\148\000\000O\140P\1363\136\019\132\019\128\018\128\018\128\015\132,\128/\132S\136/\132\000\000\000\000\017\157+\132\016\128\018\132\018\128\017\128\015\132.\132M\132R\1405\136\147\144\000\000\000\000\000\000\242\152/\1320\132R\140R\1402\1360\136.\136-\132\177\148\000\000\000\000\000\000\000\000\000\000\000\000Q\1401\140\016\132\016\1320\136P\140\000\000\000\000\000\000\000\000" greenball = "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\244\182\240\174\238\170\205\162\138\154L\158\000\000\000\000\000\000\000\000\000\000\000\000q\167-\175o\199\208\183\172\151i\135G\131\197\130$\130H\150\000\000\000\000\000\000\216\190\143\159\209\195\244\223\242\191\205\151\169\135\136\131\229\130\132\134\004\142\011\162\000\000\000\000P\183\207\179\245\199\243\195\236\159\201\139\201\135\135\131\230\130h\134G\134J\146\000\000\213\194.\175\173\175\239\179\174\171\203\151\233\139\201\139\168\131\008\131\136\134%\130\198\129\169\157M\159n\179\210\211\239\167\236\131\234\135\233\135\200\135F\131\197\130\166\130$\130G\138)\146\010\147N\175\245\219\239\167\235\131\234\135\200\135\168\135G\131\197\130\133\130\002\130%\138\139\154\234\154,\163\241\183\172\151\138\135\169\139\135\135G\135\197\134e\130$\130\225\129$\138\137\150\204\162g\142\199\146\008\135(\131F\131$\131\228\130\165\130D\130\003\130\192\129e\142'\146\204\162'\150\164\130\199\134\199\138\197\138\164\134c\138\034\134\196\133\165\129\227\129\135\146\137\157\000\000J\158B\130\166\134\167\138c\130A\130\001\130\225\129\228\129\196\129\170\154G\142\000\000\000\000J\158\006\138\002\130C\130#\134\003\134\003\134\003\134D\134\168\142G\146\201\153\000\000\000\000\000\000\209\174J\150G\146h\150h\154h\154h\150G\146\007\138\233\145\000\000\000\000\000\000\000\000\000\000\000\000\240\173\203\157\201\153\201\149\167\145\170\149\000\000\000\000\000\000\000\000"