(BTW, my Nspire Computer Software free trial expired. Could someone just copy/paste and post the code on page 1.1 of the attached document ? Thanks.)Do you mean that this is made in OcLua and that you need a "real" document?
Right now I'm not in windows, but I'll try to do it later. (or someone else might beat me)And my Ubuntu 11.10 is out of order D:< (crappy video driver and crappy new ubuntu update and crappy dual screen ... have to reformat everything - cool story bro').
Right now I'm not in windows, but I'll try to do it later. (or someone else might beat me)And my Ubuntu 11.10 is out of order D:< (crappy video driver and crappy new ubuntu update and crappy dual screen ... have to reformat everything - cool story bro').
cubesX={1,5,7,6,4,6,4,1,3,2,3,7,8,9,1,2,3,4,2,6,7,1,9,1,2,3,4}
cubesY={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,<nod;/node>
cubesY[i]=cubesY[i]+step
if cubesY[i]>10 then
cubesX[i]=math.random(10,140)/10+player
cubesY[i]=1
end
end
end
function updateMove()
if moving then
player=player+0.04*dir
if timer.getMilliSecCounter()-moveStart>=150 then
moving=false
end
end
end
function drawPlayer(gc)
if not menu then
--gc:drawImage(playerImg,149,192)
gc:setColorRGB(100,100,100)
gc:fillRect(149,192,20,20)
end
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")
if not highscore then
var.store("highscore",0)
highscore=0
end
if score>highscore 7,7,8,8,8,9,9,9}
player=0
speed=0.05
moving=false
dir=1
moveStart=0
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)
if not menu then
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",12)
gc:drawString(tostring(score),2,0,"top")
end
end
function levelUp()
speed=speed+0.01
level=level+1
if (level-1)%5==0 then
color={225,170,0}
elseif (level-1)%5==1 then
color={0,0,255}
elseif (level-1)%5==2 then
color={100,100,100}
elseif (level-1)%5==3 then
color={90,255,0}
elseif (level-1)%5==4 then
color={255,255,255}
end
end
function on.paint(gc)
render(gc)
drawPlayer(gc)
drawMenu(gc)
drawScore(gc)<t;>menu=true
score=0
level=1
color={225,170,0}
function render(gc)
<leaf name="1word"&g/node>
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
function on.timer()
timer.stop()
updateCubes()
updateMove()
if not menu then
score=score+1
if score%1000==0 then
levelUp()
end
end
platform.window:invalidate()
end
function on.escapeKey()
menu=true
end
function on.enterKey()
if menu then
menu=false
speed=0.05
moving=false
score=0
level=1
color={225,170,0}
for i=1,27 do
cubesY[i]=cubesY[i]-5
end
end
end
function on.arrowLeft()
if not menu then
dir=-1
moving=true
moveStart=timer.getMilliSecCounter()
<leaf name="1word"t;gc:setColorRGB(0,0,0)
gc:drawLine(0,60,317,60)
local size,x,y
for i=1,27 do
end
end
function on.arrowRight()
if not menu then
dir=1
moving=true
moveStart=timer.getMilliSecCounter()
end
end<ce="1word">size=cubesY[i]*cubesY[i]/1.5+8
x=(cubesX[i]-7-player)*20*(cubesY[i]*cubesY[i]/20+0.5)-size/2+160
y=cubesY[i]*cubesY[i]*2+50
if cubesY[i]>1 then
gc:setColorRGB(color[1],color[2],color[3])
gc:fillRect(x,y,size,size)
gc:setColorRGB(0,0,0)
gc:drawRect(x,y,size,size)
end
if cubesY[i]>7.5 and cubesY[i]<8.5 then
if x<167 and x+size>151 then
on.escapeKey()
end
end
end
end
function updateCubes()
local step=menu and 0.05 or speed
for i=1,27 do
cubesY[i]=cubesY[i]+step
if cubesY[i]>10 then
cubesX[i]=math.random(10,140)/10+player
cubesY[i]=1
end
end
end
function updateMove()
if moving then
player=player+0.04*dir
if timer.getMilliSecCounter()-moveStart>=150 then
moving=false
end
end
end
function drawPlayer(gc)
if not menu then
--gc:drawImage(playerImg,149,192)
gc:setColorRGB(100,100,100)
gc:fillRect(149,192,20,20)
end
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")
if not 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)
if not menu then
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",12)
gc:drawString(tostring(score),2,0,"top")
end
end
function levelUp()
speed=speed+0.01
level=level+1
if (level-1)%5==0 then
color={225,170,0}
elseif (level-1)%5==1 then
color={0,0,255}
elseif (level-1)%5==2 then
color={100,100,100}
elseif (level-1)%5==3 then
color={90,255,0}
elseif (level-1)%5==4 then
color={255,255,255}
end
end
function on.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
function on.timer()
timer.stop()
updateCubes()
updateMove()
if not menu then
score=score+1
if score%1000==0 then
levelUp()
end
end
platform.window:invalidate()
end
function on.escapeKey()
menu=true
end
function on.enterKey()
if menu then
menu=false
speed=0.05
moving=false
score=0
level=1
color={225,170,0}
for i=1,27 do
cubesY[i]=cubesY[i]-5
end
end
end
function on.arrowLeft()
if not menu then
dir=-1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
function on.arrowRight()
if not menu then
dir=1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
playerImg=image.new("\\020\\000\\000\\000\\020\\000\\000\\000\\000\\000\\000\\000\\040\\000\\000\\000\\016\\000\\001\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\00me="1word"/>
function drawMenu(gc)
if menu then
gc:setColorRGB(0,0,0)
00\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\151\\194\\000\\128\\000\\128\\000\\128\\000\\128\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\000\\000\\128\\151\\194\\151\\194\\151\\194\\000\\128\\000\\128\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\000\\128\\000\\128\\061\\215\\061\\215\\061\\215\\000\\128\\000\\000\\000\\128\\151\\194\\151\\194\\000\\128\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\000\\128\\061\\215\\061\\215\\000\\128\\000\\128\\000\\128\\000\\128\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\128\\000\\128\\000\\128")
you can cheat like in Squidgetx game and simply display sprites of squares and display alternate ones when they're far away or rotating?
DJ_O :Yeah but can Lua actually display rotated polygons? If so, then that's epically awesome O.O
The function gc:fillPolygon() could be used, it would be quite easy.
Thanks for the avi btw !
Jonius7 :
The corridor would be harder... Well, I would have to create levels instead of random cubes. But I could do this.
And your latest screenie is great ! Thanks ! :)
DJ_O :Yeah but can Lua actually display rotated polygons? If so, then that's epically awesome O.O
The function gc:fillPolygon() could be used, it would be quite easy.
Thanks for the avi btw !
Jonius7 :
The corridor would be harder... Well, I would have to create levels instead of random cubes. But I could do this.
And your latest screenie is great ! Thanks ! :)
cubesX={1,5,7,6,4,6,4,1,3,2,3,7,8,9,1,2,3,4,2,6,7,1,9,1,2,3,4}
cubesY={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9}
lastCube=1
player=0
speed=0.08
moving=false
dir=1
moveStart=0
menu=true
score=0
level=1
color={225,170,0}
rotation=0
function render(gc)
drawHorizon(gc)
local size,x,y,i,polygon
for j=1,27 do
i=(j+lastCube-2)%27+1
size=cubesY[i]*cubesY[i]/1.5+8
x=(cubesX[i]-7-player)*20*(cubesY[i]*cubesY[i]/20+0.5)-size/2
y=cubesY[i]*cubesY[i]*2-152
polygon=rotate({x,y,x+size,y,x+size,y+size,x,y+size,x,y})
if cubesY[i]>1 then
gc:setColorRGB(color[1],color[2],color[3])
gc:fillPolygon(polygon)
gc:setColorRGB(0,0,0)
gc:drawPolyLine(polygon)
end
if cubesY[i]>7.5 and cubesY[i]<8.5 then
if x<7 and x+size>-7 then
on.escapeKey()
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 and 0.06 or speed
for i=1,27 do
cubesY[i]=cubesY[i]+step
if cubesY[i]>10 then
if score%1000<800 then
cubesX[i]=math.random(10,140)/10+player
else
cubesX[i]=math.random(10,140)/100+player+(i-1)%2*5+4
end
cubesY[i]=1
lastCube=lastCube==1 and 27 or lastCube-1
end
end
end
function updateMove()
if moving then
player=player+0.07*dir
if math.abs(rotation)<0.1 then
rotation=rotation-0.005*dir
end
if timer.getMilliSecCounter()-moveStart>=150 then
moving=false
end
else
if math.abs(rotation)>0.005 then
rotation=rotation-0.005*rotation/math.abs(rotation)
end
end
end
function drawPlayer(gc)
if not menu then
--gc:drawImage(playerImg,149,192)
gc:setColorRGB(100,100,100)
gc:fillRect(149,192,20,20)
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")
if not 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)
if not menu then
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",12)
gc:drawString(tostring(score),2,0,"top")
if score%1000>950 then
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==0 then
color={225,170,0}
elseif (level-1)%5==1 then
color={0,0,255}
elseif (level-1)%5==2 then
color={100,100,100}
elseif (level-1)%5==3 then
color={90,255,0}
elseif (level-1)%5==4 then
color={255,255,255}
end
end
function on.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
function on.timer()
timer.stop()
updateCubes()
updateMove()
if not menu then
score=score+1
if score%1000==0 then
levelUp()
end
end
platform.window:invalidate()
end
function on.escapeKey()
menu=true
end
function on.enterKey()
if menu then
menu=false
speed=0.08
moving=false
score=0
level=1
color={225,170,0}
for i=1,27 do
cubesY[i]=cubesY[i]-5
end
end
end
function on.arrowLeft()
if not menu then
dir=-1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
function on.arrowRight()
if not menu then
dir=1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
function on.charIn(ch)
if ch=="6" then
on.arrowRight()
elseif ch=="4" then
on.arrowLeft()
end
end
I've just tested and it is quite nice =)Yeah I noticed that too. Sometimes I find myself going between two blocks, expecting to pass through, but the area becomes narrower and narrower, then I die.
the only thing I would say is that the paralax is a bit strange. Closer objects are going slower than Far ones. It is a bit difficult to go between to cubes along Z axis (forward).
You really well managed game-events (speed up), but I think you better make it faster to come, don't you think ?
I haven't looked at the code yet.
the only thing I would say is that the paralax is a bit strange. Closer objects are going slower than Far ones. It is a bit difficult to go between to cubes along Z axis (forward).Yeah I noticed that too. Sometimes I find myself going between two blocks, expecting to pass through, but the area becomes narrower and narrower, then I die.[/quote]Same. Remember that close objects are supposed to approach faster, or they seem to slow down.
Sorry for double-posting, but...
Update ! (again)
-There is a nice sprite for the player
-The corridor is more regular
I just modified the source which Adriweb gave to me, so no need to extract the code this time.
I think this is the final release...
Jonius7, could you please do another animated screenshot ? :)
Final source code :Spoiler For Spoiler:
DOWNLOAD (http://www.omnimaga.org/index.php?action=dlattach;topic=10924.0;attach=10009)
My highscore with the latest version is 5064...1109 D:
and yes from DJ_O and DT, there is this gap oftentimes which should look passable, but instead the precision of moving left and right isn't great and BAM! game over.
It's awesome but the key responding is kinda bad D:Not his fault. Nspire Lua doesn't repeat keypresses at all.
so that key problem won't be solved until ndless 3?Ndless doesn't affect Lua at all, does it?
CUBEFIELD
|-------------------------------------------------------------------------------|
|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 |
|-------------------------------------------------------------------------------|
I think that you should write "Survive as long as you can without getting hitten by the cubes!" but an answer from someone whose first language is English would be better ;D"getting hit" is correct. There don't seem to be any problems with the readme.
Hayleia :I learnt them a long time ago, (hit/hit/hit) but now, in English class, we learn to discuss about topics, we don't learn to speak anymore D:
Haven't you learnt the irregular verbs ?
(j/k :D )
Okay, I'll upload it
Final Fantasy.Hmm probably not. Starwing is doable. (put an FX chip in your nspire!!)
/me runs
Are you also planning to upload it in Omnimaga archives Chokosta by the way?Oh, I always forget to upload my games on Omni. (Don't know why :) )
Well he might want to rename it to Star Fox if he does that or include both name in the readme, since a lot of Nspire users are from United States (and Starwing in USA is called Star Fox). It could be possible if he manages to gain a decent framerate out of his 3D engine. Else he could do Space Dementia, which is similar but has no floor nor building obstacles.Yes, I really should use my 3D engine... Space Dementia/StarFox is a good idea :)
Final Fantasy type games tend to be rather hard for someone who only made arcade games before. Usually people will only do one of both, although a CX RPG is definitively doable (after all I did 23 RPGs on the 83+ I think)
playerImg=image.new("\020\000\000\000\020\000\000\000\000\000\000\000(\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\128\000\128\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128")
cubesX={1,5,7,6,4,6,4,1,3,2,3,7,8,9,1,2,3,4,2,6,7,1,9,1,2,3,4}
cubesY={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9}
lastCube=1
player=0
speed=0.08
moving=false
dir=1
moveStart=0
menu=true
score=0
level=1
color={225,170,0}
rotation=0
lastTick=0
delay=0
function render(gc)
drawHorizon(gc)
local size,x,y,i,polygon
for j=1,27 do
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]>1 then
gc:setColorRGB(color[1],color[2],color[3])
gc:fillPolygon(polygon)
gc:setColorRGB(0,0,0)
gc:drawPolyLine(polygon)
end
if y+size>3 and y<17 then
if x<6 and x+size>-6 then
menu=true
score=math.floor(score)
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 and 0.06 or speed
for i=1,27 do
cubesY[i]=cubesY[i]+step*delay/30
if cubesY[i]>10 then
if score%1000<800 then
cubesX[i]=math.random(0,140)/10+player
else
cubesX[i]=math.random(0,140)/200+player+(i-1)%2*5+4.1
end
cubesY[i]=cubesY[i]-9
lastCube=lastCube==1 and 27 or lastCube-1
end
end
end
function updateMove()
if moving then
player=player+0.07*dir*delay/30
if math.abs(rotation)<0.15 or dir==rotation/math.abs(rotation) then
rotation=rotation-0.005*dir*delay/30
end
if timer.getMilliSecCounter()-moveStart>=150 then
moving=false
end
else
if math.abs(rotation)>0.005 then
rotation=rotation-0.005*rotation/math.abs(rotation)*delay/30
end
end
end
function drawPlayer(gc)
if not 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")
if not 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)
if not menu then
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",12)
gc:drawString(tostring(math.floor(score)),2,0,"top")
if score%1000>950 then
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==0 then
color={225,170,0}
elseif (level-1)%5==1 then
color={0,0,255}
elseif (level-1)%5==2 then
color={100,100,100}
elseif (level-1)%5==3 then
color={90,255,0}
elseif (level-1)%5==4 then
color={255,255,255}
end
end
function on.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")
updateFPS()
timer.start(0.01)
end
function on.timer()
timer.stop()
updateCubes()
updateMove()
if not menu then
score=score+delay/30
if score>level*1000 then
levelUp()
end
end
platform.window:invalidate()
end
function on.enterKey()
if menu then
menu=false
speed=0.08
moving=false
score=0
level=1
color={225,170,0}
for i=1,27 do
cubesY[i]=cubesY[i]-5
end
end
end
function on.arrowLeft()
if not menu then
dir=-1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
function on.arrowRight()
if not menu then
dir=1
moving=true
moveStart=timer.getMilliSecCounter()
end
end
function on.charIn(ch)
if ch=="6" then
on.arrowRight()
elseif ch=="4" then
on.arrowLeft()
end
end
function updateFPS()
delay=timer.getMilliSecCounter()-lastTick
delay=delay<300 and delay or 0
lastTick=timer.getMilliSecCounter()
end
-Add a minimum value for the space between the two blocks appearing at once, so we don't end up stuck in dead-ends as much or without enough space to go between two blocks.I think the original cubefield allowed cubes to get as close as touching edges with each other, but not overlapping. That could be something to consider.
-Allow going behind blocks. Right now we have to wait until we're about 4 steps away from a block before being able to move behind it, else we die.This would be quite hard to do. I would have to change my collision detection. And since my blocks are squares and not cubes, they dont have a defined thickness. (I'm not sure this is the correct word)
-Add a minimum value for the space between the two blocks appearing at once, so we don't end up stuck in dead-ends as much or without enough space to go between two blocks.This is possible, but I think it would possibly become too easy. I will test this.
My 3D engine is too slow for that, it wouldn't be a good idea to use it.Aw shnikeys
About criss cross paths, I can try... But now I'm working on others projects, so you have to wait a bit :)