Skip to content

Commit 2e60eed

Browse files
committed
fix(render): correct star drawing with triangulation
The previous `drawStar` implementation used a single `love.graphics.polygon` call with all the star vertices. This method is not suitable for rendering concave polygons and resulted in an incorrect visual representation of the star. Additionally, the copyright holder in the `LICENSE` file has been updated.
1 parent b75a960 commit 2e60eed

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Martin Wimpress of Oval Tutu.
3+
Copyright (c) 2025 Aliet Exposito.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

game/main.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,20 +656,34 @@ function love.update(dt)
656656
end
657657
end
658658

659-
-- Dibujar una estrella con un polígono
659+
-- Función para dibujar una estrella
660660
local function drawStar(x, y, r)
661+
love.graphics.push()
662+
love.graphics.translate(x, y)
663+
661664
local points = {}
662665
local spikes = 5
663-
local step = math.pi / spikes
666+
local outerRadius = r
667+
local innerRadius = r * 0.6
668+
local angleStep = 2 * math.pi / (spikes * 2)
664669

670+
-- Generar puntos de la estrella
665671
for i = 0, 2 * spikes - 1 do
666-
local radius = (i % 2 == 0) and r or r * 0.5
667-
local angle = i * step - math.pi / 2
668-
table.insert(points, x + math.cos(angle) * radius)
669-
table.insert(points, y + math.sin(angle) * radius)
672+
local radius = (i % 2 == 0) and outerRadius or innerRadius
673+
local angle = i * angleStep - math.pi / 2
674+
table.insert(points, math.cos(angle) * radius)
675+
table.insert(points, math.sin(angle) * radius)
676+
end
677+
678+
-- Usar triangulación para polígonos cóncavos
679+
local triangles = love.math.triangulate(points)
680+
681+
-- Dibujar cada triángulo
682+
for i, triangle in ipairs(triangles) do
683+
love.graphics.polygon("fill", triangle)
670684
end
671685

672-
love.graphics.polygon("fill", points)
686+
love.graphics.pop()
673687
end
674688

675689
function love.draw()

0 commit comments

Comments
 (0)