|
| 1 | +-- utils.lua: Funkcje pomocnicze |
| 2 | + |
| 3 | +function checkCollision(a, b) |
| 4 | +return a.x < b.x + b.width and |
| 5 | +a.x + a.width > b.x and |
| 6 | +a.y < b.y + b.height and |
| 7 | +a.y + a.height > b.y |
| 8 | +end |
| 9 | + |
| 10 | +function checkCircleCollision(a, circle) |
| 11 | +local closestX = math.max(a.x, math.min(circle.x, a.x + a.width)) |
| 12 | +local closestY = math.max(a.y, math.min(circle.y, a.y + a.height)) |
| 13 | +local dx = closestX - circle.x |
| 14 | +local dy = closestY - circle.y |
| 15 | +return (dx * dx + dy * dy) < (circle.radius ^ 2) |
| 16 | +end |
| 17 | + |
| 18 | +function createParticles(x, y, count, color) |
| 19 | +for i = 1, count do |
| 20 | + table.insert(player.particles, { |
| 21 | + x = x, |
| 22 | + y = y, |
| 23 | + vx = math.random(-100, 100), |
| 24 | + vy = math.random(-100, 100), |
| 25 | + life = math.random(0.2, 0.5), |
| 26 | + color = color |
| 27 | + }) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + function saveHighScore(score) |
| 32 | + love.filesystem.write("highscore.txt", tostring(score)) |
| 33 | + end |
| 34 | + |
| 35 | + function loadHighScore() |
| 36 | + local data = love.filesystem.read("highscore.txt") |
| 37 | + return data and tonumber(data) or 0 |
| 38 | + end |
| 39 | + |
| 40 | + function saveHighestLevel(level) |
| 41 | + love.filesystem.write("highestlevel.txt", tostring(level)) |
| 42 | + end |
| 43 | + |
| 44 | + function loadHighestLevel() |
| 45 | + local data = love.filesystem.read("highestlevel.txt") |
| 46 | + return data and tonumber(data) or 1 |
| 47 | + end |
| 48 | + |
| 49 | + function saveAchievements() |
| 50 | + local data = "" |
| 51 | + for k, v in pairs(achievements) do |
| 52 | + data = data .. k .. "=" .. tostring(v) .. "\n" |
| 53 | + end |
| 54 | + love.filesystem.write("achievements.txt", data) |
| 55 | + end |
| 56 | + |
| 57 | + function loadAchievements() |
| 58 | + local ach = {hacker = false, data_collector = false, endless_runner = false, game_winner = false} |
| 59 | + local data = love.filesystem.read("achievements.txt") |
| 60 | + if data then |
| 61 | + for line in data:gmatch("[^\r\n]+") do |
| 62 | + local k, v = line:match("(%w+)=(%w+)") |
| 63 | + if k and v then |
| 64 | + ach[k] = (v == "true") |
| 65 | + end |
| 66 | + end |
| 67 | + end |
| 68 | + return ach |
| 69 | + end |
| 70 | + |
| 71 | + function unlockAchievement(name) |
| 72 | + if not achievements[name] then |
| 73 | + achievements[name] = true |
| 74 | + saveAchievements() |
| 75 | + end |
| 76 | + end |
0 commit comments