This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wired2coffee's profile picture

Wired's RPG (v -1.0)

Started by Wired2coffee, 16 April 2012 - 11:48 PM
Wired2coffee #1
Posted 17 April 2012 - 01:48 AM
Unfortunately, it's not finished yet, but it'll be updated regularly!

COMPRESSED CODE:
http://pastebin.com/ENKqng80

ORIGINAL CODE:
Spoiler


function checkLines(file)
if fs.exists(file) == true then
sFile = fs.open(file, "r")
sCount = 0
for i = 1, math.huge do
line = sFile:readLine()
if line ~= nil then
sCount = sCount+1
else
return sCount
end
end
sFile:close()
else
return false
end
end
--POWER/HEALTH
function loadHealth(health, maxHealth)
term.setCursorPos(1,1)
if health <= 0 then
initDeath()
end
io.write("H: {")
for i = 1, health/maxHealth*30 do
io.write("|")
end
term.setCursorPos(35,1)
io.write("}")
term.setCursorPos(37,1)
if health == math.floor(health) then
io.write(health..".")
else
io.write(health)
end
end
function loadPower(power, maxPower)
term.setCursorPos(1,2)
if power < 0 then
power = 0
end
io.write("P: {")
for i = 1, power/maxPower*30 do
io.write("|")
end
term.setCursorPos(35,2)
io.write("}")
term.setCursorPos(37,2)
if power == math.floor(power) then
io.write(power..".")
else
io.write(power)
end
end
--POWER/HEALTH
--EXPERIENCE
function loadEXP()
term.setCursorPos(1,18)
io.write("{")
for i = 1, experience/(level^2*50)*46 do
io.write("|")
end
term.setCursorPos(49,18)
io.write("}")
term.setCursorPos(24,17)
io.write(level)
end
--EXPERIENCE
--SAVE/LOAD STUFF
function Save()
if fs.exists(".WiredGameSave") == true then
fs.delete(".WiredGameSave")
file = io.open(".WiredGameSave","w")
else
file = io.open(".WiredGameSave","w")
end
file:write(tostring(health).."n")
file:write(tostring(maxHealth).."n")
file:write(tostring(power).."n")
file:write(tostring(maxPower).."n")
file:write(tostring(charPos[1]).."n")
file:write(tostring(charPos[2]).."n")
file:write(char.."n")
file:write(tostring(healthRegen).."n")
file:write(tostring(powerRegen).."n")
file:write(tostring(level).."n")
file:write(tostring(armor).."n")
file:write(tostring(experience).."n")
--MORE STUFF TO SAVE(positions and all that)
file:close()
end
function Load()
file = fs.open(".WiredGameSave","r")
health = tonumber(file:readLine())
maxHealth = tonumber(file:readLine())
power = tonumber(file:readLine())
maxPower = tonumber(file:readLine())
charPos[1] = tonumber(file:readLine())
charPos[2] = tonumber(file:readLine())
char = tostring(file:readLine())
healthRegen = tonumber(file:readLine()) 
powerRegen = tonumber(file:readLine()) 
level = tonumber(file:readLine())
armor = tonumber(file:readLine())
experience = tonumber(file:readLine())
--MORE STUFF TO LOAD(positions and all that)
file:close()
end
--SAVE/LOAD STUFF
--DEATH
function initDeath()
term.clear()
term.setCursorPos(1,1)
print("You died, please submit score.")
EXPERIENCEZZZ = 0
for i=1, level do
EXPERIENCEZZZ = EXPERIENCEZZZ+i^2*50
end
print("Experience: "..EXPERIENCEZZZ)
io.write("Name: ")
inp = read()
file = fs.open(".WiredGameScores","r")
scores = {}
linesZZZ = checkLines(".WiredGameScores")
for i = 1, linesZZZ do
table.insert(scores, tostring(file:readLine()))
end
file:close()
file = io.open(".WiredGameScores","w")
file:write(tostring(inp)..": "..EXPERIENCEZZZ.."n")
for i = 1, linesZZZ do
file:write(tostring(scores[i]).."n")
end
fs.delete(".WiredGameSave")
os.reboot()
end
--DEATH
--SPELLS
function castSpell(spell, currentTick)
if spell == "Fire" then
fireSpell = {true, currentTick, charPos[1], charPos[2]}
end
if spell == "Fireball" then
fireballSpell = {true, currentTick, charPos[1], charPos[2], char}
end
if spell == "Fire Walk" then
firewalkSpell = {true, currentTick, charPos[1], charPos[2]}
end
if spell == "Super Fire" then
superfireSpell = {true, currentTick, charPos[1], charPos[2]}
end
end
--SPELLS
--INPUT
function processInput()
while true do
a, b = os.pullEvent()
if a == "key" then
if stopProcesses == false then --Asks if game is paused
if b == 17 then
if 3 < charPos[2] then
charPos[2] = charPos[2]-1
char = "^"
end
end
if b == 30 then
if charPos[1] > 1 then
charPos[1] = charPos[1]-1
char = "<"
end
end
if b == 32 then
if charPos[1] < 49 then
charPos[1] = charPos[1]+1
char = ">"
end
end
if b == 31 then
if charPos[2] < 17 then
charPos[2] = charPos[2]+1
char = "v"
end
end
if b == 57 then
castSpell(currentSpell, tick)
end
end
if b == 2 then
if level>=1 then
currentSpell = "Fire"
end
end
if b == 3 then
if level>=10 then
currentSpell = "Fireball"
end
end
if b == 4 then
if level>=20 then
currentSpell = "Fire Walk"
end 
end
if b == 5 then
if level>=30 then
currentSpell = "Super Fire"
end
end
if b == 6 then
if level>=40 then
currentSpell = ""
end
end
if b == 7 then
if level>=50 then
currentSpell = ""
end
end
if b == 18 then
if statsMenu == nil then 
statsMenu = true 
end
if statsMenu == true then
statsMenu = false
stopProcesses = false
else
statsMenu = true
stopProcesses = true
end
if statsMenu == true then
if scoreMenu == true then
scoreMenu = false
statsMenu = true
end
end
end
if b == 25 then
if scoreMenu == nil then 
scoreMenu = true 
end
if scoreMenu == true then
scoreMenu = false
stopProcesses = false
else
scoreMenu = true
stopProcesses = true
end
if statsMenu == true then
if scoreMenu == true then
scoreMenu = false
statsMenu = true
end
end
end
end 
end
end
--INPUT
--TICK
function processTick()
while true do 
--Tick System
if tick/20 == math.floor(tick/20) then
Save() --Saves every 1s automatically.
end
sleep(.05)
term.clear()
tick = tick+1
if statsMenu == true then
stopProcesses = true
else
stopProcesses = false
end
if scoreMenu == true then
stopProcesses = true
else
stopProcesses = false
end
--Tick System
--STATS
maxHealth = level*2
maxPower = math.floor(level*1.5)
healthRegen = maxHealth/3000
powerRegen = maxPower/1000
--STATS
--EXPBoxes
if stopProcesses == false then
ran = math.random(1000,1500)
ran2 = math.random(3,17)
ran3 = math.random(1,49)
ran4 = math.random(1,50)
ran5 = math.random(1,5)
if tick/ran == math.floor(tick/ran) then
table.insert(box, ran2)
table.insert(box2, ran3)
table.insert(box3, ran4)
if ran5 == 5 then
table.insert(box4, 1)
elseif ran5 == 4 then
table.insert(box4, 2)
elseif ran5 == 3 then
table.insert(box4, 3)
end
end
for i = 1, #box do
term.setCursorPos(box2[i], box[i])
if box4[i] == 2 or box4[i] == 3 then
io.write("O")
else
io.write("o")
if box4[i] == 1 then
box3[i] = 250
end
end
end
for i = 1, #box do
if charPos[1] == box2[i] then
if charPos[2] == box[i] then
term.setCursorPos(charPos[1]-1,charPos[2]-2)
io.write(tostring(box3[i]))
sleep(.08)
box[i] = -99
box2[i] = -99
experience = experience+box3[i]
box3[i] = -99
if box4[i] == 1 then
armor = armor+box4[i]
elseif box4[i] == 2 then
if armor>1 then
armor = armor-1
else
health = health-1
end
end
end
end
end
end
--EXPBoxes
--Power Regeneration
if statsMenu == false then --Asks if game is paused.
if health ~= maxHealth then
health = health+healthRegen
end
if power ~= maxPower then
power = power+powerRegen
end
if maxPower <= power then
power = maxPower
end
if maxHealth <= health then
health = maxHealth
end
term.setCursorPos(37, 1)
io.write("0.00000000000")
term.setCursorPos(37, 2)
io.write("0.00000000000")
loadHealth(health, maxHealth)
loadPower(power, maxPower)
end
--Power Regeneration
--Character
if statsMenu == false then --Asks if game is paused.
term.setCursorPos(charPos[1], charPos[2]) 
io.write(char)
if lastCharPos ~= charPos then
term.setCursorPos(lastCharPos[1],lastCharPos[2]) 
io.write(" ")
term.setCursorPos(charPos[1], charPos[2]) 
io.write(char)
end
lastCharPos[1] = charPos[1]
lastCharPos[2] = charPos[2]
end
--Character
--DING
if statsMenu == false then
loadEXP()
if experience >= level^2*50 then
level = level+1
experience = experience-(level-1)^2*50
end
if level == 100 then
experience = 0
end
end
--DING!
--Stats Screen
if scoreMenu == false then
if statsMenu == true then
stopProcesses = true
tick = tick-1
term.clear()
term.setCursorPos(1,1)
print("                  -GAME PAUSED-")
term.setCursorPos(1,4)
print("Health: "..health.."/"..maxHealth)
print("Health Regen: "..healthRegen*20 .." per second n")
print("Power: "..power.."/"..maxPower)
print("Power Regen: "..powerRegen*20 .." per second n")
print("Armor: "..armor.."/"..maxArmor.."n")
print("Level: "..level)
print("Experience: "..experience.."/"..tostring(level^2*50).."n")
io.write("Selected Spell: ")
if currentSpell == "" or currentSpell == nil then
io.write("None")
else
io.write(currentSpell)
end
sleep(.05)
else
stopProcesses = false
end
end
if statsMenu == true then
if scoreMenu == true then
scoreMenu = false
statsMenu = true
end
end
--Stats Screen
--Score Screen
if statsMenu == false then
if scoreMenu == true then
stopProcesses = true
term.clear()
tick = tick-1
file = fs.open(".WiredGameScores","r")
term.setCursorPos(21,1)
io.write("-SCORES-n")
for i = 1,14 do
term.setCursorPos(1,i+3)
print(file:readLine())
end
sleep(.05)
else
stopProcesses = false
file:close()
end
end
--Score Screen
--ARMOR
if armor >= maxArmor then
armor = maxArmor
end
if armor <= 0 then
armor = 0
end
--ARMOR
--Spells
if fireSpell[1] == true then
currentTick = fireSpell[2]
if power>0 then 
if tick < currentTick+10 then
charPos[1] = fireSpell[3]
charPos[2] = fireSpell[4]
term.setCursorPos(charPos[1]+1,charPos[2])
io.write("#")
term.setCursorPos(charPos[1]-1,charPos[2])
io.write("#")
term.setCursorPos(charPos[1],charPos[2]+1)
io.write("#")
term.setCursorPos(charPos[1],charPos[2]-1)
io.write("#")
power = power-.01
end
end
end
if fireballSpell[1] == true then
currentTick = fireSpell[2]
if power>0 then
vchar = fireballSpell[5]
if vchar == "^" then
if fireballSpell[4]-offsetY < 3 then
fireballSpell[1] = false
offsetY = 1 
end
term.setCursorPos(fireballSpell[3], fireballSpell[4]-offsetY)
io.write("|")
if tick/1 == math.floor(tick/1) then
offsetY = offsetY+1
power = power-(1/9)
end
end
if vchar == "v" then
if fireballSpell[4]+offsetY > 17 then 
fireballSpell[1] = false
offsetY = 1 
end
term.setCursorPos(fireballSpell[3], fireballSpell[4]+offsetY)
io.write("|")
if tick/1 == math.floor(tick/1) then
offsetY = offsetY+1
power = power-(1/9)
end
end
if vchar == ">" then
if fireballSpell[3]+offsetX > 48 then 
fireballSpell[1] = false
offsetX = 1
end
term.setCursorPos(fireballSpell[3]+offsetX, fireballSpell[4])
io.write("-")
if tick/1 == math.floor(tick/1) then
offsetX = offsetX+1
power = power-(1/9)
end
end
if vchar == "<" then
if fireballSpell[3]-offsetX < 1 then 
fireballSpell[1] = false
offsetX = 1
end
term.setCursorPos(fireballSpell[3]-offsetX, fireballSpell[4])
io.write("-")
if tick/1 == math.floor(tick/1) then
offsetX = offsetX+1
power = power-(1/9)
end
end
end
end
if firewalkSpell[1] == true then
currentTick = firewalkSpell[2]
if power>0 then 
if tick < currentTick+10 then
term.setCursorPos(charPos[1]+1,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1]-1,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]+1)
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]-1)
io.write("&amp;")
power = power-.015
end
end
end
if superfireSpell[1] == true then
currentTick = superfireSpell[2]
if power>0 then 
if tick < currentTick+10 then
term.setCursorPos(charPos[1]-1,charPos[2]+1)
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]+1)
io.write("&amp;")
term.setCursorPos(charPos[1]+1,charPos[2]+1)
io.write("&amp;")
term.setCursorPos(charPos[1]-1,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1]-2,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1]+1,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1]+2,charPos[2])
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]+2)
io.write("&amp;")
term.setCursorPos(charPos[1]-1,charPos[2]-1)
io.write("&amp;")
term.setCursorPos(charPos[1]+1,charPos[2]-1)
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]-1)
io.write("&amp;")
term.setCursorPos(charPos[1],charPos[2]-2)
io.write("&amp;")
power = power-.25
end
end
end
--Spells
end
end
--TICK
--MAIN
function MAIN()
charPos = {}
if lastCharPos == nil then
lastCharPos = {50, 50}
end
if fs.exists(".WiredGameScores") ~= true then
file = io.open(".WiredGameScores","w")
file:write(" ")
file:close()
end
if fs.exists(".WiredGameSave") ~= true then
file = io.open(".WiredGameSave","w")
file:write(tostring(3).."n") --health
file:write(tostring(3).."n") --maxHealth
file:write(tostring(3).."n") --power
file:write(tostring(3).."n") --MaxPower
file:write(tostring(1).."n") --character xPos
file:write(tostring(3).."n") --character yPos
file:write(tostring(">").."n") --character looks
file:write(tostring(.00099999).."n") --healthRegen
file:write(tostring(.005).."n") --powerRegen
file:write(tostring(1).."n") --level
file:write(tostring(0).."n") --armor
file:write(tostring(0).."n") --experience
file:write(tostring(0).."n") --game time
--MORE STUFF TO SAVE(positions and all that)
file:close()
end
Load()
if tick == nil then 
tick = 0 
end
term.clear()
maxArmor = level*10
fireSpell = {}
superfireSpell = {}
fireballSpell = {}
firewalkSpell = {}
currentSpell = "Fire"
offsetX = 1
offsetY = 1
maxHealth = level*2
maxPower = math.floor(level*1.5)
healthRegen = maxHealth/3000
powerRegen = maxPower/1000
box = {}
box2 = {}
box3 = {}
box4 = {}
stopProcesses = false
statsMenu = false
scoreMenu = false
parallel.waitForAny(processTick, processInput)
end
--MAIN
MAIN()


CONTROLS:

E: Stats Screen
W/A/S/D: Movement
P: Scores Screen
1-6: Select Spell (spells will become available every 10 levels, ending at level 50)
SPACE: Cast Spell (each spell consumes a different amount of power, displayed on the power bar)


TODO:

1. Last two spells
2. Mobs
3. Zones (maps)
4. Items (armor and all that)


Notable Stuff:

1. 12172 characters are in the code.
2. All code will be compressed, all on one line.
3. Your game saves every second, so if your game crashes, your RPG won't.

When you start playing the game, you'll notice these "O"s, those are experience orbs that spawn randomly throughout the game, these will probably get changed in later versions.


Images:

Spoiler


Please post suggestions, as well as what the last two spells should be, because I'm clueless (possibly ice?)
con2000 #2
Posted 17 April 2012 - 02:45 AM
Boss! :)/>/>
Wolvan #3
Posted 17 April 2012 - 08:21 AM
Like that 1!
Soo many RPGs floating around
Advert #4
Posted 17 April 2012 - 08:31 AM
I haven't had the chance to try this, but I notice that you are trying to hide your code. I am very dissapoint. You're also using some general globals, too, and that's pretty bad.

You're also making function(s) for thing(s) that already exist.
Wired2coffee #5
Posted 17 April 2012 - 12:35 PM
I haven't had the chance to try this, but I notice that you are trying to hide your code. I am very dissapoint. You're also using some general globals, too, and that's pretty bad.

You're also making function(s) for thing(s) that already exist.
Actually, I wasn't trying to hide my code, it just runs slightly faster on certain things like servers. If you'd like to see my original code, you can find it here: http://pastebin.com/p01FRSzH
Cloudy #6
Posted 17 April 2012 - 03:13 PM
The speed difference in removing whitespace will be negligible if there is a speed increase at all (I'm thinking not). Also, servers don't execute Lua code any differently than a client. The only reason you might perceive "lag" or sluggishness would be because it has to transmit any changes to the terminal to the clients over the internet.
Wired2coffee #7
Posted 17 April 2012 - 03:49 PM
The speed difference in removing whitespace will be negligible if there is a speed increase at all (I'm thinking not). Also, servers don't execute Lua code any differently than a client. The only reason you might perceive "lag" or sluggishness would be because it has to transmit any changes to the terminal to the clients over the internet.
Maybe I should've clarified, I meant I could get it onto a server faster. I normally use an automatic typer to paste things like that. Also, (just to note, I was playing at 250 FPS at the time in SSP), the game flickered every once in a while in the noncompressed version, meaning the text didn't update after the last frame was cleared. Whether or not this was just a coincidence, I figured better safe than sorry.
Learning_inpaired #8
Posted 17 May 2012 - 05:10 AM
you should make it work with a 4X4 screen and have it be wireless to a pc thats hooked up to screen
tommyroyall #9
Posted 20 May 2012 - 12:39 AM
Hey man, do I have permission to make small, personal mods for this?
rick3333 #10
Posted 01 January 2013 - 08:09 PM
great program
remiX #11
Posted 02 January 2013 - 12:57 AM
Why's the code compressed onto one line? O.o
nutcase84 #12
Posted 02 January 2013 - 12:01 PM
Nice program.
billysback #13
Posted 05 January 2013 - 03:04 AM
firstly, as Cloudy said there should be no difference between code with and without white space;
that's the definition of "white space is ignored", right?

secondly, TAB. Please, just press that one little button, whatever you are coding in should keep up with the tabs for you :(/>
the game looks pretty nice but the code is horrifically unreadable, maybe if it was tabbed I would see some form of organization…

another thing, if you are going to talk about the size of the game in terms of code then generally it is done in the amount of lines, not the amount of characters…
(It's 630 lines btw)