Skip to content

Commit

Permalink
Merge pull request #3 from parameterized/dev
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
parameterized authored Feb 2, 2019
2 parents dea9f42 + faf61d0 commit c3f5a41
Show file tree
Hide file tree
Showing 71 changed files with 3,469 additions and 604 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Open World RPG

*Current version: 0.1.1*<br>
*Current version: 0.2.0*<br>
*Uses Love2D version 11.2.0*

![](https://i.imgur.com/rF9idF9.png)
Expand All @@ -22,7 +22,8 @@ If you're on Windows, the easiest way to run is to drag the folder containing ma
- Shift-click or double-click to use item
- E to interact
- Enter to open chat
- G to show fullscreen map
- Tab to toggle inventory
- M to toggle map
- L to toggle levels/stats
- F1 to toggle debug info
- F1 to toggle debug view
5 changes: 5 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function client.connect(ip, port)
healPlayer = function(self, data)
local p = playerController.player
p.hp = math.min(p.hp + data.hp, p.hpMax)
end,
damageText = function(self, data)
damageText.add(data)
end
}
for k, v in pairs(bitserRPCs) do
Expand Down Expand Up @@ -119,6 +122,7 @@ function client.connect(ip, port)
clientRealm:destroy()
slimeBalls.reset()
items.client.reset()
damageText.reset()
collectgarbage()
end
client.currentState = client.newState()
Expand Down Expand Up @@ -222,6 +226,7 @@ function client.update(dt)
playerController.update(dt)
entities.client.update(dt)
slimeBalls.update(dt)
damageText.update(dt)
end
end

Expand Down
38 changes: 38 additions & 0 deletions damageText.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

damageText = {
container = {}
}

function damageText.reset()
damageText.container = {}
end

-- t = {v=_, x=_, y=_}
function damageText.add(t)
if t.v == nil then t.v = 0 end
if t.x == nil then t.x = 0 end
if t.y == nil then t.y = 0 end
t.v = tostring(t.v)
t.timer = 1
table.insert(damageText.container, t)
end

function damageText.update(dt)
for k, v in pairs(damageText.container) do
v.timer = v.timer - dt*0.5
if v.timer < 0 then
damageText.container[k] = nil
end
end
end

function damageText.draw()
local font = fonts.stats
love.graphics.setFont(font)
for _, v in pairs(damageText.container) do
local t = ease.outCubic(1 - v.timer)
local y = v.y - t*8
love.graphics.setColor(1, 0, 0, 1 - t)
love.graphics.print(v.v, lume.round(v.x - font:getWidth(v.v)/2), lume.round(y - font:getHeight()/2))
end
end
50 changes: 31 additions & 19 deletions entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ entities = {
entities.activeRadius = 500
entities.chunkSize = 8

local entityDefs = {
require 'entityDefs.player',
require 'entityDefs.slime'
}
local entityDefs = {}
for _, v in ipairs{'player', 'slime', 'tree', 'wall', 'sorcerer', 'spoder', 'stingy', 'zombie', 'ant',
'newMonster1', 'newMonster2', 'mudskipper', 'mudskipperEvolved', 'godex'} do
table.insert(entityDefs, require('entityDefs.' .. v))
end

for _, sc in ipairs{'server', 'client'} do
-- entities.server.defs.slime = slime.server
Expand All @@ -26,16 +27,6 @@ for _, sc in ipairs{'server', 'client'} do
end
end

--[[
function entities.server.load()
-- todo: load chunks
for i=1, 8 do
local x, y = (math.random()*2-1)*256, (math.random()*2-1)*256
entities.server.defs.slime:new{x=x, y=y}:spawn()
end
end
]]

function entities.server.reset()
for etype, _ in pairs(entities.server.defs) do
for _, v in pairs(entities.server.container[etype] or {}) do
Expand All @@ -57,18 +48,39 @@ function entities.server.update(dt)
if newActiveChunks[cx] == nil then newActiveChunks[cx] = {} end
newActiveChunks[cx][cy] = true
if not entities.server.activeChunks[cx] or not entities.server.activeChunks[cx][cy] then
local choices = {none=90, slime=10}
-- spawn enemies
local choices = {none=80, slime=2, sorcerer=2, spoder=2, stingy=2, zombie=2, ant=2,
newMonster1=2, newMonster2=2, mudskipper=1, mudskipperEvolved=1, godex=2}
for _=1, 3 do
choice = lume.weightedchoice(choices)
if choice ~= 'none' then
local x = cx*entities.chunkSize*15 + math.random()*entities.chunkSize*15
local y = cy*entities.chunkSize*15 + math.random()*entities.chunkSize*15
-- if not in spawn area
if not (x^2 + y^2 < 192^2) then
local x = (cx*entities.chunkSize + math.random()*entities.chunkSize)*15
local y = (cy*entities.chunkSize + math.random()*entities.chunkSize)*15
-- if not in spawn area or wall
if x^2 + y^2 > 192^2 and serverRealm.world:getTile(x, y) ~= tile2id['wall'] then
entities.server.defs[choice]:new{x=x, y=y}:spawn()
end
end
end
-- spawn trees
if math.random() < 0.5 then
local x = (cx*entities.chunkSize + math.random()*entities.chunkSize)*15
local y = (cy*entities.chunkSize + math.random()*entities.chunkSize)*15
-- if on grass
if serverRealm.world:getTile(x, y) == tile2id['grass'] then
entities.server.defs.tree:new{x=x, y=y}:spawn()
end
end
-- spawn walls
for i=1, entities.chunkSize do
for j=1, entities.chunkSize do
local x = (cx*entities.chunkSize + (i-1))*15
local y = (cy*entities.chunkSize + (j-1))*15
if serverRealm.world:getTile(x, y) == tile2id['wall'] then
entities.server.defs.wall:new{x=x, y=y}:spawn()
end
end
end
end
end
end
Expand Down
32 changes: 12 additions & 20 deletions entityDefs/_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ for _, sc in ipairs{'server', 'client'} do
base[sc].newDefaults = function()
return {
id = lume.uuid(),
x = 0, y
x = 0, y = 0
}
end

base[sc].new = function(self, o)
o = o or {}
for k, v in pairs(self.newDefaults()) do
if o[k] == nil then o[k] = v end
end
setmetatable(o, self)
self.__index = self
return o
end

-- entities.server.defs[type]
base[sc].type = 'base'
base[sc].static = true
end

function base.server:new(o)
o = o or {}
for k, v in pairs(self.newDefaults()) do
if o[k] == nil then o[k] = v end
end
setmetatable(o, self)
self.__index = self
return o
end


function base.server:spawn()
self.destroyed = false
Expand Down Expand Up @@ -70,16 +72,6 @@ end



function base.client:new(o)
o = o or {}
for k, v in pairs(self.newDefaults()) do
if o[k] == nil then o[k] = v end
end
setmetatable(o, self)
self.__index = self
return o
end

function base.client:spawn()
self.destroyed = false
client.currentState.entities[self.id] = self
Expand Down
Loading

0 comments on commit c3f5a41

Please sign in to comment.