Skip to content

Commit

Permalink
Made draw_fireball more efficient, and fleshed out menu somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
ionarevamp committed Nov 18, 2023
1 parent 2caa4d9 commit 686e884
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 54 deletions.
19 changes: 7 additions & 12 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
- ! Swap CENTER indices to have X value first. Not SUPER crucial, but can get confusing
- Inventory menu needs to have a good UI, perhaps reminiscent of band-likes.
> On that note, finish the menu templates ( menutemplate.txt )
> ! On that note, finish the menu templates ( menutemplate.txt )
- Consider reducing code bloat from busywait. ( slp() and busywait() are incompatible )
- Proper skill/spell/stat tableing ( data is also incomplete )
- Create standard order for listing & reading monster info from files
- Make better attempt at building files platform-independently ( windows sux tho:/ )
- Figure out how to use libbf for more accurate floats ( might help wait accuracy, although not crucial )
> libbf would likely aid in stat calculation
> src/lib/gmp.lua ?
- Implement more commands, like "cast", "status", "inv"/"item(s)"
> Synonym database?
- Figure out how to use src/lib/gmp.lua ...
- Synonym database for commands?
- Implement single-key input ( recommended steps not working, path unclear )
> link ncurses when compiling. Also, refer to ncurses_examples/ for help.
- How to use magic.lua ? ( should contain rules for magic, but necessary structure is unclear )
- CREATE MORE MONSTERRRS
- Figure out how memorytest.lua works, and gain insight <-- in progress
- ! Reduce memory leakage. <-- reduced calls to unpack(), as it copies rather than referencing
- ! Reduce memory leakage.
> Garbage collection is fine for now, but main loop should not be accumulating variables in memory without input.
- {Maybe use ncurses to shift into Unicode and back again}
- Regarding animations, "dirty rect" erasing+drawing technique should be utilized where possible
- ! Lua/LuaJIT has faster I/O buffer calls than C, so terminal writing functions should be handled by Lua
> ((port functions from C, done)), as well as creating buffer-equivalent funcs
> ! create method for concatenating all buffer characters into single string to minimize write steps
>> at some point, reduce redundant color code writing to minimize writebuffer
- at some point, reduce redundant color code writing to minimize writebuffer
- ! have method that stores previous coordinate separate from built-in "save cursor" escape code
- Circle drawing using sine calculations seems slow ( sqrt function? )
2 changes: 1 addition & 1 deletion src/intro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ for i = 1,#splash_text do
deadline = ((st*i)*duration/(100*#splash_text))
+writestart
rgbbg(gradientratio(
CLR.red,BGCOLOR,st,100,-1))
CLR.red,BGCOLOR,st,100))
rgbwr(charat(splash_text,i),gradientratio(--
CLR.goldmetal,CLR.gold,i,#splash_text))
io.flush()
Expand Down
9 changes: 8 additions & 1 deletion src/lib/buffer.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- Contains data and functions regarding program
-- and screen/terminal buffer manipulation

require("src/lib/strings")

mvdirs = {
Expand Down Expand Up @@ -202,7 +205,11 @@ function loadcursor() io.write("\027[u") end
local determine_break = {[true]="",[false]="io.write('');"}
local determine_horizontal = {[true]="C",[false]="D"}
local determine_vertical = {[true]="B",[false]="A"}
function mvcursor(x,y) -- Non-relative, starts at 1,1
function mvcursor(x,y,wrap) -- Non-relative, starts at 1,1
wrap = wrap or false
if (wrap == false and (flr(x)>WIDTH or flr(y)>HEIGHT)) then
return
end
io.write(conc("\027[",flr(y),";",flr(x),"H"))
-- LINE, then COLUMN
end
Expand Down
9 changes: 7 additions & 2 deletions src/lib/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ CLRV = {} -- TODO:for each CLR, create RGB vector via:
function gradient(rgb,rgb2,percent,dir)
-- MUST accept non-empty table
-- percentage as value from 0 to 1
percent = percent or 0.50
percent = math.abs(percent*btoi[percent<1.00])+
1.00*btoi[percent>1.00]
dir = dir or 1 --takes 1 or -1
local mathabs = math.abs
local gradient = {}
local diffs = {}
for i=1,3 do
local ins = table.insert
ins(diffs,mathabs(rgb2[i]-rgb[i]))
ins(gradient,rgb[i]+(dir*(diffs[i]*percent)))
ins(diffs,rgb2[i]-rgb[i])
ins(gradient,
rgb[i]+(dir*(diffs[i]*percent))
)
end
return gradient
end
Expand Down
4 changes: 3 additions & 1 deletion src/lib/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ end
function castspell(args)
local name = args[1]
if name == "fireball" then
draw_fireball()
local size = tonumber(args[2]) or 6
local target; -- set default target
draw_fireball(CENTER[2],CENTER[1],size)
slp()
end
end
24 changes: 15 additions & 9 deletions src/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ function flrall(arr)
for i=1,#tmp do tmp[i] = flr(arr[i]) end
return tmp
end
function newline(count)
for i=1,count do
io.write("\n")
end
end
function toggle(boolval)
local opposite = {[true]=false,[false]=true}
return opposite[boolval];
end
function gmch(...) return string.gmatch(...) end
function conc(...) --table.concat for speed(?)
local args = {...}
return table.concat(args)
function conc(...) --table.concat for speed(?)
return table.concat({...})
end;
-- COMPILE/BUILD
dofile("src/build.spec")
Expand All @@ -33,12 +41,8 @@ FGCOLOR = {255,255,255}
BGCOLOR = {0,0,0}
fr,fg,fb = unpack(FGCOLOR) -- mutable global variables to reduce memory usage in functions
br,bg,bb = unpack(BGCOLOR)
function sin(...)
return math.sin(...)
end
function cos(...)
return math.cos(...)
end
function sin(...) return math.sin(...) end
function cos(...) return math.cos(...) end
function slp(duration)
--os.execute(conc("tcc -run src/lib/sleep.c ","\"",duration,"\""))
duration = duration or 0.5
Expand All @@ -47,6 +51,8 @@ function slp(duration)
end
function input_buf() return dll.input_buf() end
function rgbwr(text,rgb)
-- merely limits inputs to valid format and range,
-- WITHOUT `if` statements.
fr = flr((255*btoi[rgb[1]>255])+(0*btoi[rgb[1]<0])+(rgb[1]*btoi[256 > rgb[1] and rgb[1] >= 0]))
fg = flr((255*btoi[rgb[2]>255])+(0*btoi[rgb[2]<0])+(rgb[2]*btoi[256 > rgb[2] and rgb[2] >= 0]))
fb = flr((255*btoi[rgb[3]>255])+(0*btoi[rgb[3]<0])+(rgb[3]*btoi[256 > rgb[3] and rgb[3] >= 0]))
Expand Down
14 changes: 12 additions & 2 deletions src/lib/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ startmenu = {
exit = "'Quit' / exit",
optioncount = 4,
}
racenames = {
"human","wild elf","luminant","dwarf"
}
racedata = {}
backgroundnames = {
"((Feature not yet implemented))"
}
playerstatus = {
{"Health","Stamina","Mana","Heat","Null","Space","Motion","Force"},
{Player.hp,Player.ep,Player.sp,Player.heat,Player.null,Player.space,Player.motion,Player.force}
{"Health","Stamina","Mana",
"Heat","Null","Space","Motion","Force"},
{Player.hp,Player.ep,Player.sp,
Player.stats.affinity.heat,Player.stats.affinity.null,
Player.stats.affinity.space,Player.stats.affinity.motion,Player.stats.affinity.force}
}

function startmenu:open()
Expand Down
14 changes: 8 additions & 6 deletions src/lib/spellgfx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ function draw_fireball(posx,posy,size,intensity)
cy = posy or CENTER[1]
local radius = size/2
local chars = {"O","x","+"}
os.execute("tput civis;")
for i=1,size do
os.execute("tput civis")
for i=0.1,size do
local curgradient = gradientratio(CLR.burntorange,{1,1,1},i,size)
rgbbg(curgradient)
mvcursor(1,1)
print(curgradient[1],curgradient[2],curgradient[3])
-- mvcursor(1,1)
-- print(curgradient[1],curgradient[2],curgradient[3])
local sqrt = math.sqrt
local x,y = 0,0
radius = i/2
for j=0,(math.pi*2),(math.pi*2)/(360-y) do
x = radius*cos(j)
y = radius*sin(j)/3
mvcursor(cx+x,cy+y)
rgbwr("0",
rgbwr(chars[3],
-- gradientratio(
-- CLR.burntorange,
-- CLR.red,size-(i/2),
-- size)
CLR.red
)
end
-- ensures last circle is drawn at full size
i=i+btoi[flr(i+1)~=size]
io.flush()
end
io.flush()
os.execute("tput cnorm")
end
23 changes: 13 additions & 10 deletions src/lib/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
creature = {
x = 1,
y = 1,
maxhp = 100,
age = 1,
stats = {
power = 1, --all life is born with power = 1 * powermod
Expand All @@ -36,7 +37,7 @@ creature = {
space = default,
motion = default,
force = default
},
}
},
genes = {
powermod = 1,
Expand Down Expand Up @@ -67,11 +68,13 @@ creature = {


-- COULD do this procedurally, but would be unnecessarily complex
function creature:new(o)
o = o or {}
function creature:new(type,statstable)
local o = statstable or {}
setmetatable(o, self)
self.__index = self
o.name = tostring(type)
o.stats.power = o.stats.power*(1+(((3*o.age)-((4*o.age)^2+o.age))/2))*o.genes.powermod
o.stats.power = math.abs(o.stats.power*btoi[o.stats.power >= 0])
o.stats.iq = o.stats.iq*o.genes.iq
o.stats.sight = o.stats.sight*o.genes.sight
o.stats.smell = o.stats.smell*o.genes.smell
Expand All @@ -81,8 +84,10 @@ function creature:new(o)
o.stats.size = o.stats.size*o.genes.size
o.stats.leverage = (default/o.stats.size)*o.stats.leverage*o.genes.leverage
o.stats.flex = (o.stats.flex*o.genes.flex)-(o.stats.flex/o.stats.size)
o.stats.intel = ((o.stats.iq/default)*((o.stats.sight+(o.stats.smell/20)+(o.stats.hearing/2)+(o.stats.taste/2)+(o.stats.touch*0.7)+math.floor(o.stats.iq/2000)+(o.stats.mana/10))/default))
o.stats.intel = ((o.stats.iq/default)*((o.stats.sight+(o.stats.smell/20)+(o.stats.hearing/2)+(o.stats.taste/2)+(o.stats.touch*0.7)+flr(o.stats.iq/2000)+(o.stats.mana/10))/default))
o.stats.esp = math.floor(o.stats.iq/2000)+math.floor(o.stats.intel)*o.genes.esp
o.maxhp = (o.maxhp-(o.stats.flex/3))*o.stats.power
o.hp = o.maxhp
for i=1,#o.stats.affinity do
o.stats.affinity = o.stats.affinity*o.genes.affinity
end
Expand All @@ -92,15 +97,13 @@ end

Player = creature:new()

function advanceAge() -- the idea here is that you age faster the older you are, bodily age
function advanceAge(creature) -- the idea here is that you age faster the older you are, bodily age
-- being different than how old you are in time
if math.floor(Player.age) > currentage then
Player.age = math.floor(Player.age)
Player.power = Player.power*(1+(((3*Player.age)-((4*Player.age)^2+Player.age))/2))
Player.stats.power = Player.stats.power*(1+(((3*Player.age)-((4*Player.age)^2+Player.age))/2))
Player.stats.intel = Player.stats.intel+( (Player.stats.iq/10)*(Player.stats.intel/(age*10)) )
end
end
function toggle(boolval)
local opposite = {[true]=false,[false]=true}
return opposite[boolval];
end


13 changes: 12 additions & 1 deletion src/lib/strings.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

function charat(text,index)
return string.sub(text,index,index)
end
function capitalize(text)
return conc( string.upper(charat(text,1)), string.sub(text,2,#text) )
end
function capitalizesentence(text)
local arr = {}
for word in gmch(text,"%S+") do
table.insert(arr,
conc(string.upper(charat(word,1)), string.sub(word,2,#text))
)
end
return table.concat(arr," ")
end
function swapflags(flagtable)
local swaptable = flagtable
for i=1,#swaptable do
Expand Down
8 changes: 5 additions & 3 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ function main()
tobuffer(30,11,"Print test 2",CLR.blue)
printlinebuf(11)
slp()
-- dofile("src/intro.lua")
-- c_print("Press Enter key to start",CENTER[2])
dofile("src/intro.lua")
c_print("Press Enter key to start",CENTER[2])
memcount()
mcr(CENTER[2]);io.flush();
-- io.read()
io.read()
io.write(conc("\027[2J\027[1;1H","Debug msg: Preparing...\n"))
slp()

Expand All @@ -44,6 +44,8 @@ function main()
CLR.darkgray,
defaultBG
)
dofile("src/lib/spellgfx.lua")
dofile("src/lib/commands.lua")
memcount()

cmd = {}
Expand Down
Empty file added src/mons/rat.info
Empty file.
Loading

0 comments on commit 686e884

Please sign in to comment.