Lightspeed Alpha v1.0
Description
Hello everyone! Today I present to you: Lightspeed v1.0!I've been working in this for quite some time now. It has:- A world to explore- Ships to fight with- Enemies to fight against (three different t...
Installation
Copy one of these commands into your ComputerCraft terminal:
Pastebin:
pastebin get JjFsqCMD lightspeed_alpha_v1.0wget:
wget https://pastebin.com/raw/JjFsqCMD lightspeed_alpha_v1.0Archive:
wget https://cc.shobie.xyz/cc/get/pb-JjFsqCMD lightspeed_alpha_v1.0
Quick Install:
wget https://cc.shobie.xyz/cc/get/pb-JjFsqCMD Lightspeed Alpha v1.0
Usage
Run the program after downloading
Tags
Source
View Original SourceCode Preview
local fullname = "Lightspeed Alpha v1.0"
local doCompress = false
local data = {
[ "/eShip6_broken.img" ] = {
" 777b77",
" bbbfff7ff",
" 777bfff7",
" 7fffbbbbbb",
" fffffffffff",
" fffffffffff",
" 7fffb77777",
" bbbbfff7",
" 777fff7ff",
" 777b77",
},
[ "/ui" ] = {
"0000 00000000000000000000 00000",
"",
"00000000000000",
"",
"00000",
"0000 000000",
"0000000000 00000000",
"0 00000000",
" 00000000",
" 00000000",
" 0000000",
" 000000",
"",
"",
"",
" 00000 00000",
},
[ "/eShip3_broken.img" ] = {
" eeeeeee",
" e1111111f",
" eeffe1e11ff",
" fffffffef",
" ff11fffff",
" e11e111f1ff",
" 1eeeee1ef",
" 1111111",
},
[ "/eShip11_broken.img" ] = {
"",
" 777779",
" 777ff779f",
" 7999f7799f",
" 97ff9997ff",
" f7ffff7f",
" ff7f7fff",
" 7f777777ff",
" 7777ff779f",
" 7977ff79f",
" 999999",
},
[ "/eShip8_broken.img" ] = {
"",
" 7b",
" 7777bbbbf",
" 77ff77777f",
" fffff7f7f",
" ff7ffffff",
" bb77ff7f7f",
" bbbbbbbbf",
" 7b",
},
[ "/eShip4.img" ] = {
" eee",
" eeeeee111",
" e e",
" 1 1",
" 1111ee1ee",
" 111",
},
[ "/Lightspeed" ] = {
"world = {}",
"playerX = 0",
"playerY = 0",
"",
"p = shell.dir()..\"/\"",
"",
"pShips = {",
" {name = \"The Gillian\", laserx = 12, lasery = 6.5, maxHull = 18, fire = {{x = -1, y = 0}, {x = -1, y = 1}, {x = -1, y = 4}, {x = -1, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"pShip1.img\"),",
" rooms = {{rType = \"controll\", x = 8, y = 2, level = 9, damage = 0, repair = 0}, {rType = \"weapons\", x = 5, y = 2, level = 4, damage = 0, repair = 0}}},",
"",
" {name = \"Sinjin\", laserx = 12, lasery = 6.5, maxHull = 20, fire = {{x = -1, y = 0}, {x = -1, y = 1}, {x = -1, y = 4}, {x = -1, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"pShip2.img\"),",
" rooms = {{rType = \"controll\", x = 7, y = 2, level = 4, damage = 0, repair = 0}, {rType = \"weapons\", x = 3, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"shields\", x = 3, y = 3, level = 1, damage = 0, repair = 0}}},",
"}",
"",
"eShips = {",
" {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 24, y = 0}, {x = 24, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip1.img\"), image_broken = paintutils.loadImage(\"eShip1_broken.img\"),",
" rooms = {{rType = \"controll\", x = 17, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 3, level = 5, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 7, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip2.img\"), image_broken = paintutils.loadImage(\"eShip2_broken.img\"),",
" rooms = {{rType = \"controll\", x = 18, y = 1, level = 5, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 3, level = 4, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 5, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip3.img\"), image_broken = paintutils.loadImage(\"eShip3_broken.img\"),",
" rooms = {{rType = \"controll\", x = 16, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"weapons\", x = 19, y = 2, level = 2, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 2, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip4.img\"), image_broken = paintutils.loadImage(\"eShip4_broken.img\"),",
" rooms = {{rType = \"controll\", x = 15, y = 2, level = 8, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 2, level = 2, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 12, fire = {{x = 24, y = 0}, {x = 24, y = 1}, {x = 24, y = 4}, {x = 24, y = 5}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip5.img\"), image_broken = paintutils.loadImage(\"eShip5_broken.img\"),",
" rooms = {{rType = \"controll\", x = 16, y = 1, level = 1, damage = 0, repair = 0}, {rType = \"weapons\", x = 16, y = 3, level = 5, damage = 0, repair = 0}}},",
"",
"",
" {laserx = 13, lasery = 6.5, maxHull = 12, fire = {{x = 23, y = 0}, {x = 23, y = 3}, {x = 23, y = 4}, {x = 23, y = 7}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip6.img\"), image_broken = paintutils.loadImage(\"eShip6_broken.img\"),",
" rooms = {{rType = \"controll\", x = 14, y = 3, level = 4, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 1, level = 3, damage = 0, repair = 0}, {rType = \"shields\", x = 18, y = 5, level = 1, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip7.img\"), image_broken = paintutils.loadImage(\"eShip7_broken.img\"),",
" rooms = {{rType = \"controll\", x = 15, y = 2, level = 1, damage = 0, repair = 0}, {rType = \"weapons\", x = 15, y = 4, level = 5, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 6, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip8.img\"), image_broken = paintutils.loadImage(\"eShip8_broken.img\"),",
" rooms = {{rType = \"controll\", x = 15, y = 3, level = 10, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 3, level = 4, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 8, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 5}, {x = 22, y = 6}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip9.img\"), image_broken = paintutils.loadImage(\"eShip9_broken.img\"),",
" rooms = {{rType = \"controll\", x = 14, y = 3, level = 8, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 3, level = 5, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 6.5, maxHull = 10, fire = {{x = 23, y = 0}, {x = 23, y = 3}, {x = 23, y = 4}, {x = 23, y = 7}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip10.img\"), image_broken = paintutils.loadImage(\"eShip10_broken.img\"),",
" rooms = {{rType = \"controll\", x = 18, y = 3, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 18, y = 1, level = 4, damage = 0, repair = 0}, {rType = \"shields\", x = 18, y = 5, level = 1, damage = 0, repair = 0}}},",
"",
"",
" {laserx = 13, lasery = 8, maxHull = 13, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 3}, {x = 22, y = 6}, {x = 22, y = 7}, {x = 22, y = 8}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip11.img\"), image_broken = paintutils.loadImage(\"eShip11_broken.img\"),",
" rooms = {{rType = \"controll\", x = 14, y = 4, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"shields\", x = 17, y = 6, level = 2, damage = 0, repair = 0}}},",
"",
" {laserx = 13, lasery = 8, maxHull = 13, fire = {{x = 22, y = 1}, {x = 22, y = 2}, {x = 22, y = 3}, {x = 22, y = 6}, {x = 22, y = 7}, {x = 22, y = 8}},",
" wCooldown = 20, image = paintutils.loadImage(p..\"eShip12.img\"), image_broken = paintutils.loadImage(\"eShip12_broken.img\"),",
" rooms = {{rType = \"controll\", x = 14, y = 4, level = 3, damage = 0, repair = 0}, {rType = \"weapons\", x = 17, y = 2, level = 7, damage = 0, repair = 0}, {rType = \"shields\", x = 17, y = 6, level = 2, damage = 0, repair = 0}}},",
"}",
"",
"pShip = {}",
"eShip = {}",
"unlockedShips = {}",
"killCount = 0",
"",
"laserPhase = 0",
"miss = 0",
"missTime = 8",
"tick = 1",
"scrapSymbol = string.char(21)",
"stop = false",
"",
"scrap = 0",
"fuel = 0",
"score = 0",
"",
"target = -1",
"repeatShot = false",
"",
"screenWidth, screenHeight = term.getSize()",
"",
"x1 = 3",
"y1 = 4",
"",
"x2 = 26",
"y2 = 4",
"",
"function deepCopy(table)",
" local copy = {}",
"",
" for k, v in pairs(table) do",
" local subcopy = v",
"",
" if (type(v) == \"table\") then",
" subcopy = deepCopy(v)",
" end",
"",
" copy[k] = subcopy",
" end",
"",
" return copy",
"end",
"",
"function drawSpaceBackground()",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.white)",
" term.clear()",
"",
" for i = 1, 100 do",
" local x = math.random(screenWidth)",
" local y = math.random(screenHeight)",
" term.setCursorPos(x, y)",
" write(\".\")",
" end",
"end",
"",
"function drawBattle()",
" while true do",
" if (laserPhase > 0) then",
" if (laserPhase ~= 1) then",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.red)",
" for x = x1 + pShip.laserx + 2, x2 + eShip.laserx - 2 do",
" term.setCursorPos(x, math.ceil((pShip.lasery + eShip.lasery) / 2))",
" write(string.char(131))",
" end",
" else",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.black)",
" for x = x1 + pShip.laserx + 2, x2 + eShip.laserx - 2 do",
" term.setCursorPos(x, math.ceil((pShip.lasery + eShip.lasery) / 2))",
" write(\" \")",
" end",
" end",
" laserPhase = laserPhase - 1",
" end",
"",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.white)",
" term.setCursorPos(math.floor(screenWidth / 2) - 1, 8)",
"",
" if (miss > 0) then",
" write(\"Miss\")",
" miss = miss - 1",
" else",
" write(\" \")",
" end",
"",
" term.setBackgroundColor(colors.lightBlue)",
" term.setTextColor(colors.blue)",
" for i = 1, 20 do",
" term.setCursorPos(i, screenHeight)",
" if (i <= pShip.wCooldown) then",
" write(\"=\")",
" else",
" paintutils.drawPixel(i, screenHeight, colors.black)",
" end",
" end",
" for roomNr, room in pairs(pShip.rooms) do",
" if (room.rType == \"weapons\") then",
" for i = 1, room.level - room.damage do",
" pShip.wCooldown = pShip.wCooldown + 0.125",
" end",
" end",
" end",
"",
" term.setBackgroundColor(colors.lightBlue)",
" term.setTextColor(colors.blue)",
" for i = 1, 20 do",
" term.setCursorPos(screenWidth + 1 - i, screenHeight)",
" if (i <= eShip.wCooldown) then",
" write(\"=\")",
" else",
" paintutils.drawPixel(screenWidth + 1 - i, screenHeight, colors.black)",
" end",
" end",
" for roomNr, room in pairs(eShip.rooms) do",
" if (room.rType == \"weapons\") then",
" for i = 1, room.level - room.damage do",
" eShip.wCooldown = eShip.wCooldown + 0.125",
" end",
" end",
" end",
"",
" for fNr, fire in pairs(pShip.fire) do",
" if (tick == 0) then",
" fType = 187",
" if (fire.x % 2 ~= fire.y % 2) then",
" fType = 127",
" end",
" else",
" fType = 127",
" if (fire.x % 2 ~= fire.y % 2) then",
" fType = 187",
" end",
" end",
" term.setCursorPos(x1 + fire.x, y1 + fire.y)",
" term.setBackgroundColor(colors.red)",
" term.setTextColor(colors.orange)",
" write(string.char(fType))",
" end",
"",
" for fNr, fire in pairs(eShip.fire) do",
" if (tick == 0) then",
" fType = 171",
" if (fire.x % 2 ~= fire.y % 2) then",
" fType = 127",
" end",
" else",
" fType = 127",
" if (fire.x % 2 ~= fire.y % 2) then",
" fType = 171",
" end",
" end",
" term.setCursorPos(x2 + fire.x, y2 + fire.y)",
" term.setBackgroundColor(colors.red)",
" term.setTextColor(colors.orange)",
" write(string.char(fType))",
" end",
"",
" if (tick == 0) then",
" tick = 1",
" else",
" tick = 0",
" end",
"",
" sleep(0.1)",
" end",
"end",
"",
"function drawHullBarPlayer(x, y, value, max)",
" term.setTextColor(colors.gray)",
" for i = x, max do",
" term.setCursorPos(i, y)",
" if (value >= i) then",
" term.setBackgroundColor(colors.lime)",
" else",
" term.setBackgroundColor(colors.red)",
" end",
" write(\"L\")",
" end",
"end",
"",
"function drawHullBarEnemy(x, y, value, max)",
" term.setTextColor(colors.gray)",
" for i = 1, max do",
" term.setCursorPos(x - i + 1, y)",
" if (value >= i) then",
" term.setBackgroundColor(colors.lime)",
" else",
" term.setBackgroundColor(colors.red)",
" end",
" write(\"L\")",
" end",
"end",
"",
"function drawBattleScreen()",
" drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
" term.setTextColor(colors.gray)",
"",
" local shieldRoomNr = -1",
" for roomNr2, room2 in pairs(pShip.rooms) do",
" if (room2.rType == \"shields\") then",
" shieldRoomNr = roomNr2",
" end",
" end",
" if (shieldRoomNr > 0) then",
" for i = 1, pShip.rooms[shieldRoomNr].level do",
" term.setCursorPos((i - 1) * 4 + 1, 2)",
" if (pShip.rooms[shieldRoomNr].level - pShip.rooms[shieldRoomNr].damage >= i) then",
" term.setBackgroundColor(colors.lightBlue)",
" else",
" term.setBackgroundColor(colors.blue)",
" end",
" write(\"___|\")",
" end",
" paintutils.drawLine(16, 4, 16, 9, colors.lightBlue)",
" else",
" paintutils.drawLine(16, 4, 16, 9, colors.black)",
" end",
"",
" drawHullBarEnemy(screenWidth, 1, eShip.hull, eShip.maxHull)",
" term.setTextColor(colors.gray)",
"",
" local shieldRoomNr = -1",
" for roomNr2, room2 in pairs(eShip.rooms) do",
" if (room2.rType == \"shields\") then",
" shieldRoomNr = roomNr2",
" end",
" end",
" if (shieldRoomNr > 0) then",
" for i = 1, eShip.rooms[shieldRoomNr].level do",
" term.setCursorPos(screenWidth - i * 4 + 1, 2)",
" if (eShip.rooms[shieldRoomNr].level - eShip.rooms[shieldRoomNr].damage >= i) then",
" term.setBackgroundColor(colors.lightBlue)",
" else",
" term.setBackgroundColor(colors.blue)",
" end",
" write(\"___|\")",
" end",
" end",
"",
" paintutils.drawImage(pShip.image, x1, y1)",
" for roomNr, room in pairs(pShip.rooms) do",
" local color = colors.white",
" if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
" color = colors.lightGray",
" end",
"",
" paintutils.drawFilledBox(x1 + room.x, y1 + room.y, x1 + room.x + 2, y1 + room.y + 1, color)",
" term.setCursorPos(x1 + room.x + 1, y1 + room.y)",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.white)",
"",
" local barY = 0",
"",
" if (room.rType == \"controll\") then",
" write(\"C\")",
" barY = screenHeight - 1",
" elseif (room.rType == \"weapons\") then",
" write(\"W\")",
" barY = screenHeight - 2",
" elseif (room.rType == \"shields\") then",
" write(\"S\")",
" barY = screenHeight - 3",
" else",
" write(\"?\")",
" end",
"",
" term.setTextColor(colors.gray)",
" for i = 1, room.level do",
" if (i <= room.level - room.damage) then",
" term.setBackgroundColor(colors.lime)",
" else",
" term.setBackgroundColor(colors.red)",
" end",
" term.setCursorPos(1 + i, barY - 1)",
" write(\"L\")",
" end",
" end",
"",
" paintutils.drawImage(eShip.image, x2, y2)",
" for roomNr, room in pairs(eShip.rooms) do",
" local color = colors.white",
" if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
" color = colors.lightGray",
" end",
" paintutils.drawFilledBox(x2 + room.x, y2 + room.y, x2 + room.x + 2, y2 + room.y + 1, color)",
" ",
" if (target == roomNr) then",
" term.setCursorPos(x2 + room.x + 1, y2 + room.y + 1)",
" if (repeatShot == false) then",
" term.setTextColor(colors.red)",
" else",
" term.setTextColor(colors.orange)",
" end",
" write(string.char(174))",
" end",
"",
" term.setCursorPos(x2 + room.x + 1, y2 + room.y)",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.white)",
" ",
" if (room.rType == \"controll\") then",
" write(\"C\")",
" barY = screenHeight - 1",
" elseif (room.rType == \"weapons\") then",
" write(\"W\")",
" barY = screenHeight - 2",
" elseif (room.rType == \"shields\") then",
" write(\"S\")",
" barY = screenHeight - 3",
" else",
" write(\"?\")",
" end",
"",
" term.setTextColor(colors.gray)",
" for i = 1, room.level do",
" if (i <= room.level - room.damage) then",
" term.setBackgroundColor(colors.lime)",
" else",
" term.setBackgroundColor(colors.red)",
" end",
" term.setCursorPos(screenWidth - i, barY - 1)",
" write(\"L\")",
" end",
" end",
"",
" term.setBackgroundColor(colors.white)",
" term.setTextColor(colors.black)",
"",
" term.setCursorPos(1, screenHeight - 2)",
" write(\"C\")",
" term.setCursorPos(1, screenHeight - 3)",
" write(\"W\")",
" term.setCursorPos(1, screenHeight - 4)",
" write(\"S\")",
"",
" term.setCursorPos(screenWidth, screenHeight - 2)",
" write(\"C\")",
" term.setCursorPos(screenWidth, screenHeight - 3)",
" write(\"W\")",
" term.setCursorPos(screenWidth, screenHeight - 4)",
" write(\"S\")",
"end",
"",
"function playerShooting()",
" while true do",
" if (pShip.wCooldown >= 20) then",
" if (target ~= -1) then",
" local roomNr = target",
" local room = eShip.rooms[roomNr]",
"",
" local evasion = 0",
" for roomNr2, room2 in pairs(eShip.rooms) do",
" if (room2.rType == \"controll\") then",
" evasion = (room2.level - room2.damage) * 0.05",
" end",
" end",
"",
" local dDamage = 0",
" for roomNr2, room2 in pairs(pShip.rooms) do",
" if (room2.rType == \"weapons\") then",
" dDamage = math.ceil((room2.level - room2.damage) / 2)",
" end",
" end",
"",
" local shieldL = 0",
" local shieldRoomNr = -1",
" for roomNr2, room2 in pairs(eShip.rooms) do",
" if (room2.rType == \"shields\") then",
" shieldL = room2.level - room2.damage",
" shieldRoomNr = roomNr2",
" end",
" end",
"",
" if (math.random() > evasion) then",
" if (shieldL <= 0) then",
" eShip.hull = eShip.hull - dDamage",
" room.damage = room.damage + 1",
" else",
" if (dDamage >= 2) then",
" eShip.rooms[shieldRoomNr].damage = eShip.rooms[shieldRoomNr].damage + 1",
" end",
" end",
" else",
" miss = missTime",
" end",
" laserPhase = 2",
" pShip.wCooldown = 0",
"",
" if (repeatShot == false) then",
" target = -1",
" end",
" end",
" end",
" ",
" drawBattleScreen()",
"",
" sleep(0.2)",
" end",
"end",
"",
"function battlePlayer()",
" while true do",
" drawBattleScreen()",
"",
" local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
" ",
" local hit = false",
"",
" for roomNr, room in pairs(eShip.rooms) do",
" if (X >= x2 + room.x and X <= x2 + room.x + 2) then",
" if (Y == y2 + room.y or Y == y2 + room.y + 1) then",
" target = roomNr",
" if (button == 1) then",
" repeatShot = false",
" else",
" repeatShot = true",
" end",
" hit = true",
" end",
" end",
" end",
"",
" if (hit == false) then",
" target = -1",
" end",
" end",
"end",
"",
"function battleAI()",
" while true do",
" if (eShip.wCooldown >= 20) then",
" local room = pShip.rooms[math.ceil(math.random(table.getn(pShip.rooms)))]",
"",
" local evasion = 0",
" for roomNr2, room2 in pairs(pShip.rooms) do",
" if (room2.rType == \"controll\") then",
" evasion = (room2.level - room2.damage) * 0.05",
" end",
" end",
"",
" local dDamage = 0",
" for roomNr2, room2 in pairs(eShip.rooms) do",
" if (room2.rType == \"weapons\") then",
" dDamage = math.ceil((room2.level - room2.damage) / 2)",
" end",
" end",
"",
" local shieldL = 0",
" local shieldRoomNr = -1",
" for roomNr2, room2 in pairs(pShip.rooms) do",
" if (room2.rType == \"shields\") then",
" shieldL = room2.level - room2.damage",
" shieldRoomNr = roomNr2",
" end",
" end",
"",
" if (math.random() > evasion) then",
" if (shieldL <= 0) then",
" pShip.hull = pShip.hull - dDamage",
" room.damage = room.damage + 1",
" else",
" if (dDamage >= 2) then",
" pShip.rooms[shieldRoomNr].damage = pShip.rooms[shieldRoomNr].damage + 1",
" end",
" end",
" else",
" miss = missTime",
" end",
" laserPhase = 2",
" eShip.wCooldown = 0",
" end",
"",
" drawBattleScreen()",
"",
" if (eShip.hull <= 0) then",
" sleep(0.5)",
" paintutils.drawImage(eShip.image_broken, x2, y2 - 1)",
" break",
" end",
"",
" if (pShip.hull <= 0) then",
" break",
" end",
"",
" sleep(1)",
" end",
"end",
"",
"function repair()",
" while true do",
" for roomNr, room in pairs(pShip.rooms) do",
" if (room.damage > 0) then",
" room.repair = room.repair + 1",
" if (room.repair > 5 * 20) then",
" room.repair = 0",
" room.damage = room.damage - 1",
" end",
" end",
" end",
"",
" for roomNr, room in pairs(eShip.rooms) do",
" if (room.damage > 0) then",
" room.repair = room.repair + 1",
" if (room.repair > 5 * 20) then",
" room.repair = 0",
" room.damage = room.damage - 1",
" end",
" end",
" end",
"",
" sleep(0.2)",
" end",
"end",
"",
"function setShipPlayer(ship)",
" pShip = deepCopy(ship)",
" pShip.hull = pShip.maxHull",
"end",
"",
"function setShipAI(tier)",
" local eShipType = math.random(1, 5) + 5 * (tier - 1)",
" eShip = deepCopy(eShips[eShipType])",
" eShip.hull = eShip.maxHull",
"end",
"",
"function battle(tier)",
" setShipAI(tier)",
" for roomNr, room in pairs(pShip.rooms) do",
" room.damage = 0",
" end",
" target = -1",
"",
" drawSpaceBackground()",
" parallel.waitForAny(battlePlayer, battleAI, drawBattle, repair, playerShooting)",
"",
" if (eShip.hull <= 0) then",
" sleep(0.5)",
" paintutils.drawFilledBox(4, 3, screenWidth - 3, screenHeight - 2, colors.gray)",
" term.setTextColor(colors.lime)",
"",
" term.setCursorPos(5, 4)",
" write(\"The enemy has been defeated.\")",
"",
" term.setCursorPos(5, 5)",
" write(\"You try to find some scrap.\")",
"",
" term.setCursorPos(5, 7)",
" write(\"You found some scrap: \"..scrapSymbol..\" \"..math.ceil(eShip.maxHull * 1.3))",
"",
" if (getRoomLevel(\"controll\", \"player\") > 0 and math.random(1, 15) <= 1) then",
" term.setCursorPos(5, 9)",
" write(\"You found an upgrade for the Controll room.\")",
" upgrade(\"controll\")",
" elseif (getRoomLevel(\"weapons\", \"player\") > 0 and math.random(1, 14) <= 1) then",
" term.setCursorPos(5, 9)",
" write(\"You found an upgrade for the Weapons room.\")",
" upgrade(\"weapons\")",
" end",
"",
" scrap = scrap + math.ceil(eShip.maxHull * 1.3)",
" score = score + 5 * tier",
"",
" loadInfo()",
" killCount = killCount + 1",
" saveInfo()",
"",
" sleep(0.5)",
" os.pullEventRaw()",
" end",
"end",
"",
"function generateWorld()",
" world = {}",
" for x = -49, 51 do",
" local colomn = {}",
" for y = -49, 51 do",
" local random = math.random(0, 10)",
" local cInfo",
"",
" if (random == 10) then",
" local fuelForSale = 4 + math.random(1, 4)",
" cInfo = {3, {fuelForSale, math.random(-1, 2), math.random(-1, 2), math.random(-1, 2)}}",
" elseif (random >= 4) then",
" cInfo = 2",
" else",
" cInfo = 0",
" end",
"",
" colomn[y + 50] = cInfo",
" end",
" world[x + 50] = colomn",
" end",
"end",
"",
"function drawWorld()",
" drawSpaceBackground()",
" term.setTextColor(colors.black)",
"",
" for x = playerX - 4, playerX + 4 do",
" for y = playerY - 2, playerY + 2 do",
" local cInfo = world[x + 50][y + 50]",
"",
" local cType = 0",
" if (type(cInfo) == \"table\") then",
" cType = cInfo[1]",
" else",
" cType = cInfo",
" end",
"",
" if (x == playerX and y == playerY) then",
" term.setBackgroundColor(colors.white)",
" else",
" if (cType == 0) then",
" term.setBackgroundColor(colors.gray)",
" elseif (cType == 1) then",
" term.setBackgroundColor(colors.lime)",
" elseif (cType == 2) then",
" term.setBackgroundColor(colors.red)",
" elseif (cType == 3) then",
" term.setBackgroundColor(colors.blue)",
" end",
" end",
"",
" term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1, math.ceil(screenHeight / 2) + (y - playerY) * 4 - 1)",
" write(\" \")",
" term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1, math.ceil(screenHeight / 2) + (y - playerY) * 4)",
" write(\" \")",
" term.setCursorPos(math.ceil(screenWidth / 2) + (x - playerX) * 6 - 1 , math.ceil(screenHeight / 2) + (y - playerY) * 4 + 1)",
" write(\" \")",
" end",
" end",
"",
" drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
"",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
"",
" term.setCursorPos(screenWidth - string.len(\"Scrap: \"..scrapSymbol..\" \"..scrap) + 1, 1)",
" write(\"Scrap: \"..scrapSymbol..\" \"..scrap)",
"",
" term.setCursorPos(screenWidth - string.len(\"Fuel: \"..fuel) + 1, 2)",
" write(\"Fuel: \"..fuel)",
"",
" term.setCursorPos(1, screenHeight)",
" write(\"Save and exit\")",
"end",
"",
"function move()",
" drawWorld()",
" while true do",
" local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
"",
" if (button == 1) then",
" if (X >= math.ceil(screenWidth / 2) - 6 - 1 and X < math.ceil(screenWidth / 2) - 6 - 1 + 3) then",
" if (Y >= math.ceil(screenHeight / 2) - 1 and Y <= math.ceil(screenHeight / 2) - 1 + 3) then",
" local cInfo = world[playerX + 50][playerY + 50]",
"",
" if (type(cInfo) ~= \"table\") then",
" if (cInfo ~= 3) then",
" world[playerX + 50][playerY + 50] = 1",
" end",
" end",
"",
" playerX = playerX - 1",
" break",
" end",
" elseif (X >= math.ceil(screenWidth / 2) - 1 and X < math.ceil(screenWidth / 2) - 1 + 3) then",
" if (Y >= math.ceil(screenHeight / 2) - 4 - 1 and Y <= math.ceil(screenHeight / 2) - 4 - 1 + 3) then",
" local cInfo = world[playerX + 50][playerY + 50]",
"",
" if (type(cInfo) ~= \"table\") then",
" if (cInfo ~= 3) then",
" world[playerX + 50][playerY + 50] = 1",
" end",
" end",
"",
" playerY = playerY - 1",
" break",
" elseif (Y >= math.ceil(screenHeight / 2) + 4 - 1 and Y <= math.ceil(screenHeight / 2) + 4 - 1 + 3) then",
" local cInfo = world[playerX + 50][playerY + 50]",
"",
" if (type(cInfo) ~= \"table\") then",
" if (cInfo ~= 3) then",
" world[playerX + 50][playerY + 50] = 1",
" end",
" end",
"",
" playerY = playerY + 1",
" break",
" end",
" elseif (X >= math.ceil(screenWidth / 2) + 6 - 1 and X < math.ceil(screenWidth / 2) + 6 - 1 + 3) then",
" if (Y >= math.ceil(screenHeight / 2) - 1 and Y <= math.ceil(screenHeight / 2) - 1 + 3) then",
" local cInfo = world[playerX + 50][playerY + 50]",
"",
" if (type(cInfo) ~= \"table\") then",
" if (cInfo ~= 3) then",
" world[playerX + 50][playerY + 50] = 1",
" end",
" end",
"",
" playerX = playerX + 1",
" break",
" end",
" elseif (Y == screenHeight and X <= string.len(\"Save and exit\")) then",
" saveGame()",
" stop = true",
" break",
" end",
" end",
" end",
" fuel = fuel - 1",
"end",
"",
"function upgradePrice(room)",
" local level = getRoomLevel(room, \"player\")",
" if (room == \"shields\") then",
" level = level * 5",
" end",
" local price = math.floor(5 + 0.7 * level ^ 2)",
" return price",
"end",
"",
"function upgrade(roomT)",
" for roomNr, room in pairs(pShip.rooms) do",
" if (room.rType == roomT) then",
" room.level = room.level + 1",
" break",
" end",
" end",
"end",
"",
"function getRoomLevel(roomT, ship)",
" local level = 0",
"",
" if (ship == \"player\") then",
" for roomNr, room in pairs(pShip.rooms) do",
" if (room.rType == roomT) then",
" level = room.level - room.damage",
" break",
" end",
" end",
" elseif (ship == \"enemy\") then",
" for roomNr, room in pairs(eShip.rooms) do",
" if (room.rType == roomT) then",
" level = room.level - room.damage",
" break",
" end",
" end",
" end",
"",
" return level",
"end",
"",
"function drawNiceBorder(x1, y1, x2, y2, bg, fg)",
" paintutils.drawFilledBox(x1 + 1, y1 + 1, x2 - 1, y2 - 1, colors.gray)",
"",
" for i = x1 + 1, x2 - 1 do",
" term.setBackgroundColor(bg)",
" term.setTextColor(fg)",
" term.setCursorPos(i, y1)",
" write(string.char(131))",
" end",
" for i = x1 + 1, x2 - 1 do",
" term.setBackgroundColor(fg)",
" term.setTextColor(bg)",
" term.setCursorPos(i, y2)",
" write(string.char(143))",
" end",
" for i = y1 + 1, y2 - 1 do",
" term.setBackgroundColor(bg)",
" term.setTextColor(fg)",
" term.setCursorPos(x1, i)",
" write(string.char(149))",
" end",
" for i = y1 + 1, y2 - 1 do",
" term.setBackgroundColor(fg)",
" term.setTextColor(bg)",
" term.setCursorPos(x2, i)",
" write(string.char(149))",
" end",
"",
" term.setCursorPos(x1, y1)",
" term.setBackgroundColor(bg)",
" term.setTextColor(fg)",
" write(string.char(151))",
"",
" term.setCursorPos(x1, y2)",
" term.setBackgroundColor(fg)",
" term.setTextColor(bg)",
" write(string.char(138))",
"",
" term.setCursorPos(x2, y1)",
" term.setBackgroundColor(fg)",
" term.setTextColor(bg)",
" write(string.char(148))",
"",
" term.setCursorPos(x2, y2)",
" term.setBackgroundColor(fg)",
" term.setTextColor(bg)",
" write(string.char(133))",
"end",
"",
"function drawBorder(close)",
" drawNiceBorder(4, 3, screenWidth - 3, screenHeight - 2, colors.gray, colors.lime)",
"",
" if (close) then",
" term.setBackgroundColor(colors.red)",
" term.setTextColor(colors.white)",
" term.setCursorPos(screenWidth - 3, 3)",
" write(\"X\")",
" end",
"end",
"",
"function drawShop(fuelForSale, c, w, s)",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" ",
" term.setCursorPos(5, 4)",
" write(\"Shop:\")",
"",
" term.setCursorPos(5, 6)",
" write(\"Fuel: \"..fuelForSale..\" (\"..scrapSymbol..\" 2)\")",
"",
" term.setCursorPos(5, 8)",
" write(\"Repair: 1 (\"..scrapSymbol..\" 1)\")",
"",
" local x = 5",
"",
" if (c <= 0 and getRoomLevel(\"controll\", \"player\") > 0) then",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" term.setCursorPos(x, 11)",
" write(\"Controll\")",
" term.setCursorPos(x, 13)",
" write(scrapSymbol..\" \"..upgradePrice(\"controll\"))",
" term.setCursorPos(x, 14)",
" write(\"Current:\"..getRoomLevel(\"controll\", \"player\"))",
"",
" term.setBackgroundColor(colors.lime)",
" term.setTextColor(colors.black)",
" term.setCursorPos(x, 12)",
" write(\"[Upgrade]\")",
" x = x + 10",
" end",
"",
" if (w <= 0 and getRoomLevel(\"weapons\", \"player\") > 0) then",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" term.setCursorPos(x, 11)",
" write(\"Weapons\")",
" term.setCursorPos(x, 13)",
" write(scrapSymbol..\" \"..upgradePrice(\"weapons\"))",
" term.setCursorPos(x, 14)",
" write(\"Current:\"..getRoomLevel(\"weapons\", \"player\"))",
"",
" term.setBackgroundColor(colors.lime)",
" term.setTextColor(colors.black)",
" term.setCursorPos(x, 12)",
" write(\"[Upgrade]\")",
" x = x + 10",
" end",
"",
" if (s <= 0 and getRoomLevel(\"shields\", \"player\") > 0) then",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" term.setCursorPos(x, 11)",
" write(\"Shields\")",
" term.setCursorPos(x, 13)",
" write(scrapSymbol..\" \"..upgradePrice(\"shields\"))",
" term.setCursorPos(x, 14)",
" write(\"Current:\"..getRoomLevel(\"shields\", \"player\"))",
"",
" term.setBackgroundColor(colors.lime)",
" term.setTextColor(colors.black)",
" term.setCursorPos(x, 12)",
" write(\"[Upgrade]\")",
" x = x + 10",
" end",
"",
" term.setBackgroundColor(colors.lime)",
" term.setTextColor(colors.black)",
"",
" term.setCursorPos(5, 7)",
" write(\"[ BUY ]\")",
"",
" term.setCursorPos(5, 9)",
" write(\"[ BUY ]\")",
"",
" drawHullBarPlayer(1, 1, pShip.hull, pShip.maxHull)",
"",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
"",
" term.setCursorPos(screenWidth - string.len(\"Fuel: \"..fuel), 2)",
" write(\" Fuel: \"..fuel)",
"",
" term.setCursorPos(screenWidth - string.len(\"Scrap: \"..scrapSymbol..\" \"..scrap), 1)",
" write(\" Scrap: \"..scrapSymbol..\" \"..scrap)",
"end",
"",
"function shop(shopInfo)",
" drawBorder(true)",
"",
" while true do",
" drawShop(shopInfo[1], shopInfo[2], shopInfo[3], shopInfo[4])",
"",
" local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
"",
" if (button == 1) then",
" if (X >= 5 and X <= 11 and Y == 7) then",
" if (scrap >= 2 and shopInfo[1] >= 1) then",
" scrap = scrap - 2",
" fuel = fuel + 1",
" shopInfo[1] = shopInfo[1] - 1",
" end",
" elseif (X >= 5 and X <= 11 and Y == 9) then",
" if (scrap >= 1) then",
" if (pShip.hull < pShip.maxHull) then",
" scrap = scrap - 1",
" pShip.hull = pShip.hull + 1",
" end",
" end",
" elseif (Y == 12) then",
" local spaces = {}",
"",
" if (shopInfo[2] <= 0 and getRoomLevel(\"controll\", \"player\") > 0) then",
" table.insert(spaces, \"controll\")",
" end",
" if (shopInfo[3] <= 0 and getRoomLevel(\"weapons\", \"player\") > 0) then",
" table.insert(spaces, \"weapons\")",
" end",
" if (shopInfo[4] <= 0 and getRoomLevel(\"shields\", \"player\") > 0) then",
" table.insert(spaces, \"shields\")",
" end",
"",
" if (X >= 5 and X < 5 + 9) then",
" if (table.getn(spaces) >= 1) then",
" if (spaces[1] == \"controll\") then",
" if (scrap >= upgradePrice(spaces[1])) then",
" scrap = scrap - upgradePrice(spaces[1])",
" upgrade(spaces[1])",
" end",
" elseif (spaces[1] == \"weapons\") then",
" if (scrap >= upgradePrice(spaces[1])) then",
" scrap = scrap - upgradePrice(spaces[1])",
" upgrade(spaces[1])",
" end",
" elseif (spaces[1] == \"shields\") then",
" if (scrap >= upgradePrice(spaces[1])) then",
" scrap = scrap - upgradePrice(spaces[1])",
" upgrade(spaces[1])",
" end",
" end",
" end",
" elseif (X >= 5 + 10 and X < 5 + 9 + 10) then",
" if (table.getn(spaces) >= 2) then",
" if (spaces[2] == \"controll\") then",
" if (scrap >= upgradePrice(spaces[2])) then",
" scrap = scrap - upgradePrice(spaces[2])",
" upgrade(spaces[2])",
" end",
" elseif (spaces[2] == \"weapons\") then",
" if (scrap >= upgradePrice(spaces[2])) then",
" scrap = scrap - upgradePrice(spaces[2])",
" upgrade(spaces[2])",
" end",
" elseif (spaces[2] == \"shields\") then",
" if (scrap >= upgradePrice(spaces[2])) then",
" scrap = scrap - upgradePrice(spaces[2])",
" upgrade(spaces[2])",
" end",
" end",
" end",
" elseif (X >= 5 + 10 and X < 5 + 9 + 20) then",
" if (table.getn(spaces) >= 3) then",
" if (spaces[3] == \"controll\") then",
" if (scrap >= upgradePrice(spaces[3])) then",
" scrap = scrap - upgradePrice(spaces[3])",
" upgrade(spaces[3])",
" end",
" elseif (spaces[3] == \"weapons\") then",
" if (scrap >= upgradePrice(spaces[3])) then",
" scrap = scrap - upgradePrice(spaces[3])",
" upgrade(spaces[3])",
" end",
" elseif (spaces[3] == \"shields\") then",
" if (scrap >= upgradePrice(spaces[3])) then",
" scrap = scrap - upgradePrice(spaces[3])",
" upgrade(spaces[3])",
" end",
" end",
" end",
" end",
" elseif (X == screenWidth - 3) then",
" if (Y == 3) then",
" break",
" end",
" end",
" end",
" end",
"end",
"",
"function gameLost()",
" fs.delete(\"saveFile.sav\")",
"",
" drawBorder(false)",
"",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" ",
" term.setCursorPos(5, 4)",
" textutils.slowWrite(\"You have failed in your mission to save the\")",
" term.setCursorPos(5, 5)",
" textutils.slowWrite(\"universe...\")",
"",
" term.setCursorPos(5, 7)",
" textutils.slowWrite(\"Your score is: \"..score)",
" sleep(0.5)",
" os.pullEventRaw()",
"end",
"",
"function newGame(ship)",
" scrap = 0",
" fuel = 15",
" score = 0",
"",
" generateWorld()",
" setShipPlayer(ship)",
"end",
"",
"function saveGame()",
" local info = {scrap = scrap, fuel = fuel, score = score, playerX = playerX, playerY = playerY, world = world, pShip = pShip}",
"",
" local file = fs.open(\"saveFile.sav\", \"w\")",
" file.write(textutils.serialize(info))",
" file.close()",
"end",
"",
"function loadGame()",
" local file = fs.open(\"saveFile.sav\", \"r\")",
" local data = file.readAll()",
" file.close()",
" local info = textutils.unserialize(data)",
"",
" scrap = info.scrap",
" fuel = info.fuel",
" score = info.score",
" playerX = info.playerX",
" playerY = info.playerY",
" world = info.world",
" pShip = info.pShip",
"end",
"",
"function saveInfo()",
" local info = {unlockedShips = unlockedShips, killCount = killCount}",
"",
" local file = fs.open(\"info.sav\", \"w\")",
" file.write(textutils.serialize(info))",
" file.close()",
"end",
"",
"function loadInfo()",
" if (fs.exists(\"info.sav\")) then",
" local file = fs.open(\"info.sav\", \"r\")",
" local data = file.readAll()",
" file.close()",
" local info = textutils.unserialize(data)",
"",
" unlockedShips = info.unlockedShips",
" killCount = info.killCount",
" else",
" unlockedShips = {}",
" for shipNr, ship in pairs(pShips) do",
" if (shipNr == 1) then",
" unlockedShips[shipNr] = true",
" else",
" unlockedShips[shipNr] = false",
" end",
" end",
" killCount = 0",
" end",
"end",
"",
"function unlock(shipNr)",
" loadInfo()",
" ",
" if (unlockedShips[shipNr] == false) then",
" local width = 25",
" local height = 3",
" drawNiceBorder(screenWidth - width, 2, screenWidth - 1, height + 1, colors.gray, colors.lime)",
" ",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.red)",
" term.setCursorPos(screenWidth - width + 1, 3)",
" write(string.char(187))",
"",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
" term.setCursorPos(screenWidth - width + 1 + 2, 3)",
" write(\"New ship unlocked!\")",
"",
" unlockedShips[shipNr] = true",
" saveInfo()",
"",
" sleep(0.5)",
" os.pullEventRaw()",
" end",
"end",
"",
"function play()",
" while true do",
" if (fuel >= 0 and pShip.hull > 0) then",
" move()",
" saveGame()",
"",
" if (stop == true) then",
" stop = false",
" break",
" end",
"",
" local cInfo = world[playerX + 50][playerY + 50]",
"",
" local cType = 0",
" if (type(cInfo) == \"table\") then",
" cType = cInfo[1]",
" else",
" cType = cInfo",
" end",
"",
" if (cType == 2) then",
" battle(math.floor(math.sqrt(math.abs(playerX) ^ 2 + math.abs(playerY) ^ 2) / 10) + 1)",
"",
" loadInfo()",
" if (killCount >= 2) then",
" unlock(2)",
" end",
" elseif (cType == 3) then",
" shop(cInfo[2])",
" end",
" else",
" gameLost()",
" break",
" end",
" end",
"end",
"",
"function startScene()",
" term.setBackgroundColor(colors.white)",
" term.clear()",
" sleep(0.5)",
" term.setBackgroundColor(colors.lightGray)",
" term.clear()",
" sleep(0.2)",
" term.setBackgroundColor(colors.gray)",
" term.clear()",
" sleep(0)",
" term.setBackgroundColor(colors.black)",
" term.clear()",
" sleep(1)",
"",
" term.setTextColor(colors.lime)",
" local speed = 15",
"",
" term.setCursorPos(2, 2)",
" textutils.slowWrite(\"An evil lord has taken over the universe...\", speed)",
" sleep(0.7)",
" term.setCursorPos(2, 3)",
" textutils.slowWrite(\"It's your duty to slay his troops and free the\", speed)",
" term.setCursorPos(2, 4)",
" textutils.slowWrite(\"citizens!\", speed)",
" sleep(0.5)",
" term.setCursorPos(2, 5)",
" textutils.slowWrite(\"We have prepared a spaceship for you.\", speed)",
" sleep(0.5)",
" term.setCursorPos(2, 7)",
" textutils.slowWrite(\"Good luck!\", speed)",
"",
" os.pullEventRaw()",
"end",
"",
"function drawHangar(ship)",
" drawSpaceBackground()",
"",
" term.setBackgroundColor(colors.gray)",
" term.setTextColor(colors.lime)",
"",
" term.setCursorPos(1, 1)",
" write(\"< Back\")",
"",
" term.setCursorPos(8, 1)",
" write(ship.name)",
"",
" term.setCursorPos(screenWidth - string.len(\"Start Game >\") + 1, 1)",
" write(\"Start Game >\")",
"",
" term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\" < \") / 2) + 1 - 3, screenHeight)",
" write(\" < \")",
"",
" term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\" > \") / 2) + 1 + 3, screenHeight)",
" write(\" > \")",
"",
" drawHullBarPlayer(1, 3, ship.maxHull, ship.maxHull)",
"",
" term.setBackgroundColor(colors.white)",
" term.setTextColor(colors.black)",
"",
" term.setCursorPos(1, 5)",
" write(\"C\")",
" term.setCursorPos(1, 6)",
" write(\"W\")",
" term.setCursorPos(1, 7)",
" write(\"S\")",
"",
" local newX = 18",
" local newY = 7",
" paintutils.drawImage(ship.image, newX, newY)",
" for roomNr, room in pairs(ship.rooms) do",
" local color = colors.white",
" if (math.floor(room.x % 6 / 3) ~= math.floor(room.y % 4 / 2)) then",
" color = colors.lightGray",
" end",
"",
" paintutils.drawFilledBox(newX + room.x, newY + room.y, newX + room.x + 2, newY + room.y + 1, color)",
" term.setCursorPos(newX + room.x + 1, newY + room.y)",
" term.setBackgroundColor(colors.black)",
" term.setTextColor(colors.white)",
"",
" local barY = 0",
"",
" if (room.rType == \"controll\") then",
" write(\"C\")",
" barY = 5",
" elseif (room.rType == \"weapons\") then",
" write(\"W\")",
" barY = 6",
" elseif (room.rType == \"shields\") then",
" write(\"S\")",
" barY = 7",
" else",
" write(\"?\")",
" end",
"",
" term.setTextColor(colors.gray)",
" for i = 1, room.level do",
" if (i <= room.level - room.damage) then",
" term.setBackgroundColor(colors.lime)",
" else",
" term.setBackgroundColor(colors.red)",
" end",
" term.setCursorPos(1 + i, barY)",
" write(\"L\")",
" end",
" end",
"end",
"",
"function hangar()",
" loadInfo()",
" local shipNr = 1",
"",
" while true do",
" local ship = pShips[shipNr]",
" drawHangar(ship)",
"",
" local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
"",
" if (button == 1) then",
" if (Y == 1) then",
" if (X <= 6) then",
" break",
" elseif (X >= screenWidth - 11) then",
" newGame(ship)",
" startScene()",
" play()",
" break",
" end",
" elseif (Y == screenHeight) then",
" if (X >= math.floor(screenWidth / 2) - 5 + 1 and X < math.floor(screenWidth / 2) + 1) then",
" while true do",
" shipNr = shipNr - 1",
" if (shipNr < 1) then",
" shipNr = table.getn(pShips)",
" end",
"",
" if (unlockedShips[shipNr]) then",
" break",
" end",
" end",
" elseif (X > math.floor(screenWidth / 2) + 1 and X <= math.floor(screenWidth / 2) + 5 + 1) then",
" while true do",
" shipNr = shipNr + 1",
" if (shipNr > table.getn(pShips)) then",
" shipNr = 1",
" end",
"",
" if (unlockedShips[shipNr]) then",
" break",
" end",
" end",
" end",
" end",
" end",
" end",
"end",
"",
"function mainMenu()",
" while true do",
" drawSpaceBackground()",
" term.setBackgroundColor(colors.gray)",
" ",
" if (fs.exists(\"saveFile.sav\")) then",
" term.setTextColor(colors.lime)",
" else",
" term.setTextColor(colors.lightGray)",
" end",
"",
" term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1, 5)",
" write(\"Continue\")",
"",
" term.setTextColor(colors.lime)",
"",
" term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1, 7)",
" write(\"New Game\")",
"",
" term.setCursorPos(math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1, 9)",
" write(\"Exit\")",
"",
" local event, button, X, Y = os.pullEventRaw(\"mouse_click\")",
"",
" if (button == 1) then",
" if (Y == 5) then",
" if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"Continue\") / 2) + 1 + string.len(\"Continue\")) then",
" if (fs.exists(\"saveFile.sav\")) then",
" loadGame()",
" play()",
" end",
" end",
" elseif (Y == 7) then",
" if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"New Game\") / 2) + 1 + string.len(\"New Game\")) then",
" hangar()",
" end",
" elseif (Y == 9) then",
" if (X >= math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1 and X < math.floor(screenWidth / 2) - math.floor(string.len(\"Exit\") / 2) + 1 + string.len(\"Exit\")) then",
" term.clear()",
" break",
" end",
" end",
" end",
" end",
"end",
"",
"mainMenu()",
},
[ "/eShip6.img" ] = {
" 777b77",
" bbb 7",
" 777b 7",
" 7 bbbbbb",
" 7 b77777",
" bbbb 7",
" 777 7",
" 777b77",
},
[ "/eShip8.img" ] = {
"",
" 7b",
" 7777bbbb",
" 77 7",
" bb 7",
" bbbbbbbb",
" 7b",
},
[ "/eShip13.img" ] = {
"",
" 977779",
" 9999 99",
" 7 9 9",
" 7 9 9",
" 9999 99",
" 977779",
},
[ "/eShip12.img" ] = {
"",
" 9999977",
" 99 777",
" 77 77",
" 77 7",
" 99 9",
" 77 77",
" 99 777",
" 9999977",
},
[ "/pShip2.img" ] = {
"555ddd55",
"d55 d555",
" d5 5 5",
" 55 5 d",
"555 55dd",
"dddddddd",
},
[ "/eShip14.img" ] = {
"",
" 999999999",
" 999 7777",
" 9977 77999",
" 7777 77",
" ",
" ",
" 7777 77",
" 9977 77999",
" 999 7777",
" 999999999",
},
[ "/eShip2_broken.img" ] = {
" eeeeeeee",
" e1111e111f",
" ff1f111fff",
" ffff1",
" fefff",
" ff11e1ffff",
" ee11ee1eef",
" 11111111",
},
[ "/eShip13_broken.img" ] = {
"",
" 977779",
" 999977799f",
" 777797f79ff",
" ff7fffff9",
" ffffff7ff",
" 77f797779ff",
" 999977799f",
" 977779",
},
[ "/pShip1.img" ] = {
"555555 55",
"dddd555555d",
" d 5",
" 5 d",
"55555ddddd5",
"ddddd dd",
},
[ "/eShip12_broken.img" ] = {
"",
" 9999977",
" 99777777f",
" 7777777ff",
" f777777",
" 7ff7ff",
" ffffff",
" f9ffff9",
" 7777777ff",
" 99777777f",
" 9999977",
},
[ "/eShip1.img" ] = {
" eeeeeeee",
" e1 111",
" e11 e",
" 11e e",
" 1e 1ee",
" 11111111",
},
[ "/eShip1_broken.img" ] = {
" eeeeeeee",
" e11e1111ff",
" e11ef1eff",
" feffffff",
" fffff1ff",
" 11ef11eff",
" 1ee111eeff",
" 11111111",
},
[ "/eShip2.img" ] = {
" eeeeeeee",
" e11 111",
" 1 1",
" 1 1",
" ee1 1ee",
" 11111111",
},
[ "/eShip10_broken.img" ] = {
" 777b77",
" 77bbb7f77ff",
" 77777bff77",
" fffffbfffbb",
" fffff7f",
" ffff7ff",
" fffffbfff77",
" 77bbbbf7f7",
" 7777777f7ff",
" 777b77",
},
[ "/eShip10.img" ] = {
" 777b77",
" 77bbb 7",
" 77777b 7",
" b bb",
" b 77",
" 77bbbb 7",
" 77777 7",
" 777b77",
},
[ "/eShip7.img" ] = {
"",
" 777b777",
" 7 bbbb",
" 77 b77",
" bb b77",
" b b777",
" bbbbbbb",
},
[ "/eShip14_broken.img" ] = {
"",
" 999999999",
" 9997777777f",
" 997777777999",
" fff7777ff777",
" f7fffff7ff",
" ffff77ffff",
" fff7f77777f7",
" 997777777999",
" 9997777777f",
" 999999999",
},
[ "/eShip7_broken.img" ] = {
"",
" 777b777",
" 77ffbbbbf",
" 7ffffbf7ff",
" ffffffff",
" f7ffff7f",
" bbfffb77ff",
" bff7b777f",
" bbbbbbb",
},
[ "/info.sav" ] = {
"{",
" killCount = 90,",
" unlockedShips = {",
" true,",
" true,",
" },",
"}",
},
[ "/eShip3.img" ] = {
" eeeeeee",
" e1111111",
" ee 1",
" e1 1",
" 1eeeee1e",
" 1111111",
},
[ "/eShip9.img" ] = {
"",
" 77777b",
" 777bbbbb",
" 7 77",
" b 77",
" bbbbbbbb",
" 77777b",
},
[ "/eShip9_broken.img" ] = {
"",
" 77777b",
" 777bbbbbf",
" 77ffbf777f",
" ffffff7fff",
" fff7f7ffff",
" bf7777f77f",
" bbbbbbbbf",
" 77777b",
},
[ "/eShip4_broken.img" ] = {
" eee",
" eeeeee111f",
" e1111f1efff",
" ff1effff",
" fffff1ff",
" 1effe111fff",
" 111eee1eef",
" 111",
},
[ "/eShip11.img" ] = {
"",
" 777779",
" 777 79",
" 7999 99",
" 9 9997",
" 7 7777",
" 7777 79",
" 797 79",
" 999999",
},
[ "/eShip5_broken.img" ] = {
" eeeeeeeee",
" e1fff11111f",
" effff11efff",
" ffffff1f",
" f1ffffff",
" e1fffefefff",
" e1fffe11eef",
" 11ee11111",
},
[ "/eShip5.img" ] = {
" eeeeeeeee",
" e1 11111",
" e1 11e",
" e1 e1e",
" e1 e11ee",
" 11ee11111",
},
}
local tArg = {...}
local outpath = ((tArg[1] ~= "") and tArg[1]) or (shell and shell.getRunningProgram() or "lightspeed")
if fs.combine("",outpath) == "rom/programs/http/pastebin" then outpath = (shell and shell.dir() or "") end
local progdor = fs.getName(shell.getRunningProgram())
local dir = shell.dir()
local yield = function()
os.queueEvent("yield")
os.pullEvent("yield")
end
-- CCA API START --
local bit = bit32
--[[
local function pack(bn1, bn2)
bytes = {}
bytes[1] = bit.band(bn1, 0xFF)
bytes[2] = bit.rshift(bn1, 8) + bit.lshift(bit.band(bn2, 0xF), 4)
bytes[3] = bit.rshift(bn2, 4)
return bytes[1], bytes[2], bytes[3]
end
local function upack(b1, b2, b3)
bn1 = b1 + bit.lshift(bit.band(b2, 0xF), 8)
bn2 = bit.lshift(b3,4) + bit.band(bit.rshift(b2, 4), 0xF)
return bn1, bn2
end
--]]
local function pack(bn1, bn2)
return bit.band(bn1, 0xFF), bit.rshift(bn1, 8) + bit.lshift(bit.band(bn2, 0xF), 4), bit.rshift(bn2, 4)
end
local function upack(b1, b2, b3)
return (b1 + bit.lshift(bit.band(b2, 0xF), 8)), (bit.lshift(b3,4) + bit.band(bit.rshift(b2, 4), 0xF))
end
local function createDict(bool)
local ret = {}
for i = 1, 255 do
if bool then
ret[string.char(i)] = i
else
ret[i] = string.char(i)
end
end
if not bool then ret[256] = 256 end
return ret
end
local function cp(sInput)
local dic = createDict(true)
local s = ""
local ch
local dlen = 256
local result = {}
local temp
for i = 1, #sInput do
if dlen == 4095 then
result[#result + 1] = dic[s]
result[#result + 1] = 256
dic = createDict(true)
dlen = 256
s = ""
end
ch = sInput:sub(i, i)
temp = s..ch
if dic[temp] then
s = temp
else
result[#result + 1] = dic[s]
dlen = dlen +1
dic[temp] = dlen
s = ch
end
end
result[#result + 1] = dic[s]
return result
end
local function dc(data)
local dic = createDict(false)
local entry
local ch
local currCode
local result = {}
result[#result + 1] = dic[data[1]]
prefix = dic[data[1]]
for i = 2, #data do
currCode = data[i]
if currCode == 256 then
dic = createDict(false)
prefix = ""
else
entry = dic[currCode]
if entry then--exists in dictionary
ch = entry:sub(1, 1)
result[#result + 1] = entry
if prefix ~= "" then
dic[#dic+1] = prefix .. ch
end
else
ch = prefix:sub(1, 1)
result[#result + 1] = prefix..ch
dic[#dic + 1] = prefix..ch
end
prefix = dic[currCode]
end
end
return table.concat(result)
end
local function trim(inp)
for i = 0,2 do
if inp[#inp] == 0 then
inp[#inp] = nil
end
end
end
local function decompress(input)
local rec = {}
for i = 1, #input, 3 do
if i % 66 == 0 then
yield()
end
rec[#rec+1], rec[#rec+2] = upack(input[i], input[i+1] or 0, input[i+2] or 0)
end
trim(rec)
return dc(rec)
end
local function compress(input)
local rec = {}
local data = cp(input)
for i=1, #data, 2 do
yield()
rec[#rec+1], rec[#rec+2], rec[#rec+3] = pack(data[i], data[i+1] or 0)
end
trim(rec)
return rec
end
-- CCA API END --
local explode = function(div,str)
if (div=='') then return false end
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,str:sub(pos,st-1))
pos = sp + 1
end
table.insert(arr,str:sub(pos))
return arr
end
local sanitize = function(sani,tize)
local _,x = string.find(sani,tize)
if x then
return sani:sub(x+1)
else
return sani
end
end
local tablize = function(input)
if type(input) == "string" then
return explode("\n",input)
elseif type(input) == "table" then
return table.concat(input,"\n")
end
end
local compyress = function(input)
return string.char(unpack(compress(input)))
end
local decompyress = function(input)
local out = {}
for a = 1, #input do
table.insert(out,string.byte(input:sub(a,a)))
end
return decompress(out)
end
if not outpath then
outpath = input
end
local choice = function(input,verbose)
if not input then
input = "yn"
end
if verbose then
write("[")
for a = 1, #input do
write(input:sub(a,a):upper())
if a < #input then
write(",")
end
end
write("]?")
end
local evt,char
repeat
evt,char = os.pullEvent("char")
until string.find(input:lower(),char:lower())
if verbose then
print(char:upper())
end
local pos = string.find(input:lower(),char:lower())
return pos, char:lower()
end
local doPack = function(list,output,doCompress,verbose)
local tx = term.getTextColor()
if fs.isReadOnly(output) and (fs.combine("",output) ~= "") then return 5 end
local packageSelf = true
local packageReadOnly = true
local ro_asked = false
local ps_asked = false
if fs.exists(output) and (not fs.isDir(output)) then
fs.delete(output)
end
local amnt = 0
for k,v in pairs(list) do
amnt = amnt + 1
end
local num = 0
for k,v in pairs(list) do
num = num + 1
if v == true then
fs.makeDir(fs.combine(output,k))
else
local file = fs.open(fs.combine(output,k),"w")
if verbose then
write("[")
if term.isColor() then term.setTextColor(colors.lightGray) end
write(k)
term.setTextColor(tx)
write("]")
end
if doCompress then
file.write(decompyress(tablize(v)))
else
file.write(tablize(v))
end
file.close()
local tx = term.getTextColor()
if fs.getName(k):lower() == "peasant" then
if term.isColor() then
term.setTextColor(colors.orange)
end
print(" UNBURNINATED")
else
if term.isColor() then
term.setTextColor(colors.green)
end
print(" GOOD")
end
term.setTextColor(tx)
end
end
return 2
end
if not fs.isDir(outpath) then
fs.delete(outpath)
end
local success, res = pcall( function() return doPack(data,outpath,doCompress,true) end ) --functionized it!
if not success then
term.setTextColor(colors.white)
print("\n***Something went wrong!***")
return printError(res)
end
if res then
local msgs = {
[2] = "Successfully unpacked '"..fullname.."' to '"..outpath.."/'",
[5] = "You don't have permission.",
}
print(msgs[res])
end