0 Members and 2 Guests are viewing this topic.
function on.enterKey() maze={{0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0}} leveldata={{4,4,1,50,50,50,6}} mazewidth=leveldata[lev][1] mazeheight=leveldata[lev][2] move=leveldata[lev][3] blockwidth=leveldata[lev][4] pacx=leveldata[lev][5] pacy=leveldata[lev][6] gm=leveldata[lev][7] dir=1 mouth=1 m=1 timer.start(.01)endfunction on.tabKey() lev=1 on.enterKey()endfunction dirx() if dir==1 then return move elseif dir==2 or dir==4 then return 0 else return 0-move endendfunction diry() if dir==4 then return move elseif dir==1 or dir==3 then return 0 else return 0-move endendfunction wallcheck() if dir==1 then if maze[lev][gm+1]==0 then return false else return true end elseif dir==2 then if maze[lev][gm-mazewidth]==0 then return false else return true end elseif dir==3 then if maze[lev][gm-1]==0 then return false else return true end elseif dir==4 then if maze[lev][gm+mazewidth]==0 then return false else return true end endendfunction gmchange() if dir==1 then gmchan=1 elseif dir==2 then gmchan=0-mazewidth elseif dir==3 then gmchan=0-1 elseif dir==4 then gmchan=mazewidth endendon.tabKey()function on.paint(gc) for a=1, mazeheight do for b=1, mazewidth do local n=maze[lev][mazewidth*(a-1)+b] if n==0 then gc:fillRect(blockwidth*(b-1),blockwidth*(a-1),blockwidth,blockwidth) end end end gc:fillArc(pacx,pacy,blockwidth,blockwidth,45,315+45*mouth)endfunction on.timer()if m~=blockwidth then pacx=pacx+dirx() pacy=pacy+diry() m=m+1elseif m==blockwidth then gmchange() gm=gm+gmchan if wdir~=0 then dir=wdir wdir=0 end if wallcheck() then pacx=pacx+dirx() pacy=pacy+diry() m=1 endendmouth=0-mouthplatform.window:invalidate()endfunction on.arrowKey(key) if key=="left" then if m~=blockwidth then wdir=3 else dir=3 end elseif key=="right" then if m~=blockwidth then wdir=1 else dir=1 end elseif key=="up" then if m~=blockwidth then wdir=2 else dir=2 end elseif key=="down" then if m~=blockwidth then wdir=4 else dir=4 end endplatform.window:invalidate()end
I am a proud cynic.
First try to locate the problem by removing the code which doesn't contribue to it.Use a set of calls to print() to identify precisely what's wrong with the program flow. Tell us what you expected to be printed, and what is actually printed.You will probably get more help with this.
print() outputs strings to the console on nspire_emu.