diff options
| -rw-r--r-- | entity.lua | 1 | ||||
| -rw-r--r-- | shaders/missing_texture.glsl | 21 | ||||
| -rw-r--r-- | world.lua | 20 |
3 files changed, 38 insertions, 4 deletions
@@ -9,6 +9,7 @@ function Entity:new(x, y, width, height, physicsWidth, physicsHeight) self.height = height self.physicsWidth = physicsWidth or width self.physicsHeight = physicsHeight or height + self.texture = love.graphics.newImage("assets/missing.png") return self end diff --git a/shaders/missing_texture.glsl b/shaders/missing_texture.glsl new file mode 100644 index 0000000..3824ade --- /dev/null +++ b/shaders/missing_texture.glsl @@ -0,0 +1,21 @@ +// missing_texture.glsl + +extern float scale = 16.0; + +vec4 effect(vec4 color, Image texture, vec2 uv, vec2 screen_coords) +{ + vec4 tex = Texel(texture, uv); + + // checker pattern + float cx = floor(screen_coords.x / scale); + float cy = floor(screen_coords.y / scale); + + float checker = mod(cx + cy, 2.0); + + vec3 magenta = vec3(1.0, 0.0, 1.0); + vec3 black = vec3(0.0, 0.0, 0.0); + + vec3 pattern = mix(magenta, black, checker); + + return vec4(pattern, tex.a) * color; +}
\ No newline at end of file @@ -100,6 +100,11 @@ function World:load(mapPath, tilesets) end end + local ok, shader = pcall(love.graphics.newShader, "shaders/missing_texture.glsl") + self.missingShader = ok and shader or nil + if not ok then + print("Warning: missing_texture.glsl not loaded, using fallback (no missing texture)") + end self.player = nil self.enemies = {} self.entities = {} @@ -358,7 +363,7 @@ function World:draw() drawTileLayer(self.tilemap:getBackgroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) drawTileLayer(self.tilemap:getGroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) for _, e in ipairs(self.entities) do - if e.draw then e:draw() else World.drawEntityDefault(e) end + if e.draw then e:draw() else World.drawEntityDefault(self, e) end end drawTileLayer(self.tilemap:getForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) love.graphics.setCanvas(mainCanvas) @@ -431,7 +436,8 @@ function World:draw() if not useRefraction then for _, e in ipairs(self.entities) do - if e.draw then e:draw() else World.drawEntityDefault(e) end + print(e) + if e.draw then e:draw() else World.drawEntityDefault(self, e) end end drawTileLayer(self.tilemap:getForegroundLayer(), mapTileW, mapTileH, tileGidInfo, viewMinX, viewMinY, viewMaxX, viewMaxY) end @@ -459,12 +465,18 @@ function World.drawPhysicsBodyOutlines(entityList) love.graphics.setColor(1, 1, 1, 1) end -function World.drawEntityDefault(entity) +function World.drawEntityDefault(self, entity) love.graphics.setColor(0.2, 0.6, 1, 1) if entity.isPlayer then love.graphics.setColor(1, 0.3, 0.2, 1) end - love.graphics.rectangle("fill", math.floor(entity.x), math.floor(entity.y), entity.width, entity.height) + if self.missingShader then + love.graphics.setShader(self.missingShader) + love.graphics.draw(entity.texture, math.floor(entity.x), math.floor(entity.y)) + love.graphics.setShader() + else + love.graphics.rectangle("fill", math.floor(entity.x), math.floor(entity.y), entity.width, entity.height) + end love.graphics.setColor(1, 1, 1, 1) end |
