funny tab space

This commit is contained in:
jill 2020-10-04 04:18:24 +03:00
parent c5cb06b38c
commit 219ab00a36
Signed by: oat
GPG key ID: DD83A9617A252385
4 changed files with 264 additions and 264 deletions

130
def.lua
View file

@ -1,79 +1,79 @@
tiles = {
{
name = 'axe_clicker',
displayname = 'Axe Clicker',
type = 'clicker',
obtains = {
id = 1,
count = 1,
},
cost = 10,
{
name = 'axe_clicker',
displayname = 'Axe Clicker',
type = 'clicker',
obtains = {
id = 1,
count = 1,
},
cost = 10,
desc = 'An axe clicker. Used to obtain wood.',
},
{
name = 'basic_chainsaw',
displayname = 'Basic Chainsaw',
type = 'mine',
obtains = {
id = 1,
count = 0.25,
},
cost = 100,
desc = 'An axe clicker. Used to obtain wood.',
},
{
name = 'basic_chainsaw',
displayname = 'Basic Chainsaw',
type = 'mine',
obtains = {
id = 1,
count = 0.25,
},
cost = 100,
desc = 'A primitive chainsaw. Automatically collects wood.'
},
{
name = 'conveyor_belt',
displayname = 'Conveyor Belt',
type = 'conveyor',
cost = 5,
speed = 1,
desc = 'Moves a resource from point a to point b'
},
{
name = 'basic_seller',
displayname = 'Basic Seller',
type = 'seller',
cost = 1500,
rate = 1,
desc = 'A basic seller. Automatically sells all items coming from the forward tile',
}
desc = 'A primitive chainsaw. Automatically collects wood.'
},
{
name = 'conveyor_belt',
displayname = 'Conveyor Belt',
type = 'conveyor',
cost = 5,
speed = 1,
desc = 'Moves a resource from point a to point b'
},
{
name = 'basic_seller',
displayname = 'Basic Seller',
type = 'seller',
cost = 1500,
rate = 1,
desc = 'A basic seller. Automatically sells all items coming from the forward tile',
}
}
objectTypes = {
{
name = 'wood',
cost = 1,
desc = 'A log of wood.',
color = {1, 0.5, 0}
}
{
name = 'wood',
cost = 1,
desc = 'A log of wood.',
color = {1, 0.5, 0}
}
}
--[[
-- Things that have exchange-values:
wood -> planks -> ...
cobblestone -> stone -> flat stone -> ...
sand -> glass -> ...
clay -> bricks
oil -> plastic -> ...
copper -> copper ingot
lead -> lead ingot
silver -> silver ingot
gold -> gold ingot -> ...
platinum -> platinum ingot
titanium -> titanium ingot
diamond -> refined diamond -> ...
u r a n i u m
-- Things that have exchange-values:
wood -> planks -> ...
cobblestone -> stone -> flat stone -> ...
sand -> glass -> ...
clay -> bricks
oil -> plastic -> ...
copper -> copper ingot
lead -> lead ingot
silver -> silver ingot
gold -> gold ingot -> ...
platinum -> platinum ingot
titanium -> titanium ingot
diamond -> refined diamond -> ...
u r a n i u m
nonobtanium
nonobtanium
latex -> pappa moomin latex suit
latex -> pappa moomin latex suit
-- Things that have use-values:
water
coal
-- Concepts:
-- Things that have use-values:
water
coal
-- Concepts:
]]

View file

@ -1,14 +1,14 @@
function arrow(x, y, w, h, a)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a)) * w/2
)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a + 100)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 100)) * h/2
)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a - 100)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a - 100)) * h/2
)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a)) * w/2
)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a + 100)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 100)) * h/2
)
love.graphics.line(
x + w/2 + math.sin(math.rad(a + 180)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a + 180)) * h/2,
x + w/2 + math.sin(math.rad(a - 100)) * w/2 * 0.8, y + h/2 + math.cos(math.rad(a - 100)) * h/2
)
end

360
main.lua
View file

@ -43,223 +43,223 @@ function love.load()
getSprites()
for x = 1, width do
world[x] = {}
for y = 1, height do
world[x][y] = {0}
end
end
for x = 1, width do
world[x] = {}
for y = 1, height do
world[x][y] = {0}
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][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][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[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}
world[5][4] = {4, rotation = 0}
end
local timer = 0
function love.update(dt)
for x = 1, width do
for y = 1, height do
local tileid = getTile(x, y)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
for x = 1, width do
for y = 1, height do
local tileid = getTile(x, y)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
if tile.type == 'mine' then
if ((timer + dt + x * 0.25 + y * 0.5) % (1/tile.obtains.count)) < ((timer + x * 0.25 + y * 0.5) % (1/tile.obtains.count)) then
local a = -(tileid.rotation or 0) * 90
local x = x + 0.5 - math.sin(math.rad(a)) * 0.7
local y = y + 0.5 - math.cos(math.rad(a)) * 0.7
table.insert(objects, {
x = x,
y = y,
size = 0.3,
type = tile.obtains.id,
color = {0.5, 0.4, 0.4},
})
end
end
end
end
end
if tile.type == 'mine' then
if ((timer + dt + x * 0.25 + y * 0.5) % (1/tile.obtains.count)) < ((timer + x * 0.25 + y * 0.5) % (1/tile.obtains.count)) then
local a = -(tileid.rotation or 0) * 90
local x = x + 0.5 - math.sin(math.rad(a)) * 0.7
local y = y + 0.5 - math.cos(math.rad(a)) * 0.7
table.insert(objects, {
x = x,
y = y,
size = 0.3,
type = tile.obtains.id,
color = {0.5, 0.4, 0.4},
})
end
end
end
end
end
timer = timer + dt
timer = timer + dt
for i,o in ipairs(objects) do
o.x = o.x or 0
o.y = o.y or 0
o.velx = o.velx or 0
o.vely = o.vely or 0
o.size = o.size or 0.5
o.color = o.color or {1, 1, 1}
for i,o in ipairs(objects) do
o.x = o.x or 0
o.y = o.y or 0
o.velx = o.velx or 0
o.vely = o.vely or 0
o.size = o.size or 0.5
o.color = o.color or {1, 1, 1}
local pass = true
local object = objectTypes[o.type]
local pass = true
local object = objectTypes[o.type]
local onTileId = getTile(math.floor(o.x), math.floor(o.y))
if onTileId[1] ~= 0 then
local onTile = tiles[onTileId[1]]
local a = -(onTileId.rotation or 0) * 90
if onTile.type == 'conveyor' then
o.velx = o.velx - math.sin(math.rad(a)) * onTile.speed
o.vely = o.vely - math.cos(math.rad(a)) * onTile.speed
elseif onTile.type == 'seller' then
local movementAngle = math.deg(math.atan2(o.vely, o.velx)) - 90
if onTileId.rotation then
local sellerAngle = onTileId.rotation * 90
if math.abs(movementAngle - sellerAngle) < 45 then
table.remove(objects, i)
money = money + object.cost
else
pass = false
end
end
else
pass = false
end
end
local onTileId = getTile(math.floor(o.x), math.floor(o.y))
if onTileId[1] ~= 0 then
local onTile = tiles[onTileId[1]]
local a = -(onTileId.rotation or 0) * 90
if onTile.type == 'conveyor' then
o.velx = o.velx - math.sin(math.rad(a)) * onTile.speed
o.vely = o.vely - math.cos(math.rad(a)) * onTile.speed
elseif onTile.type == 'seller' then
local movementAngle = math.deg(math.atan2(o.vely, o.velx)) - 90
if onTileId.rotation then
local sellerAngle = onTileId.rotation * 90
if math.abs(movementAngle - sellerAngle) < 45 then
table.remove(objects, i)
money = money + object.cost
else
pass = false
end
end
else
pass = false
end
end
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
pass = false
end
end
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
pass = false
end
end
if not pass then
o.velx = -o.velx
o.vely = -o.vely
end
if not pass then
o.velx = -o.velx
o.vely = -o.vely
end
o.x = o.x + o.velx * dt
o.y = o.y + o.vely * dt
o.velx = o.velx * 0.8
o.vely = o.vely * 0.8
end
o.x = o.x + o.velx * dt
o.y = o.y + o.vely * dt
o.velx = o.velx * 0.8
o.vely = o.vely * 0.8
end
end
function love.draw()
love.graphics.setBackgroundColor(0.8, 0.7, 0.7)
-- layer 1
for x = 1, width do
for y =1, height do
local drawx = x * tilesize
local drawy = y * tilesize
love.graphics.setBackgroundColor(0.8, 0.7, 0.7)
-- layer 1
for x = 1, width do
for y =1, height do
local drawx = x * tilesize
local drawy = y * tilesize
love.graphics.setColor(0.4, 0.3, 0.3)
love.graphics.rectangle('line', drawx, drawy, tilesize, tilesize)
love.graphics.setColor(0.4, 0.3, 0.3)
love.graphics.rectangle('line', drawx, drawy, tilesize, tilesize)
local tileid = getTile(x, y)
local tileid = getTile(x, y)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
local sprite = s('tiles/' .. tile.name)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
local sprite = s('tiles/' .. tile.name)
if sprite then
love.graphics.setColor(1, 1, 1)
love.graphics.draw(sprite, drawx + tilesize/2, drawy + tilesize/2, math.rad((tileid.rotation or 0) * 90), 1, 1, tilesize/2, tilesize/2)
else
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle('fill', drawx, drawy, tilesize, tilesize)
end
end
end
end
if sprite then
love.graphics.setColor(1, 1, 1)
love.graphics.draw(sprite, drawx + tilesize/2, drawy + tilesize/2, math.rad((tileid.rotation or 0) * 90), 1, 1, tilesize/2, tilesize/2)
else
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle('fill', drawx, drawy, tilesize, tilesize)
end
end
end
end
-- layer 2
for x = 0, width do
for y = 0, height do
local drawx = x * tilesize
local drawy = y * tilesize
-- layer 2
for x = 0, width do
for y = 0, height do
local drawx = x * tilesize
local drawy = y * tilesize
local hovered = mouseInsideRectangle(drawx, drawy, tilesize + 1, tilesize + 1)
local hovered = mouseInsideRectangle(drawx, drawy, tilesize + 1, tilesize + 1)
if hovered then
love.graphics.setColor(0.8, 0.7, 0.7)
love.graphics.rectangle('line', drawx, drawy, tilesize, tilesize)
end
end
end
if hovered then
love.graphics.setColor(0.8, 0.7, 0.7)
love.graphics.rectangle('line', drawx, drawy, tilesize, tilesize)
end
end
end
for _, o in ipairs(objects) do
love.graphics.setColor(o.color)
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.rectangle('line', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
end
for _, o in ipairs(objects) do
love.graphics.setColor(o.color)
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.rectangle('line', o.x * tilesize - o.size * tilesize / 2, o.y * tilesize - o.size * tilesize / 2, o.size * tilesize, o.size * tilesize)
end
local hoveredTileId = getCameraTile(love.mouse.getX(), love.mouse.getY())
if hoveredTileId[1] ~= 0 then
local tmaxwidth = 256
local padding = 4
local offset = 16
local hoveredTileId = getCameraTile(love.mouse.getX(), love.mouse.getY())
if hoveredTileId[1] ~= 0 then
local tmaxwidth = 256
local padding = 4
local offset = 16
local hoveredTile = tiles[hoveredTileId[1]]
local hoveredTile = tiles[hoveredTileId[1]]
local text = hoveredTile.displayname .. '\n' .. hoveredTile.desc
local textObj = love.graphics.newText(love.graphics.getFont(), text)
textObj:setf(text, tmaxwidth, 'left')
local text = hoveredTile.displayname .. '\n' .. hoveredTile.desc
local textObj = love.graphics.newText(love.graphics.getFont(), text)
textObj:setf(text, tmaxwidth, 'left')
local twidth, theight = textObj:getDimensions()
local mx, my = love.mouse.getPosition()
local tilex = math.floor(love.mouse.getX() / tilesize) * tilesize
local tiley = math.floor(love.mouse.getY() / tilesize) * tilesize
local twidth, theight = textObj:getDimensions()
local mx, my = love.mouse.getPosition()
local tilex = math.floor(love.mouse.getX() / tilesize) * tilesize
local tiley = math.floor(love.mouse.getY() / tilesize) * tilesize
love.graphics.setColor(0.9, 0.9, 0.9, 0.7)
love.graphics.rectangle('fill', mx + offset, my + offset, twidth + padding * 2, theight + padding * 2)
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.draw(textObj, mx + padding + offset, my + padding + offset)
love.graphics.setColor(0.9, 0.9, 0.9, 0.7)
love.graphics.rectangle('fill', mx + offset, my + offset, twidth + padding * 2, theight + padding * 2)
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.draw(textObj, mx + padding + offset, my + padding + offset)
if hoveredTileId.rotation then
love.graphics.setColor(1, 1, 1, 0.7)
local a = -hoveredTileId.rotation * 90
arrow(tilex, tiley, tilesize, tilesize, a)
end
end
if hoveredTileId.rotation then
love.graphics.setColor(1, 1, 1, 0.7)
local a = -hoveredTileId.rotation * 90
arrow(tilex, tiley, tilesize, tilesize, a)
end
end
love.graphics.setColor(1, 1, 1)
love.graphics.print(love.timer.getFPS() .. 'fps\n' .. money .. '$')
love.graphics.setColor(1, 1, 1)
love.graphics.print(love.timer.getFPS() .. 'fps\n' .. money .. '$')
end
function love.mousepressed(x, y, button)
if button == 1 then
local tileid = getCameraTile(x, y)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
if tile.type == 'clicker' then
local a = -tileid.rotation * 90
local x = math.floor(x/tilesize) + 0.5 - math.sin(math.rad(a)) * 0.7
local y = math.floor(y/tilesize) + 0.5 - math.cos(math.rad(a)) * 0.7
if button == 1 then
local tileid = getCameraTile(x, y)
if tileid[1] ~= 0 then
local tile = tiles[tileid[1]]
if tile.type == 'clicker' then
local a = -tileid.rotation * 90
local x = math.floor(x/tilesize) + 0.5 - math.sin(math.rad(a)) * 0.7
local y = math.floor(y/tilesize) + 0.5 - math.cos(math.rad(a)) * 0.7
for i = 1, tile.obtains.count do
table.insert(objects, {
x = x,
y = y,
size = 0.3,
type = tile.obtains.id,
color = {0.5, 0.4, 0.4},
})
end
end
end
end
for i = 1, tile.obtains.count do
table.insert(objects, {
x = x,
y = y,
size = 0.3,
type = tile.obtains.id,
color = {0.5, 0.4, 0.4},
})
end
end
end
end
end

View file

@ -1,24 +1,24 @@
function pointInsideRectangle(x1, y1, x2, y2, w, h)
return x1 > x2 and x1 < (x2 + w) and y1 > y2 and y1 < (y2 + w) -- An Awesome Project
return x1 > x2 and x1 < (x2 + w) and y1 > y2 and y1 < (y2 + w) -- An Awesome Project
end
function mouseInsideRectangle(x, y, w, h)
local x1, y1 = love.mouse.getPosition()
return pointInsideRectangle(x1, y1, x, y, w, h)
local x1, y1 = love.mouse.getPosition()
return pointInsideRectangle(x1, y1, x, y, w, h)
end
function rectangleTouchingRectangle(x1, y1, w1, h1, x2, y2, w2, h2)
return (x1 + w1 > x2 and x1 < x2 + w2) and (y1 + h1 > y2 and y1 < y2 + h2)
return (x1 + w1 > x2 and x1 < x2 + w2) and (y1 + h1 > y2 and y1 < y2 + h2)
end
function getTile(x, y)
return (world[x] or {})[y] or {0}
return (world[x] or {})[y] or {0}
end
function getCameraTile(cx, cy)
return getTile(math.floor(cx / tilesize), math.floor(cy / tilesize))
return getTile(math.floor(cx / tilesize), math.floor(cy / tilesize))
end
function s(name) -- sprite
return sprites[name]
return sprites[name]
end