Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lcb = 0
- function loadcallback()
- screen.print(370,255,string.sub("Kaboom!!!!",1,math.floor(lcb)))
- screen.flip()
- lcb = lcb + 1.5
- end
- --SCENERYBETA SPLASH HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- os.cpu(333) --A little powah for loading all
- if os.language() == "spanish" then
- _moves = "movidas: %i"
- _level = "Nivel %i"
- _level_completed = "Nivel completado."
- _record = "Récord: %i"
- _congrats = "Felicidades, has compltado el juego!\n¿Deseas volver a jugar?"
- else
- _moves = "moves: %i"
- _level_completed = "Level completed."
- _level = "Level %i"
- _record = "Record: %i"
- congrats = "Congratulations, you have completed the game!\nWould you like to play again?"
- end
- prism = {obj=model.load("models/prism.obj")}
- sel = {obj=model.load("models/selector.obj"),x=1,y=1}
- sel2 = {obj=model.load("models/selector2.obj"),x=1,y=1,rot=0}
- exit = {obj=model.load("models/exit.obj")}
- cube = {obj=model.load("models/cube.obj")}
- floor = {obj=model.load("models/floor.obj")}
- bg = image.load("images/background.png")
- record = {}
- cnv = tonumber(ini.read("config.ini","currentlevel",1)) or 1 --Currentlevel
- map = {
- {
- --Level 1
- {"","","","",""},
- {"v","c","","",""},
- {"","","","",""},
- {"","","c","",""},
- {"","","e","",""}
- },
- {
- --Level 2
- {"", "", "", "d", "c", "", "", ""},
- {"", "", "", "", "", "", "", ""},
- {"", "c", "", "c", "", "", "", "c"},
- {"", "", "", "", "", "c", "", ""},
- {"", "", "c", "", "", "", "", ""},
- {"", "", "", "", "", "c", "", ""},
- {"", "", "c", "", "", "", "", ""},
- {"", "", "", "", "", "c", "e", "e"}
- },
- {
- --Level 3
- {"", "", "", "", "", "", "", ""},
- {"", "", "", "", "", "", "", ""},
- {"", "c", "", "", "", "", "", ""},
- {"", "", "", "c", "", "", "c", ""},
- {"", "", "", "", "", "", "", ""},
- {"", "", "", "v", "", "", "c", ""},
- {"e", "", "", "c", "", "", "", ""},
- {"c", "", "", "", "", "", "", ""}
- },
- {
- --Level 4
- {"", "", "", "", "", "c", "", ""},
- {"", "c", "c", "", "", "", "", ""},
- {"", "", "", "", "", "c", "", ""},
- {"", "e", "v", "c", "", "", "", ""},
- {"c", "", "", "c", "", "", "", "c"},
- {"c", "", "c", "", "", "c", "", ""},
- {"", "", "", "", "c", "", "", ""},
- {"", "", "", "", "", "", "", ""}
- }
- }
- creator_map = {
- {"","","","","","",""},
- {"","","","","","",""},
- {"","","","","","",""},
- {"","","","","","",""},
- {"","","","","","",""},
- {"","","","","","",""},
- {"","","","","","",""}
- }
- function read_record()
- for i = 1, #map do
- record[i] = tonumber(ini.read("config.ini","level"..i,1)) or 1
- end
- end
- read_record()
- --Y->z
- --X->x
- --Z->y
- exit_coord = {}
- map.height = #map[cnv]
- map.width = #map[cnv][1]
- map.w=10
- map.h=5
- map.d=10
- pos={x=-map.width*5,y=0,z=-85}
- rot={x=1,y=0,z=0}
- prism.x = 1
- prism.y = 2
- prism.x2 = 1
- prism.y2 = 1
- prism.status = "vertical"
- list={"vertical","up","down","right","left"}
- function level_creator()
- currentmodel = "cube"
- while true do
- --prism.status=list[c]
- controls.read()
- sel.move()
- blit_creator_map()
- screen.print(425,5,"@"..screen.fps(),0.77,color.new(255,255,0),color.new(0,0,0))
- screen.print(5,5,"POS: ".." x:"..sel.x.." y:"..sel.y)
- _G[currentmodel].obj:position(0,0,0)
- if controls.press("cross") then
- if currentmodel == "cube" then
- creator_map[sel.y][sel.x] = "c"
- end
- end
- if controls.press("triangle") then
- str = ""
- if os.message("¿Deseas guardar el nivel?",1)== 1 then
- for y = 1, #creator_map do
- if y < #creator_map then
- str = str..string.implode(creator_map[y],"|X|").."|Y|"
- else
- str = str..string.implode(creator_map[y],"|X|")
- end
- end
- ini.write("levels.ini","1",str)
- end
- end
- if controls.press("square") then
- str = ini.read("levels.ini","1","")
- for y = 1, #creator_map do
- if y < #creator_map then
- str = str..string.implode(creator_map[y],"|X|").."|Y|"
- else
- str = str..string.implode(creator_map[y],"|X|")
- end
- end
- end
- 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
- end
- screen.print(240-screen.textwidth("Level creator",0.9)/2,5,"Level creator",0.9,color.new(255,0,0),color.new(255,255,0))
- if controls.select() then a() end
- if controls.start() and controls.l() and controls.r() then break end
- screen.flip()
- end
- end
- function sel.move()
- if controls.press("down") then
- sel.y = sel.y+1 if sel.y > #creator_map then sel.y = 1 end
- end
- if controls.press("up") then
- sel.y = sel.y-1 if sel.y < 1 then sel.y = #creator_map end
- end
- if controls.press("right") then
- sel.x = sel.x+1 if sel.x > #creator_map[1] then sel.x = 1 end
- end
- if controls.press("left") then
- sel.x = sel.x-1 if sel.x < 1 then sel.x = #creator_map[1] end
- end
- end
- function blit_creator_map()
- sel2.rot = sel2.rot+0.03
- bg:blit(0,0)
- 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, #creator_map do
- for x = 1, #creator_map[y] 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 creator_map[y][x] != "" then
- if creator_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 creator_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
- if x == sel.x and y == sel.y then
- sel.obj:rotation(rot.x,rot.y,rot.z)
- sel.obj:position(pos.x +((x-0.5)*map.w), pos.y + math.sin(-rot.x)*(y-ny-0.5)*map.w,pos.z + math.cos(-rot.x)*(y-ny-0.5)*map.w)
- sel.obj:blit()
- sel2.obj:rotation(rot.x,rot.y+sel2.rot,rot.z)
- sel2.obj:position(pos.x +((x-0.5)*map.w),pos.y + math.sin(-rot.x)*((y-0.5)-ny)*map.w+math.sin(1.57-rot.x)*1, pos.z + math.cos(-rot.x)*((y-0.5)-ny)*map.w+math.cos(1.57-rot.x)*1)
- sel2.obj:blit()
- end
- end
- end
- end
- function change_level(n)
- exit_coord = nil
- exit_coord = {}
- map.height = #map[n]
- map.width = #map[n][1]
- for y = 1, map.height do
- for x = 1, map.width do
- if map[n][y][x] == "e" then
- table.insert(exit_coord,{x=x,y=y})
- elseif map[n][y][x] == "v" then
- prism.x = x
- prism.y= y
- prism.status="vertical"
- elseif map[n][y][x] == "r" then
- prism.x = x
- prism.y= y
- prism.status="right"
- elseif map[n][y][x] == "l" then
- prism.x = x
- prism.y= y
- prism.status="left"
- elseif map[n][y][x] == "u" then
- prism.x = x
- prism.y= y
- prism.status="up"
- elseif map[n][y][x] == "d" then
- prism.x = x
- prism.y= y
- prism.status="down"
- end
- end
- end
- map.height = #map[cnv]
- map.width = #map[cnv][1]
- prism.moves=0
- end
- function level_completed()
- blit_map()
- blit_info()
- screen.flip()
- if record[cnv] == 0 or prism.moves < record[cnv] then
- ini.write("config.ini",tostring("level"..cnv),tostring(prism.moves))
- end
- ini.write("config.ini","currentlevel",tostring(cnv))
- if cnv < #map then
- os.message(_level_completed)
- cnv = cnv+1
- change_level(cnv)
- else
- if os.message(_congrats,1) == 1 then
- cnv = 1
- read_record()
- change_level(cnv)
- else
- --os.exit()
- asfbfdhdhrhrehreh()
- end
- end
- end
- function check_exit()
- if prism.status == "right" then prism.x2 = prism.x+1; prism.y2 = prism.y end
- if prism.status == "left" then prism.x2 = prism.x-1; prism.y2 = prism.y end
- if prism.status == "up" then prism.x2 = prism.x; prism.y2 = prism.y-1 end
- if prism.status == "down" then prism.x2 = prism.x; prism.y2 = prism.y+1 end
- if #exit_coord == 1 then
- if prism.status == "vertical" and exit_coord[1].x == prism.x and exit_coord[1].y == prism.y then
- level_completed()
- end
- elseif #exit_coord == 2 and prism.status != "vertical" then
- if (exit_coord[1].x == prism.x and exit_coord[1].y == prism.y and exit_coord[2].x == prism.x2 and exit_coord[2].y == prism.y2) or
- (exit_coord[2].x == prism.x and exit_coord[2].y == prism.y and exit_coord[1].x == prism.x2 and exit_coord[1].y == prism.y2) then
- level_completed()
- end
- end
- end
- function blit_map()
- bg:blit(0,0)
- 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[cnv][y][x] != "" then
- if map[cnv][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[cnv][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[cnv][y][x]
- else
- return "c"
- end
- end
- 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"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "up" then
- if xy(prism.y +1,prism.x) != "c" then
- prism.y = prism.y+1
- prism.status = "vertical"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "down" 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"
- prism.moves = prism.moves+1
- 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
- prism.moves = prism.moves+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
- prism.moves = prism.moves+1
- end
- end
- check_exit()
- 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"
- prism.moves = prism.moves+1
- 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"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "down" then
- if xy(prism.y -1,prism.x) != "c" then
- prism.y = prism.y-1
- prism.status = "vertical"
- prism.moves = prism.moves+1
- 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
- prism.moves = prism.moves+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
- prism.moves = prism.moves+1
- end
- end
- check_exit()
- end
- if controls.press("right") then
- if prism.status == "vertical" then
- if xy(prism.y ,prism.x+1) != "c" and xy(prism.y ,prism.x+2) != "c" then
- prism.x = prism.x+1
- prism.status = "right"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "up" then
- if xy(prism.y ,prism.x+1) != "c" and xy(prism.y-1 ,prism.x+1) != "c" then
- prism.x = prism.x+1
- prism.moves = prism.moves+1
- end
- elseif prism.status == "down" then
- if xy(prism.y ,prism.x+1) != "c" and xy(prism.y+1 ,prism.x+1) != "c" then
- prism.x = prism.x+1
- prism.moves = prism.moves+1
- end
- elseif prism.status == "right" then
- if xy(prism.y ,prism.x+1) != "c" and xy(prism.y ,prism.x+2) != "c" then
- prism.x = prism.x+2
- prism.status = "vertical"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "left" then
- if xy(prism.y ,prism.x+1) != "c" then
- prism.x = prism.x+1
- prism.status = "vertical"
- prism.moves = prism.moves+1
- end
- end
- check_exit()
- end
- if controls.press("left") then
- if prism.status == "vertical" then
- if xy(prism.y ,prism.x-1) != "c" and xy(prism.y ,prism.x-2) != "c" then
- prism.x = prism.x-1
- prism.status = "left"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "up" then
- if xy(prism.y ,prism.x-1) != "c" and xy(prism.y-1 ,prism.x-1) != "c" then
- prism.x = prism.x-1
- prism.moves = prism.moves+1
- end
- elseif prism.status == "down" then
- if xy(prism.y ,prism.x-1) != "c" and xy(prism.y+1 ,prism.x-1) != "c" then
- prism.x = prism.x-1
- prism.moves = prism.moves+1
- end
- elseif prism.status == "right" then
- if xy(prism.y ,prism.x-1) != "c" then
- prism.x = prism.x-1
- prism.status = "vertical"
- prism.moves = prism.moves+1
- end
- elseif prism.status == "left" then
- if xy(prism.y ,prism.x-2) != "c" then
- prism.x = prism.x-2
- prism.status = "vertical"
- prism.moves = prism.moves+1
- end
- end
- check_exit()
- end
- end
- function blit_info()
- screen.print(5,5,string.format(_level,cnv)..", "..string.format(_moves,prism.moves),0.77,color.new(255,0,0),color.new(0,255,0))
- screen.print(425,5,"@"..screen.fps(),0.77,color.new(255,255,0),color.new(0,0,0))
- screen.print(405,255,"R: Reset",0.77,color.new(0,255,0),color.new(0,0,0))
- screen.print(5,25,string.format(_record,record[cnv]),0.77,color.new(255,0,0),color.new(0,255,0))
- end
- change_level(cnv)
- level_creator()
- while true do
- 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
- end
- if controls.press("r") then --Reset level
- change_level(cnv)
- end
- prism.move()
- blit_map()
- blit_info()
- if controls.select() then a() end
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement