Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(os.time())
- os.cpu(333) --A little powah for loading all
- lcb = 0
- function loadcallback()
- screen.print(370,255,"Cargandeh"..string.sub("...",1,math.floor(lcb)))
- screen.flip()
- lcb = lcb + 0.05 if lcb > 4 then lcb = 0 end
- end
- prism = {obj=model.load("models/prism.obj")}
- exit = {obj=model.load("models/exit.obj")}
- cube = {obj=model.load("models/cube.obj")}
- floor = {obj=model.load("models/floor.obj")}
- map = {
- {"","","c","",""},
- {"","","e","",""},
- {"","","","c",""},
- {"","","","",""},
- {"","","c","",""},
- }
- map.height = #map
- map.width = #map[1]
- map.w=10
- map.h=5
- map.d=10
- --Y->z
- --X->x
- --Z->y
- pos={x=-map.width*5+5,y=0,z=-75}
- rot={x=1,y=0,z=0}
- prism.x = 2
- prism.y = 2
- prism.status = "down"
- list={"vertical","up","down","right","left"}
- c=1
- function blit_map()
- local depth = 0
- local p={x=0,y=0,z=0}
- local r={x=0,y=0,z=0}
- local sp = {x=0,y=0,z=0}
- local sr = {x=0,y=0,z=0}
- local ny = map.height/2
- for y = 1, map.height do
- for x = 1, map.width do
- --Calculate the position of empty models
- p.x = pos.x +((x-1)*map.w)
- p.y = pos.y + math.sin(-rot.x)*(y-ny)*map.w
- p.z = pos.z + math.cos(-rot.x)*(y-ny)*map.w
- --Blit the empty models
- floor.obj:rotation(rot.x ,rot.y, rot.z)
- floor.obj:position(p.x, p.y, p.z)
- floor.obj:blit()
- if x== prism.x and y == prism.y then
- if prism.status == "up" then
- sp.x = p.x
- sp.y = p.y+math.sin(1.57-rot.x)*15
- sp.z = p.z+math.cos(1.57-rot.x)*15
- sr.x = rot.x-1.57
- sr.y = rot.y
- sr.z = rot.z
- elseif prism.status == "down" then
- sp.x = p.x
- sp.y = pos.y + math.sin(-rot.x)*((y-1)-ny)*map.w+math.sin(1.57-rot.x)*5
- sp.z = pos.z + math.cos(-rot.x)*((y-1)-ny)*map.w+math.cos(1.57-rot.x)*5
- sr.x = rot.x+1.57
- sr.y = rot.y
- sr.z = rot.z
- elseif prism.status == "right" then
- sp.x = p.x
- sp.y = pos.y+ math.sin(-rot.x)*((y-1)-ny)*map.w+math.sin(1.57-rot.x)*15
- sp.z = pos.z + math.cos(-rot.x)*((y-1)-ny)*map.w+math.cos(1.57-rot.x)*15
- sr.x = rot.x-1.57
- sr.y = rot.y
- sr.z = rot.z-1.57
- elseif prism.status == "left" then
- sp.x = pos.x +(x*map.w)
- sp.y = p.y+math.sin(1.57-rot.x)*15
- sp.z = p.z+math.cos(1.57-rot.x)*15
- sr.x = rot.x-1.57
- sr.y = rot.y
- sr.z = rot.z+1.57
- elseif prism.status == "vertical" then
- sp.x = p.x
- sp.y = p.y+math.sin(1.57-rot.x)*5
- sp.z = p.z+math.cos(1.57-rot.x)*5
- sr.x = rot.x
- sr.y = rot.y
- sr.z = rot.z
- end
- prism.obj:rotation(sr.x,sr.y,sr.z)
- prism.obj:position(sp.x,sp.y,sp.z)
- prism.obj:blit()
- end
- if map[y][x] != "" then
- if map[y][x] == "c" then
- cube.obj:position(p.x,p.y+math.sin(1.57-rot.x)*5,p.z+math.cos(1.57-rot.x)*5)
- cube.obj:rotation(rot.x,rot.y,rot.z)
- cube.obj:blit()
- elseif map[y][x] == "e" then
- exit.obj:position(p.x,p.y+math.sin(1.57-rot.x)*5,p.z+math.cos(1.57-rot.x)*5)
- exit.obj:rotation(rot.x,rot.y,rot.z)
- exit.obj:blit()
- end
- end
- end
- end
- end
- function xy(y,x)
- if x >0 and y > 0 and x <= map.width and y<=map.height then
- return map[y][x]
- else
- return "c"
- end
- end
- prism.status = "vertical"
- function prism.move()
- if controls.press("down") then
- if prism.status == "vertical" then
- if xy(prism.y +1,prism.x) != "c" and xy(prism.y +2,prism.x) != "c" then
- prism.y = prism.y+1
- prism.status = "down"
- end
- elseif prism.status == "up" then
- if xy(prism.y +1,prism.x) != "c" and xy(prism.y +2,prism.x) != "c" then
- prism.y = prism.y+1
- prism.status = "vertical"
- end
- elseif prism.status == "down" then
- if xy(prism.y +1,prism.x) != "c" then
- prism.y = prism.y+2
- prism.status = "vertical"
- end
- elseif prism.status == "right" then
- if xy(prism.y +1,prism.x) != "c" and xy(prism.y +1,prism.x+1) != "c" then
- prism.y = prism.y+1
- end
- elseif prism.status == "left" then
- if xy(prism.y +1,prism.x) != "c" and xy(prism.y +1,prism.x-1) != "c" then
- prism.y = prism.y+1
- end
- end
- end
- if controls.press("up") then
- if prism.status == "vertical" then
- if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
- prism.y = prism.y-1
- prism.status = "up"
- end
- elseif prism.status == "up" then
- if xy(prism.y -1,prism.x) != "c" and xy(prism.y -2,prism.x) != "c" then
- prism.y = prism.y-2
- prism.status = "vertical"
- end
- elseif prism.status == "down" then
- if xy(prism.y -1,prism.x) != "c" then
- prism.y = prism.y-1
- prism.status = "vertical"
- end
- elseif prism.status == "right" then
- if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x+1) != "c" then
- prism.y = prism.y-1
- end
- elseif prism.status == "left" then
- if xy(prism.y -1,prism.x) != "c" and xy(prism.y -1,prism.x-1) != "c" then
- prism.y = prism.y-1
- end
- end
- end
- if controls.press("right") then
- end
- if controls.press("left") then
- end
- end
- while true do
- --prism.status=list[c]
- controls.read()
- if controls.start() then
- --POS
- if controls.up() then pos.y = pos.y+0.5 end
- if controls.down() then pos.y = pos.y-0.5 end
- if controls.left() then pos.x = pos.x-0.5 end
- if controls.right() then pos.x = pos.x+0.5 end
- if controls.l() then pos.z = pos.z-0.5 end
- if controls.r() then pos.z = pos.z+0.5 end
- --ROT
- if controls.triangle() then rot.y = rot.y+0.05 end
- if controls.cross() then rot.y = rot.y-0.05 end
- if controls.square() then rot.x = rot.x-0.05 end
- if controls.circle() then rot.x = rot.x+0.05 end
- if math.abs(controls.analogy())> 50 then rot.x = rot.x+controls.analogy()/2000 end
- else
- prism.move()
- if controls.press("l") then c= c-1 if c<1 then c = #list end end
- if controls.press("r") then c= c+1 if c>#list then c = 1 end end
- end
- blit_map()
- screen.print(5,5,"ROT: ".." x:"..rot.x.." y:"..rot.y.." z:"..rot.z)
- screen.print(5,25,"POS: ".." x:"..pos.x.." y:"..pos.y.." z:"..pos.z)
- screen.print(5,45,"Prism: ".." x:"..prism.x.." y:"..prism.y.." status:"..prism.status)
- screen.print(425,5,"@"..screen.fps())
- if controls.select() then a() end
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement