Merge branch 'main' of https://github.com/jyelon/luprex into main
This commit is contained in:
@@ -6,5 +6,6 @@
|
||||
ut-table.lua
|
||||
ut-globaldb.lua
|
||||
ut-tablecmp.lua
|
||||
player.lua
|
||||
login.lua
|
||||
horps.lua
|
||||
|
||||
|
||||
110
luprex/core/lua/horps.lua
Normal file
110
luprex/core/lua/horps.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
makeclass('player')
|
||||
|
||||
--
|
||||
-- Data Structure
|
||||
-- Army.Count
|
||||
-- Army.Kind 'r','p','s'
|
||||
--
|
||||
|
||||
function player.interface(actor, place)
|
||||
gui.menu_item("cb_north", "Go North")
|
||||
gui.menu_item("cb_south", "Go South")
|
||||
gui.menu_item("cb_east", "Go East")
|
||||
gui.menu_item("cb_west", "Go West")
|
||||
gui.menu_item("cb_map", "Show the Map")
|
||||
gui.menu_item("cb_emit_army","Emit an Army")
|
||||
gui.menu_item("cb_emit_buff","Emit a Buff")
|
||||
end
|
||||
|
||||
function player:printanimstate()
|
||||
local graphic,plane,x,y,z,facing = tangible.animstate(self)
|
||||
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
||||
end
|
||||
|
||||
function player.cb_north(actor, place, dialog)
|
||||
tangible.animate(place, {action="walk", dy=1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_south(actor, place, dialog)
|
||||
tangible.animate(place, {action="walk", dy=-1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_east(actor, place, dialog)
|
||||
tangible.animate(place, {action="walk", dx=1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_west(actor, place, dialog)
|
||||
tangible.animate(place, {action="walk", dx=-1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_emit_army(actor,place,dialog)
|
||||
local _,pl,ax,ay=tangible.animstate(actor)
|
||||
t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='army'}
|
||||
pprint("building ",t)
|
||||
tangible.build(t)
|
||||
t.kind='r'
|
||||
t.count=5
|
||||
end
|
||||
|
||||
function player.cb_emit_buff(actor,place,dialog)
|
||||
local _,pl,ax,ay=tangible.animstate(actor)
|
||||
t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='buff'}
|
||||
pprint("building ",t)
|
||||
tangible.build(t)
|
||||
end
|
||||
|
||||
makeclass('army')
|
||||
makeclass('buff')
|
||||
|
||||
function seq(a,b,c) return a<=b and b<=c or false end
|
||||
|
||||
function player.cb_map(actor,place,dialog)
|
||||
local rad=2
|
||||
local scratch={}
|
||||
local lis=tangible.near(actor,rad,true,false)
|
||||
pprint("cb_map ",lis)
|
||||
for _,t in pairs(lis) do
|
||||
local graphic,plane,x,y,z,facing = tangible.animstate(t)
|
||||
local c=tangible.getclass(t)
|
||||
local dx,dy=tangible.xyz(t)
|
||||
local offset=(dy+rad)*(rad*2+1)+dx+rad
|
||||
local cl=tangible.getclass(t)
|
||||
print("Offset of "..cl.." is "..offset)
|
||||
if not scratch[offset] then scratch[offset]={} end
|
||||
if not scratch[offset].armies then scratch[offset].armies={} end
|
||||
if cl=='player' then table.insert(scratch[offset].armies,t) end
|
||||
if not scratch[offset].count then scratch[offset].count={}
|
||||
if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end
|
||||
if t.count then scratch[offset].count[cl]=scratch[offset].count[cl]+t.count end
|
||||
end
|
||||
for dy=-rad,rad do for line=0,1 do
|
||||
local lbuf=""
|
||||
for dx=-rad,rad do
|
||||
if line==0 then lbuf=lbuf.."---"
|
||||
elseif line==1 then
|
||||
local kc=0
|
||||
local tc=0
|
||||
local kstr=' '
|
||||
for k,c in pairs(scratch[offset].count) do if c>0 then
|
||||
kc=kc+1
|
||||
tc=tc+c
|
||||
if kc>1 then kstr='M' else kstr=k end
|
||||
end end
|
||||
lbuf=lbuf.."-"..kstr..(tc>0 and tc or " ")
|
||||
end end
|
||||
lbuf=lbuf.."-"
|
||||
print(lbuf)
|
||||
end end
|
||||
lbuf=""
|
||||
for dx=-rad,rad do lbuf=lbuf.."---" end
|
||||
lbuf=lbuf.."-"
|
||||
print(lbuf)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ end
|
||||
|
||||
function login.cb_becomeplayer(actor, place, dialog)
|
||||
tangible.setclass(actor, player)
|
||||
tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0})
|
||||
end
|
||||
|
||||
function login.cb_p123(actor, place, dialog)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
makeclass('player')
|
||||
|
||||
function player.interface(actor, place)
|
||||
-- print("actor=", actor)
|
||||
-- print("place=", place)
|
||||
-- print("t.actor=", tangible.actor())
|
||||
-- print("t.place=", tangible.place())
|
||||
gui.menu_item("cb_north", "Go North")
|
||||
gui.menu_item("cb_south", "Go South")
|
||||
gui.menu_item("cb_east", "Go East")
|
||||
gui.menu_item("cb_west", "Go West")
|
||||
end
|
||||
|
||||
function player:printanimstate()
|
||||
local graphic,plane,x,y,z,facing = tangible.animstate(self)
|
||||
print("Resulting state: ", graphic, plane, x, y, z, facing)
|
||||
end
|
||||
|
||||
function player.cb_north(actor, place, dialog)
|
||||
print("Moving north")
|
||||
tangible.animate(place, {action="walk", dy=1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_south(actor, place, dialog)
|
||||
print("Moving south")
|
||||
tangible.animate(place, {action="walk", dy=-1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_east(actor, place, dialog)
|
||||
print("Moving east")
|
||||
tangible.animate(place, {action="walk", dx=1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
function player.cb_west(actor, place, dialog)
|
||||
print("Moving west")
|
||||
tangible.animate(place, {action="walk", dx=-1})
|
||||
actor:printanimstate()
|
||||
end
|
||||
|
||||
|
||||
41
luprex/core/lua/teppygame.lua
Normal file
41
luprex/core/lua/teppygame.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
makeclass('grass')
|
||||
|
||||
if global.once("build grass") then
|
||||
for y=0,4 do for x=0,y%2==1 and 3 or 4 do
|
||||
tangible.build{class="grass",x=y%2==1 and 2*x+1 or 2*x+1,y=2*y+1,z=0,plane="main",graphic="grass"}
|
||||
end end
|
||||
end
|
||||
|
||||
if global.once("walkable") then global.walkable={} end
|
||||
if global.once("walkable main") then global.walkable["main"]={} end
|
||||
|
||||
|
||||
function walkable(pl,x,y)
|
||||
if not global.walkable then return false end
|
||||
if not global.walkable[pl] then return false end
|
||||
if not global.walkable[pl][y] then return false end
|
||||
return global.walkable[pl][y][x] or false
|
||||
end
|
||||
|
||||
function setwalkable(pl,x,y,val)
|
||||
if not global.walkable[pl][y] then global.walkable[pl][y]={} end
|
||||
global.walkable[pl][y][x]=val
|
||||
end
|
||||
|
||||
if global.once("walkablexy") then for y=0,4 do for x=0,4 do setwalkable("main",x,y,true) end end end
|
||||
|
||||
function player.move(actor,place,dx,dy)
|
||||
local _,pl,x,y,_,_=tangible.animstate(actor)
|
||||
print("Checking walkable "..pl.." "..x.." "..y.." is "..(walkable(pl,x+dx,y+dy) and "true" or "false"))
|
||||
if not walkable(pl,x+dx,y+dy) then print("Not walkable") else
|
||||
tangible.animate(place, {action="walk", dx=dx,dy=dy})
|
||||
local lis=tangible.near(actor,1,false,true)
|
||||
if #lis==0 then print("The area is empty")
|
||||
else for _,t in pairs(lis) do
|
||||
print("There is a "..tangible.getclass(t).." here")
|
||||
end end
|
||||
end
|
||||
_,pl,x,y,_,_=tangible.animstate(actor)
|
||||
print("Your location is "..x.." "..y)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user