Skip to content

Commit

Permalink
better trees, bush, rocks, sound, video/audio option tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Feb 11, 2019
1 parent faf61d0 commit 9669750
Show file tree
Hide file tree
Showing 34 changed files with 522 additions and 509 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Open World RPG
## Running
Windows builds can be found on the [releases](https://github.com/parameterized/tier/releases) page

Instructions for running Love2D games from source can be found [here](https://love2d.org/wiki/Getting_Started)
Instructions for running Love2D games from source can be found [here](https://love2d.org/wiki/Getting_Started).
If you're on Windows, the easiest way to run is to drag the folder containing main.lua onto either love.exe or a shortcut to love.exe (C:\\Program Files\\LOVE\\love.exe)

## Controls
- WASD to move
- Left Shift to sprint
- Left Mouse Button to attack
- Left click to attack
- Right click to transfer item
- Shift-click or double-click to use item
- E to interact
Expand Down
1 change: 1 addition & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function client.connect(ip, port)
healPlayer = function(self, data)
local p = playerController.player
p.hp = math.min(p.hp + data.hp, p.hpMax)
sound.play('heal')
end,
damageText = function(self, data)
damageText.add(data)
Expand Down
37 changes: 26 additions & 11 deletions entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ entities.activeRadius = 500
entities.chunkSize = 8

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

Expand Down Expand Up @@ -62,15 +63,6 @@ function entities.server.update(dt)
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
Expand All @@ -81,6 +73,29 @@ function entities.server.update(dt)
end
end
end
-- spawn trees, bush, rocks
for _=1, 3 do
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 and grass surrounding
local onGrass = true
for i=-1, 1 do
for j=-1, 1 do
if serverRealm.world:getTile(x + i*15, y + j*15) ~= tile2id['grass'] then
onGrass = false
break
end
end
if not onGrass then break end
end
if onGrass then
local choices = {tree=40, bush=30, bigRock=10, smallRock=20}
choice = lume.weightedchoice(choices)
entities.server.defs[choice]:new{x=x, y=y}:spawn()
end
end
end
end
end
end
Expand Down
44 changes: 2 additions & 42 deletions entityDefs/ant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,7 @@ function ant.server:update(dt)
end

function ant.server:damage(d, clientId)
self.hp = self.hp - d
if self.hp <= 0 and not self.destroyed then
server.addXP(clientId, math.random(3, 5))
local bagItems = {}
local choices = {
none=50, shield=15, apple=20,
sword0=3, sword1=3, sword2=3, sword3=3, sword4=3
}
for _=1, 3 do
choice = lume.weightedchoice(choices)
if choice ~= 'none' then
local itemData = {imageId=choice}
if choice == 'sword0' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+10))
elseif choice =='sword1' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+12))
elseif choice =='sword2' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+14))
elseif choice =='sword3' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+16))
elseif choice =='sword4' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+18))
end
local itemId = items.server.newItem(itemData)
table.insert(bagItems, itemId)
end
end
local numItems = #bagItems
if numItems ~= 0 then
local type = lume.randomchoice{'lootBag', 'lootBag1', 'lootBagFuse'}
lootBag.server:new{
realm = serverRealm,
x = self.x, y = self.y,
items = bagItems,
type = type,
life = 30
}:spawn()
end
self:destroy()
end
serverEnemyDamage(self, d, clientId)
end


Expand Down Expand Up @@ -225,8 +186,7 @@ function ant.client:draw()
love.graphics.pop()

-- name, level
local mx, my = love.mouse.getPosition()
mx, my = window2game(mx, my)
local mx, my = window2game(love.mouse.getPosition())
mx, my = lume.round(mx), lume.round(my)
local wmx, wmy = camera:screen2world(mx, my)
if wmx > vx - img:getWidth()/2 and wmx < vx + img:getWidth()/2
Expand Down
91 changes: 91 additions & 0 deletions entityDefs/bigRock.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

local base = require 'entityDefs._base'
local bigRock = {
server = base.server:new(),
client = base.client:new()
}

for _, sc in ipairs{'server', 'client'} do
bigRock[sc].newDefaults = function()
local t = {
id = lume.uuid(),
x = 0, y = 0
}
if sc == 'server' then
t.base = base.server
t.realm = serverRealm
elseif sc == 'client' then
t.base = base.client
t.realm = clientRealm
end
return t
end

bigRock[sc].spawn = function(self)
self.body = love.physics.newBody(self.realm.physics.world, self.x, self.y, 'static')
self.polys = {
{0.075, 0.05, 0.875, 0.05, 0.975, 0.15, 0.025, 0.15}
}
-- transform - todo: load from file already transformed
local img = gfx.environment.bigRock
for _, v in pairs(self.polys) do
for i2, v2 in pairs(v) do
if (i2-1) % 2 == 0 then -- x
v[i2] = v2*img:getWidth() - img:getWidth()/2
else
v[i2] = v2*img:getWidth()*-1
end
end
end
self.shapes = {}
self.fixtures = {}
for _, v in pairs(self.polys) do
local shape = love.physics.newPolygonShape(unpack(v))
table.insert(self.shapes, shape)
local fixture = love.physics.newFixture(self.body, shape, 1)
table.insert(self.fixtures, fixture)
fixture:setUserData(self)
fixture:setCategory(4)
end
return self.base.spawn(self)
end

bigRock[sc].destroy = function(self)
if self.fixtures then
for _, v in pairs(self.fixtures) do
if not v:isDestroyed() then v:destroy() end
end
end
if self.body and not self.body:isDestroyed() then
self.body:destroy()
end
self.base.destroy(self)
end

bigRock[sc].type = 'bigRock'
end



function bigRock.client:draw()
local img = gfx.environment.bigRock
local vx, vy = self.body:getPosition()
vx, vy = lume.round(vx), lume.round(vy)
local p = playerController.player
local px, py = lume.round(p.x), lume.round(p.y)
local pdx = px - vx
local pdy = py - vy
local a = 1
if math.abs(px - vx) < lume.round(img:getWidth()/2) and pdy > -img:getHeight() and pdy < 0 then
a = 0.5
end
love.graphics.setColor(1, 1, 1, a)
love.graphics.push()
love.graphics.translate(vx, vy)
love.graphics.draw(img, 0, 0, 0, 1, 1, lume.round(img:getWidth()/2), img:getHeight())
love.graphics.pop()
end



return bigRock
49 changes: 49 additions & 0 deletions entityDefs/bush.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

local base = require 'entityDefs._base'
local bush = {
server = base.server:new(),
client = base.client:new()
}

for _, sc in ipairs{'server', 'client'} do
bush[sc].newDefaults = function()
local t = {
id = lume.uuid(),
x = 0, y = 0
}
if sc == 'server' then
t.base = base.server
t.realm = serverRealm
elseif sc == 'client' then
t.base = base.client
t.realm = clientRealm
end
return t
end

bush[sc].type = 'bush'
end



function bush.client:draw()
local img = gfx.environment.bush
vx, vy = lume.round(self.x), lume.round(self.y)
local p = playerController.player
local px, py = lume.round(p.x), lume.round(p.y)
local pdx = px - vx
local pdy = py - vy
local a = 1
if math.abs(px - vx) < lume.round(img:getWidth()/2) and pdy > -img:getHeight() and pdy < 0 then
a = 0.5
end
love.graphics.setColor(1, 1, 1, a)
love.graphics.push()
love.graphics.translate(vx, vy)
love.graphics.draw(img, 0, 0, 0, 1, 1, lume.round(img:getWidth()/2), img:getHeight())
love.graphics.pop()
end



return bush
44 changes: 2 additions & 42 deletions entityDefs/godex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,7 @@ function godex.server:update(dt)
end

function godex.server:damage(d, clientId)
self.hp = self.hp - d
if self.hp <= 0 and not self.destroyed then
server.addXP(clientId, math.random(3, 5))
local bagItems = {}
local choices = {
none=50, shield=15, apple=20,
sword0=3, sword1=3, sword2=3, sword3=3, sword4=3
}
for _=1, 3 do
choice = lume.weightedchoice(choices)
if choice ~= 'none' then
local itemData = {imageId=choice}
if choice == 'sword0' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+10))
elseif choice =='sword1' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+12))
elseif choice =='sword2' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+14))
elseif choice =='sword3' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+16))
elseif choice =='sword4' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+18))
end
local itemId = items.server.newItem(itemData)
table.insert(bagItems, itemId)
end
end
local numItems = #bagItems
if numItems ~= 0 then
local type = lume.randomchoice{'lootBag', 'lootBag1', 'lootBagFuse'}
lootBag.server:new{
realm = serverRealm,
x = self.x, y = self.y,
items = bagItems,
type = type,
life = 30
}:spawn()
end
self:destroy()
end
serverEnemyDamage(self, d, clientId)
end


Expand Down Expand Up @@ -232,8 +193,7 @@ function godex.client:draw()
love.graphics.pop()

-- name, level
local mx, my = love.mouse.getPosition()
mx, my = window2game(mx, my)
local mx, my = window2game(love.mouse.getPosition())
mx, my = lume.round(mx), lume.round(my)
local wmx, wmy = camera:screen2world(mx, my)
if wmx > vx - img:getWidth()/2 and wmx < vx + img:getWidth()/2
Expand Down
44 changes: 2 additions & 42 deletions entityDefs/mudskipper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,46 +99,7 @@ function mudskipper.server:update(dt)
end

function mudskipper.server:damage(d, clientId)
self.hp = self.hp - d
if self.hp <= 0 and not self.destroyed then
server.addXP(clientId, math.random(3, 5))
local bagItems = {}
local choices = {
none=50, shield=15, apple=20,
sword0=3, sword1=3, sword2=3, sword3=3, sword4=3
}
for _=1, 3 do
choice = lume.weightedchoice(choices)
if choice ~= 'none' then
local itemData = {imageId=choice}
if choice == 'sword0' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+10))
elseif choice =='sword1' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+12))
elseif choice =='sword2' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+14))
elseif choice =='sword3' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+16))
elseif choice =='sword4' then
itemData.atk = math.max(5, math.floor(love.math.randomNormal()*2+18))
end
local itemId = items.server.newItem(itemData)
table.insert(bagItems, itemId)
end
end
local numItems = #bagItems
if numItems ~= 0 then
local type = lume.randomchoice{'lootBag', 'lootBag1', 'lootBagFuse'}
lootBag.server:new{
realm = serverRealm,
x = self.x, y = self.y,
items = bagItems,
type = type,
life = 30
}:spawn()
end
self:destroy()
end
serverEnemyDamage(self, d, clientId)
end


Expand Down Expand Up @@ -223,8 +184,7 @@ function mudskipper.client:draw()
love.graphics.pop()

-- name, level
local mx, my = love.mouse.getPosition()
mx, my = window2game(mx, my)
local mx, my = window2game(love.mouse.getPosition())
mx, my = lume.round(mx), lume.round(my)
local wmx, wmy = camera:screen2world(mx, my)
if wmx > vx - w/2 and wmx < vx + w/2
Expand Down
Loading

0 comments on commit 9669750

Please sign in to comment.