|-------------------------------------------------------------------------------| |FRANCAIS| |-------------------------------------------------------------------------------| |Touches :| |Flèches ou 4/6 : se déplacer| |-------------------------------------------------------------------------------| |Ceci est un jeu inspiré de CubeRunner (pour téléphones), écrit en Lua (OS>3)| |Survivez aussi longtemps que possible sans rentrer dans les cubes ! | |Tous les 1000 points, un couloir annonce le passage au nivau suivant, où la| |vitesse augmente.| |-------------------------------------------------------------------------------|
|-------------------------------------------------------------------------------| |ENGLISH| |-------------------------------------------------------------------------------| |Keys : | |Arrows or 4/6 : move| |-------------------------------------------------------------------------------| |This is a game inspired by CubeRunner (for smartphones), written in Lua (OS>3)| |Survive as long as you can without getting hit by the cubes! | |Every 1000 points, a corridor appears to introduce the next level, where the| |speed icreases.| |-------------------------------------------------------------------------------|
|-------------------------------------------------------------------------------| |Loïc Pujet (Chockosta), 2011| |-------------------------------------------------------------------------------| Is there any mistake ?
bufDrawString(buf, 50, 0, "Nspire clock - By Loic Pujet", 0); uint32_t time = *(volatile uint32_t*) 0x90090000; sprintf(clock, "%lu : %lu : %lu", (time%86400)/3600, (time%3600)/60, time%60); bufDrawString(buf, 115, 150, clock, 0); EDIT : Oops, I haven't seen that this post was quite old. But maybe it will be useful for someone
function render(gc) drawHorizon(gc) local size,x,y,i,polygon for j=1,27do i=(j+lastCube-2)%27+1 size=100/(10-cubesY[i]) x=(cubesX[i]-7-player)/(10-cubesY[i])*150-size/2 y=5/(10-cubesY[i])*50-180 polygon=rotate({x,y,x+size,y,x+size,y+size,x,y+size,x,y}) if cubesY[i]>1then gc:setColorRGB(color[1],color[2],color[3]) gc:fillPolygon(polygon) gc:setColorRGB(0,0,0) gc:drawPolyLine(polygon) end if y+size>3and y<17then if x<6and x+size>-6then menu=true end end end end
function rotate(p) local s,c=math.sin(rotation),math.cos(rotation) return {p[1]*c-p[2]*s+159,p[1]*s+p[2]*c+202,p[3]*c-p[4]*s+159,p[3]*s+p[4]*c+202,p[5]*c-p[6]*s+159,p[5]*s+p[6]*c+202,p[7]*c-p[8]*s+159,p[7]*s+p[8]*c+202,p[9]*c-p[10]*s+159,p[9]*s+p[10]*c+202} end
function updateCubes() local step=menu and0.06or speed for i=1,27do cubesY[i]=cubesY[i]+step if cubesY[i]>10then if score%1000<800then cubesX[i]=math.random(10,140)/10+player else cubesX[i]=math.random(10,140)/200+player+(i-1)%2*5+4.1 end cubesY[i]=1 lastCube=lastCube==1and27or lastCube-1 end end end
function updateMove() if moving then player=player+0.07*dir if math.abs(rotation)<0.15or dir==rotation/math.abs(rotation) then rotation=rotation-0.005*dir end iftimer.getMilliSecCounter()-moveStart>=150then moving=false end else if math.abs(rotation)>0.005then rotation=rotation-0.005*rotation/math.abs(rotation) end end end
function drawPlayer(gc) ifnot menu then gc:drawImage(playerImg,149,192) end end
function drawHorizon(gc) local s,c=math.sin(rotation),math.cos(rotation) gc:setColorRGB(0,0,0) gc:drawLine(s*142-c*200+159,202-c*142-s*200,c*200+s*142+159,s*200-c*142+202) end
function drawMenu(gc) if menu then gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",30) gc:drawString("CubeField",80,10,"top") gc:setFont("sansserif","b",12) gc:drawString("Press Enter",115,150,"top") local highscore=var.recall("highscore") ifnot highscore then var.store("highscore",0) highscore=0 end if score>highscore then var.store("highscore",score) document.markChanged() end local str="Score : "..tostring(score).." Highscore : "..tostring(highscore) gc:drawString(str,159-gc:getStringWidth(str)/2,100,"top") end end
function drawScore(gc) ifnot menu then gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",12) gc:drawString(tostring(score),2,0,"top") if score%1000>950then gc:setFont("sansserif","r",30) gc:drawString("Speed Up !",80,10,"top") end end end
function levelUp() speed=speed+0.02 level=level+1 if (level-1)%5==0then color={225,170,0} elseif (level-1)%5==1then color={0,0,255} elseif (level-1)%5==2then color={100,100,100} elseif (level-1)%5==3then color={90,255,0} elseif (level-1)%5==4then color={255,255,255} end end
functionon.paint(gc) render(gc) drawPlayer(gc) drawMenu(gc) drawScore(gc) gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",8) gc:drawString("Lua CubeField - Par Loic Pujet",10,200,"top") timer.start(0.01) end
functionon.timer() timer.stop() updateCubes() updateMove() ifnot menu then score=score+1 if score%1000==0then levelUp() end end platform.window:invalidate() end
functionon.enterKey() if menu then menu=false speed=0.1 moving=false score=0 level=1 color={225,170,0} for i=1,27do cubesY[i]=cubesY[i]-5 end end end
functionon.arrowLeft() ifnot menu then dir=-1 moving=true moveStart=timer.getMilliSecCounter() end end
functionon.arrowRight() ifnot menu then dir=1 moving=true moveStart=timer.getMilliSecCounter() end end
functionon.charIn(ch) if ch=="6"then on.arrowRight() elseif ch=="4"then on.arrowLeft() end end