SHOW:
|
|
- or go back to the newest paste.
| 1 | consoleRow = 3 | |
| 2 | cSpeaker = "Guide" | |
| 3 | invShown = false | |
| 4 | data = {}
| |
| 5 | ||
| 6 | data.melee = {
| |
| 7 | {
| |
| 8 | "Sword",5 | |
| 9 | } | |
| 10 | } | |
| 11 | ||
| 12 | data.player = {
| |
| 13 | inv = {
| |
| 14 | "empty","empty","empty" | |
| 15 | }, | |
| 16 | weaponType = "melee", | |
| 17 | weaponID = 1, | |
| 18 | hp = 10, | |
| 19 | int = 10, | |
| 20 | str = 10, | |
| 21 | dex = 10, | |
| 22 | gold = 10, | |
| 23 | name = "Explorer", | |
| 24 | class = "warrior", | |
| 25 | race = "human" | |
| 26 | } | |
| 27 | ||
| 28 | data.buttons = {
| |
| 29 | startGameYes = {
| |
| 30 | label = "Yes", | |
| 31 | color = colors.green | |
| 32 | }, | |
| 33 | startGameNo = {
| |
| 34 | label = "No ", | |
| 35 | color = colors.red | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | data.maps = {
| |
| 40 | {
| |
| 41 | {"X","X","X","X","X","X","X","X","X","X"},
| |
| 42 | {"X","X","X","X","X","X","X"," ","X","X"},
| |
| 43 | {"X"," "," "," "," "," "," "," "," ","X"},
| |
| 44 | {"X","X","X"," ","X","X","X","X","X","X"},
| |
| 45 | {"X","X","X","D","X","X","X","X","X","X"}
| |
| 46 | }, | |
| 47 | {
| |
| 48 | {"X","X","X","D","X","X","X","X","X","X"},
| |
| 49 | {"X"," "," "," "," "," "," "," "," ","X"},
| |
| 50 | {"X"," "," "," "," "," "," "," "," ","X"},
| |
| 51 | {"X","X","X","X","X","X","X","X","X","X"}
| |
| 52 | } | |
| 53 | } | |
| 54 | ||
| 55 | data.mapText = {
| |
| 56 | "You stand in a dreary corridor..", | |
| 57 | "You enter a dimly lit room" | |
| 58 | } | |
| 59 | ||
| 60 | data.menu = {
| |
| 61 | save = { label = "Save", output = "Not yet implemented :["},
| |
| 62 | exit = { label = "Exit", output = "Good Bye!"}
| |
| 63 | } | |
| 64 | ||
| 65 | function startGame() | |
| 66 | term.setBackgroundColor(colors.black) | |
| 67 | term.clear() | |
| 68 | term.setCursorPos(1,1) | |
| 69 | dial("Welcome to the dungeons of Mordug brave adventurer.")
| |
| 70 | dial("Are you sure your up for the challenge?")
| |
| 71 | end | |
| 72 | ||
| 73 | function drawButton(buttonName,x,y) | |
| 74 | if data["buttons"][buttonName] ~= nil then | |
| 75 | term.setCursorPos(x,y) | |
| 76 | term.setBackgroundColor(data["buttons"][buttonName]["color"]) | |
| 77 | term.write(" "..data["buttons"][buttonName]["label"].." ")
| |
| 78 | end | |
| 79 | end | |
| 80 | ||
| 81 | function getStartGame() | |
| 82 | drawButton("startGameYes",1,10)
| |
| 83 | drawButton("startGameNo",1,12)
| |
| 84 | event, button, x, y = os.pullEvent("mouse_click")
| |
| 85 | if x >= 1 and x <= 5 then | |
| 86 | if y == 10 then | |
| 87 | return true | |
| 88 | end | |
| 89 | if y == 12 then | |
| 90 | return false | |
| 91 | end | |
| 92 | end | |
| 93 | end | |
| 94 | ||
| 95 | function dial(txt) | |
| 96 | term.setCursorPos(26,consoleRow) | |
| 97 | print(cSpeaker..": "..txt) | |
| 98 | consoleRow = consoleRow+1 | |
| 99 | end | |
| 100 | ||
| 101 | function speaker(speak_) | |
| 102 | cpseaker = speak_ | |
| 103 | end | |
| 104 | ||
| 105 | function drawMap(name) | |
| 106 | if data["maps"][name] ~= nil then | |
| 107 | for i=1,#data["maps"][name] do | |
| 108 | for j = 1,#data["maps"][name][i] do | |
| 109 | term.setCursorPos(j,i) | |
| 110 | if data["maps"][name][i][j] == " " then | |
| 111 | term.setBackgroundColor(colors.black) | |
| 112 | term.write(" ")
| |
| 113 | elseif data["maps"][name][i][j] == "X" then | |
| 114 | term.setBackgroundColor(colors.gray) | |
| 115 | term.write(" ")
| |
| 116 | elseif data["maps"][name][i][j] == "D" then | |
| 117 | term.setBackgroundColor(colors.brown) | |
| 118 | term.write(" ")
| |
| 119 | end | |
| 120 | end | |
| 121 | end | |
| 122 | end | |
| 123 | currentMap = name | |
| 124 | end | |
| 125 | ||
| 126 | function drawPlayer(x,y) | |
| 127 | if currentMap ~= nil then | |
| 128 | if data["maps"][currentMap][y][x] == " " then | |
| 129 | term.setCursorPos(x,y) | |
| 130 | term.setBackgroundColor(colors.blue) | |
| 131 | term.write(" ")
| |
| 132 | elseif data["maps"][currentMap][y][x] == "X" or data["maps"][currentMap][y][x] == "D" then | |
| 133 | print("Invlaid! There's a wall there!")
| |
| 134 | shell.exit() | |
| 135 | else | |
| 136 | term.setCursorPos(x,y) | |
| 137 | term.setBackgroundColor(colors.blue) | |
| 138 | term.write(" ")
| |
| 139 | end | |
| 140 | else | |
| 141 | print("Invalid! No map loaded!")
| |
| 142 | shell.exit() | |
| 143 | end | |
| 144 | data.player.x = x | |
| 145 | data.player.y = y | |
| 146 | end | |
| 147 | ||
| 148 | function checkMove(x,y) | |
| 149 | if currentMap ~= nil then | |
| 150 | if data["maps"][currentMap][y][x] == " " then | |
| 151 | return "clear" | |
| 152 | elseif data["maps"][currentMap][y][x] == "X" then | |
| 153 | return "wall" | |
| 154 | elseif data["maps"][currentMap][y][x] == "D" then | |
| 155 | return "door" | |
| 156 | end | |
| 157 | end | |
| 158 | end | |
| 159 | ||
| 160 | function movePlayer(x,y) | |
| 161 | term.setCursorPos(data.player.x,data.player.y) | |
| 162 | term.setBackgroundColor(colors.black) | |
| 163 | term.write(" ")
| |
| 164 | term.setCursorPos(x,y) | |
| 165 | term.setBackgroundColor(colors.blue) | |
| 166 | term.write(" ")
| |
| 167 | data.player.x = x | |
| 168 | data.player.y = y | |
| 169 | end | |
| 170 | ||
| 171 | function renderInv(x,y) | |
| 172 | term.setCursorPos(x,y) | |
| 173 | term.setBackgroundColor(colors.black) | |
| 174 | term.write("INVENTORY:")
| |
| 175 | for i = 1,#data["player"]["inv"] do | |
| 176 | term.setCursorPos(x,y+i) | |
| 177 | term.write(data["player"]["inv"][i]) | |
| 178 | y_ = y+i | |
| 179 | end | |
| 180 | term.setCursorPos(x,#data["player"]["inv"]+y+1) | |
| 181 | term.write("Weapon: ")
| |
| 182 | term.write(data[data.player.weaponType][data.player.weaponID][1].." (dmg: "..data[data.player.weaponType][data.player.weaponID][2]..")") | |
| 183 | term.setCursorPos(x,#data["player"]["inv"]+y+2) | |
| 184 | term.write("Gold: "..data.player.gold)
| |
| 185 | end | |
| 186 | ||
| 187 | function drawConsole() | |
| 188 | term.setBackgroundColor(colors.black) | |
| 189 | for i = 1,19 do | |
| 190 | term.setCursorPos(26,i) | |
| 191 | term.write("|")
| |
| 192 | if i == 1 then | |
| 193 | term.write("Console")
| |
| 194 | elseif i == 2 then | |
| 195 | for i = 1,25 do | |
| 196 | term.write("-")
| |
| 197 | end | |
| 198 | end | |
| 199 | end | |
| 200 | end | |
| 201 | ||
| 202 | function getMapText(mapID) | |
| 203 | term.setBackgroundColor(colors.black) | |
| 204 | term.setCursorPos(27,consoleRow) | |
| 205 | --newRows_ = string.len(data["mapText"][mapID])/25 | |
| 206 | term.write(data["mapText"][mapID]) | |
| 207 | consoleRow = consoleRow + 1 | |
| 208 | end | |
| 209 | ||
| 210 | startGame() | |
| 211 | starter = getStartGame() | |
| 212 | ||
| 213 | if starter == true then | |
| 214 | term.setBackgroundColor(colors.black) | |
| 215 | term.clear() | |
| 216 | term.setCursorPos(1,1) | |
| 217 | drawMap(1) | |
| 218 | drawPlayer(2,3) | |
| 219 | drawConsole() | |
| 220 | --renderInv(1,8) | |
| 221 | while true do | |
| 222 | event,button = os.pullEvent("key")
| |
| 223 | if keys.getName(button) == "up" then | |
| 224 | check_ = checkMove(data.player.x,data.player.y-1) | |
| 225 | if check_ == "clear" then | |
| 226 | movePlayer(data.player.x,data.player.y-1) | |
| 227 | elseif check_ == "door" then | |
| 228 | term.setBackgroundColor(colors.black) | |
| 229 | term.clear() | |
| 230 | drawMap(currentMap-1) | |
| 231 | drawPlayer(2,3) | |
| 232 | if invShown == true then | |
| 233 | renderInv(1,8) | |
| 234 | end | |
| 235 | getMapText(currentRoom) | |
| 236 | end | |
| 237 | drawConsole() | |
| 238 | elseif keys.getName(button) == "right" then | |
| 239 | check_ = checkMove(data.player.x+1,data.player.y) | |
| 240 | if check_ == "clear" then | |
| 241 | movePlayer(data.player.x+1,data.player.y) | |
| 242 | end | |
| 243 | elseif keys.getName(button) == "left" then | |
| 244 | check_ = checkMove(data.player.x-1,data.player.y) | |
| 245 | if check_ == "clear" then | |
| 246 | movePlayer(data.player.x-1,data.player.y) | |
| 247 | end | |
| 248 | elseif keys.getName(button) == "down" then | |
| 249 | check_ = checkMove(data.player.x,data.player.y+1) | |
| 250 | if check_ == "clear" then | |
| 251 | movePlayer(data.player.x,data.player.y+1) | |
| 252 | elseif check_ == "door" then | |
| 253 | term.setBackgroundColor(colors.black) | |
| 254 | term.clear() | |
| 255 | drawMap(currentMap+1) | |
| 256 | drawPlayer(3,2) | |
| 257 | if invShown == true then | |
| 258 | renderInv(1,8) | |
| 259 | end | |
| 260 | getMapText(currentRoom) | |
| 261 | end | |
| 262 | drawConsole() | |
| 263 | elseif keys.getName(button) == "rightShift" then | |
| 264 | term.setBackgroundColor(colors.black) | |
| 265 | term.clear() | |
| 266 | term.setCursorPos(1,1) | |
| 267 | print("Thanks for playing CC Dungeons version ALPHA 0.0.1!")
| |
| 268 | os.sleep(2) | |
| 269 | os.reboot() | |
| 270 | elseif keys.getName(button) == "e" then | |
| 271 | if invShown == false then | |
| 272 | renderInv(1,8) | |
| 273 | invShown = true | |
| 274 | else | |
| 275 | term.setBackgroundColor(colors.black) | |
| 276 | term.clear() | |
| 277 | drawMap(currentMap) | |
| 278 | drawPlayer(data.player.x,data.player.y) | |
| 279 | invShown = false | |
| 280 | end | |
| 281 | elseif keys.getName(button) == "q" then | |
| 282 | getMapText(currentRoom) | |
| 283 | end | |
| 284 | drawConsole() | |
| 285 | end | |
| 286 | elseif starter == false then | |
| 287 | print("Then fly you fool!")
| |
| 288 | end |