Skip to content

Commit

Permalink
slime balls pushed by spawn, quest block
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Feb 14, 2019
1 parent 9669750 commit d0c0be9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 14 deletions.
8 changes: 5 additions & 3 deletions entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ entities.chunkSize = 8
local entityDefs = {}
for _, v in ipairs{'player', 'slime', 'sorcerer', 'spoder', 'stingy', 'zombie', 'ant',
'newMonster1', 'newMonster2', 'mudskipper', 'mudskipperEvolved', 'godex',
'tree', 'wall', 'bush', 'bigRock', 'smallRock'} do
'tree', 'wall', 'bush', 'bigRock', 'smallRock', 'questBlock'} do
table.insert(entityDefs, require('entityDefs.' .. v))
end

Expand Down Expand Up @@ -63,12 +63,14 @@ function entities.server.update(dt)
end
end
end
-- spawn walls
-- spawn walls, quest block
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
if x == 0 and y == 0 then
entities.server.defs.questBlock:new{x=x, y=y}:spawn()
elseif serverRealm.world:getTile(x, y) == tile2id['wall'] then
entities.server.defs.wall:new{x=x, y=y}:spawn()
end
end
Expand Down
82 changes: 82 additions & 0 deletions entityDefs/questBlock.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

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

for _, sc in ipairs{'server', 'client'} do
questBlock[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

questBlock[sc].spawn = function(self)
self.body = love.physics.newBody(self.realm.physics.world, self.x, self.y, 'static')
self.shapes = {}
self.fixtures = {}
local shape = love.physics.newRectangleShape(15/2, 15/2, 15, 15)
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)
return self.base.spawn(self)
end

questBlock[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

questBlock[sc].type = 'questBlock'
end



function questBlock.client:draw()
local _shader = love.graphics.getShader()
local img = gfx.environment.questBlock
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 + 8)
local pdy = py - (vy + 8)
love.graphics.setColor(1, 1, 1)
love.graphics.setShader(shaders.outline)
shaders.outline:send('stepSize', {1/img:getWidth(), 1/img:getHeight()})
if math.abs(pdx) < playerController.interactRange
and math.abs(pdy) < playerController.interactRange then
shaders.outline:send('outlineColor', {0.8, 0.8, 0.8, 1})
else
shaders.outline:send('outlineColor', {0, 0, 0, 1})
end
love.graphics.push()
love.graphics.translate(vx, vy)
love.graphics.draw(img, 0, 0, 0, 1, 1,
2, img:getHeight() - 17)
love.graphics.pop()
love.graphics.setShader(_shader)
end



return questBlock
Binary file added gfx/environment/questBlock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion loadassets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ gfx = {
tree = love.graphics.newImage('gfx/environment/tree.png'),
bush = love.graphics.newImage('gfx/environment/bush.png'),
bigRock = love.graphics.newImage('gfx/environment/bigRock.png'),
smallRock = love.graphics.newImage('gfx/environment/smallRock.png')
smallRock = love.graphics.newImage('gfx/environment/smallRock.png'),
questBlock = love.graphics.newImage('gfx/environment/questBlock.png')
},
player = {
walk = {
Expand Down
9 changes: 0 additions & 9 deletions shaders/mapGen.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,5 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
choice = 8;
}

// test
if (p == vec2(0.0) || p == vec2(1.0, 0.0) || p == vec2(0.0, 1.0) || p == vec2(1.0, 2.0)) {
choice = 5;
}
if (p == vec2(0.0)+vec2(18.0, 0.0) || p == vec2(1.0, 0.0)+vec2(18.0, 0.0) || p == vec2(0.0, 1.0)+vec2(18.0, 0.0) || p == vec2(1.0, 2.0)+vec2(18.0, 0.0)) {
choice = 5;
}


return vec4(choice/255.0, 0.0, 0.0, 1.0);
}
15 changes: 14 additions & 1 deletion slimeBalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ slimeBalls.slimeType2color = {
slime1 = {0/255, 101/255, 234/255, 174/255},
slime2 = {0/255, 234/255, 101/255, 174/255}
}
slimeBalls.speed = 1.5e2

function slimeBalls.spawn(t)
local defaults = {
slimeType = 'slime1',
x = 0, y = 0,
angle = 0,
speed = 1.5e2,
speed = slimeBalls.speed,
life = 1,
pierce = 0,
damage = 5
Expand Down Expand Up @@ -59,6 +60,18 @@ end
function slimeBalls.update(dt)
for k, v in pairs(slimeBalls.container) do
v.x, v.y = v.body:getPosition()
local d = math.sqrt(v.x^2 + v.y^2)
if d < 8*15 then
local f = math.min((8*15 - d)*50, slimeBalls.speed)
local fx = v.x/d*f
local fy = v.y/d*f
v.body:applyForce(fx, fy)
local lvx, lvy = v.body:getLinearVelocity()
local dv = math.sqrt(lvx^2 + lvy^2)
if dv > slimeBalls.speed then
v.body:setLinearVelocity(lvx/dv*slimeBalls.speed, lvy/dv*slimeBalls.speed)
end
end
if gameTime - v.spawnTime > v.life then
slimeBalls.destroy(k)
end
Expand Down

0 comments on commit d0c0be9

Please sign in to comment.