diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..579f1ad --- /dev/null +++ b/main.lua @@ -0,0 +1,74 @@ +local inventory = { + {name = "Pistol", sprite = "sprites/pistol.png", descip = "Long range enchanced pacifier!"}, + {name = "Knife", sprite = "sprites/knife.png", descip = "For cutting that bread"}, + {name = "Fiber Wire", sprite = "sprites/fiberwire.png", descip = "Enhanced pacifier"}, + {name = "Syringe", sprite = "sprites/syringe.png", descip = "Poisoned syringe, hell yeah!"}, + {name = "Explosive", sprite = "sprites/explosive.png", descip = "Goes boom boom and boom!"} +} + +local currentIndex = 1 +local rotateAngle = 0 +local targetAngle = 0 +local rotationSpeed = math.pi / 2 +local centerX, centerY +local radius = 150 +local sprites = {} + +function love.load() + love.graphics.setFont(love.graphics.newFont(24)) + centerX = love.graphics.getWidth() / 2 + centerY = love.graphics.getHeight() / 2 + + for _, item in ipairs(inventory) do + sprites[item.name] = love.graphics.newImage(item.sprite) + end +end + +function smoothRotation(dt) + if math.abs(targetAngle - rotateAngle) > 0.01 then + local delta = targetAngle - rotateAngle + rotateAngle = rotateAngle + math.min(math.abs(delta), rotationSpeed * dt) * math.sign(delta) + else + rotateAngle = targetAngle + end +end +-- thank fuck for chatGPT being a thing for these formulas otherwise I'd never have figured It out +-- I'll leave It on github.. + +function love.update(dt) + smoothRotation(dt) +end + +function love.keypressed(key) + if key == "right" then + currentIndex = (currentIndex % #inventory) + 1 + targetAngle = targetAngle - (2 * math.pi / #inventory) + elseif key == "left" then + currentIndex = (currentIndex - 2) % #inventory + 1 + targetAngle = targetAngle + (2 * math.pi / #inventory) + end +end + +function love.draw() + love.graphics.print("Current Item: " .. inventory[currentIndex].name, centerX - 100, centerY + 200) + love.graphics.print(inventory[currentIndex].descip, centerX - 150, centerY + 250) + + for i, item in ipairs(inventory) do + local angle = (i - 1) * (2 * math.pi / #inventory) + rotateAngle + local x = centerX + math.cos(angle) * radius + local y = centerY + math.sin(angle) * radius + local sprite = sprites[item.name] + + if i == currentIndex then + love.graphics.setColor(1, 0.5, 0) + love.graphics.draw(sprite, x - sprite:getWidth() / 2, y - sprite:getHeight() / 2, 0, 1.2, 1.2) + else + love.graphics.setColor(1, 1, 1) + love.graphics.draw(sprite, x - sprite:getWidth() / 2, y - sprite:getHeight() / 2) + end + end +end + +function math.sign(x) + return x > 0 and 1 or x < 0 and -1 or 0 +end diff --git a/sprites/explosive.png b/sprites/explosive.png new file mode 100644 index 0000000..03a11d9 Binary files /dev/null and b/sprites/explosive.png differ diff --git a/sprites/fiberwire.png b/sprites/fiberwire.png new file mode 100644 index 0000000..c1c0659 Binary files /dev/null and b/sprites/fiberwire.png differ diff --git a/sprites/knife.png b/sprites/knife.png new file mode 100644 index 0000000..e02effc Binary files /dev/null and b/sprites/knife.png differ diff --git a/sprites/pistol.png b/sprites/pistol.png new file mode 100644 index 0000000..f2e1282 Binary files /dev/null and b/sprites/pistol.png differ diff --git a/sprites/syringe.png b/sprites/syringe.png new file mode 100644 index 0000000..2fa6442 Binary files /dev/null and b/sprites/syringe.png differ