temp block placing
This commit is contained in:
parent
219ab00a36
commit
ae3ee8fcb2
1 changed files with 62 additions and 24 deletions
86
main.lua
86
main.lua
|
@ -16,6 +16,9 @@ money = 0
|
||||||
|
|
||||||
local objects = {}
|
local objects = {}
|
||||||
|
|
||||||
|
local selectedTile = 1
|
||||||
|
local defaultTileRotation = 0
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
function getSprites(d)
|
function getSprites(d)
|
||||||
local dir = "assets/sprites"
|
local dir = "assets/sprites"
|
||||||
|
@ -51,26 +54,6 @@ function love.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setDefaultFilter('nearest', 'nearest')
|
love.graphics.setDefaultFilter('nearest', 'nearest')
|
||||||
|
|
||||||
world[1][1] = {2, rotation = 2}
|
|
||||||
world[2][1] = {2, rotation = 2}
|
|
||||||
world[3][1] = {2, rotation = 2}
|
|
||||||
world[4][1] = {2, rotation = 2}
|
|
||||||
world[5][1] = {2, rotation = 2}
|
|
||||||
|
|
||||||
world[1][3] = {2, rotation = 0}
|
|
||||||
world[2][3] = {2, rotation = 0}
|
|
||||||
world[3][3] = {2, rotation = 0}
|
|
||||||
world[4][3] = {2, rotation = 1}
|
|
||||||
|
|
||||||
world[1][2] = {3, rotation = 1}
|
|
||||||
world[2][2] = {3, rotation = 1}
|
|
||||||
world[3][2] = {3, rotation = 1}
|
|
||||||
world[4][2] = {3, rotation = 1}
|
|
||||||
world[5][2] = {3, rotation = 2}
|
|
||||||
world[5][3] = {3, rotation = 2}
|
|
||||||
|
|
||||||
world[5][4] = {4, rotation = 0}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local timer = 0
|
local timer = 0
|
||||||
|
@ -90,7 +73,7 @@ function love.update(dt)
|
||||||
table.insert(objects, {
|
table.insert(objects, {
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
size = 0.3,
|
size = math.random(30, 40)/100,
|
||||||
type = tile.obtains.id,
|
type = tile.obtains.id,
|
||||||
color = {0.5, 0.4, 0.4},
|
color = {0.5, 0.4, 0.4},
|
||||||
})
|
})
|
||||||
|
@ -109,6 +92,7 @@ function love.update(dt)
|
||||||
o.vely = o.vely or 0
|
o.vely = o.vely or 0
|
||||||
o.size = o.size or 0.5
|
o.size = o.size or 0.5
|
||||||
o.color = o.color or {1, 1, 1}
|
o.color = o.color or {1, 1, 1}
|
||||||
|
o.despawntimer = o.despawntimer or 0
|
||||||
|
|
||||||
local pass = true
|
local pass = true
|
||||||
local object = objectTypes[o.type]
|
local object = objectTypes[o.type]
|
||||||
|
@ -137,17 +121,30 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
for i2,o2 in ipairs(objects) do
|
for i2,o2 in ipairs(objects) do
|
||||||
if i ~= i2 and rectangleTouchingRectangle(o.x - o.size, o.y - o.size, o.size, o.size, o2.x - o2.size, o2.y - o2.size, o2.size, o2.size) then
|
if i ~= i2 and rectangleTouchingRectangle(o.x - o.size, o.y - o.size, o.size, o.size, o2.x - o2.size, o2.y - o2.size, o2.size, o2.size) then
|
||||||
pass = false
|
pass = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- this doesnt work
|
||||||
|
]]
|
||||||
|
|
||||||
if not pass then
|
if not pass then
|
||||||
o.velx = -o.velx
|
o.velx = -o.velx
|
||||||
o.vely = -o.vely
|
o.vely = -o.vely
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if math.abs(o.velx) < 0.01 and math.abs(o.vely) < 0.01 then
|
||||||
|
o.despawntimer = o.despawntimer + dt
|
||||||
|
else
|
||||||
|
o.despawntimer = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if o.despawntimer > 5 then
|
||||||
|
table.remove(objects, i)
|
||||||
|
end
|
||||||
|
|
||||||
o.x = o.x + o.velx * dt
|
o.x = o.x + o.velx * dt
|
||||||
o.y = o.y + o.vely * dt
|
o.y = o.y + o.vely * dt
|
||||||
o.velx = o.velx * 0.8
|
o.velx = o.velx * 0.8
|
||||||
|
@ -201,9 +198,11 @@ function love.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, o in ipairs(objects) do
|
for _, o in ipairs(objects) do
|
||||||
love.graphics.setColor(o.color)
|
local trans = 1 - (o.despawntimer / 5)
|
||||||
|
|
||||||
|
love.graphics.setColor({o.color[1], o.color[2], o.color[3], trans})
|
||||||
love.graphics.rectangle('fill', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
|
love.graphics.rectangle('fill', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
|
||||||
love.graphics.setColor(0, 0, 0)
|
love.graphics.setColor(0, 0, 0, trans)
|
||||||
love.graphics.rectangle('line', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
|
love.graphics.rectangle('line', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -234,6 +233,22 @@ function love.draw()
|
||||||
local a = -hoveredTileId.rotation * 90
|
local a = -hoveredTileId.rotation * 90
|
||||||
arrow(tilex, tiley, tilesize, tilesize, a)
|
arrow(tilex, tiley, tilesize, tilesize, a)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if selectedTile ~= 0 then
|
||||||
|
local drawTile = tiles[selectedTile]
|
||||||
|
local tilex = math.floor(love.mouse.getX() / tilesize) * tilesize
|
||||||
|
local tiley = math.floor(love.mouse.getY() / tilesize) * tilesize
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1, 0.5)
|
||||||
|
|
||||||
|
local sprite = s('tiles/' .. drawTile.name)
|
||||||
|
|
||||||
|
if sprite then
|
||||||
|
love.graphics.draw(sprite, tilex + tilesize/2, tiley + tilesize/2, math.rad((defaultTileRotation or 0) * 90), 1, 1, tilesize/2, tilesize/2)
|
||||||
|
else
|
||||||
|
love.graphics.rectangle('fill', tilex, tiley, tilesize, tilesize)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
@ -254,12 +269,35 @@ function love.mousepressed(x, y, button)
|
||||||
table.insert(objects, {
|
table.insert(objects, {
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
size = 0.3,
|
size = math.random(30, 40)/100,
|
||||||
type = tile.obtains.id,
|
type = tile.obtains.id,
|
||||||
color = {0.5, 0.4, 0.4},
|
color = {0.5, 0.4, 0.4},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if selectedTile ~= 0 then
|
||||||
|
world[math.floor(x/tilesize)][math.floor(y/tilesize)] = {selectedTile, rotation = defaultTileRotation}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif button == 2 then
|
||||||
|
local tileid = getCameraTile(x, y)
|
||||||
|
if tileid[1] ~= 0 then
|
||||||
|
world[math.floor(x/tilesize)][math.floor(y/tilesize)] = {0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.wheelmoved(x, y)
|
||||||
|
local mx, my = love.mouse.getPosition()
|
||||||
|
local tileid = getCameraTile(mx, my)
|
||||||
|
|
||||||
|
if tileid[1] ~= 0 then
|
||||||
|
local rot = math.min(math.max(((tileid.rotation or 0) + math.floor(y)) % 4, 0), 3)
|
||||||
|
defaultTileRotation = rot
|
||||||
|
tileid.rotation = rot
|
||||||
|
world[math.floor(mx/tilesize)][math.floor(my/tilesize)] = tileid
|
||||||
|
else
|
||||||
|
selectedTile = math.min(math.max(selectedTile + math.floor(y), 0), #tiles)
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue