This repository has been archived by the owner on May 6, 2024. It is now read-only.
forked from jakubg1/OpenSMCE
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This moves skulls into their own class - Hole (just like the original code for Zuma), and it borrows code from UIWidgetSpriteProgress. Contributes to issue #9
- Loading branch information
1 parent
f5f66ea
commit 05631b4
Showing
3 changed files
with
106 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
local class = require "com.class" | ||
|
||
---@class Hole | ||
---@overload fun(params):Hole | ||
local Hole = class:derive("Hole") | ||
|
||
local Vec2 = require("src.Essentials.Vector2") | ||
|
||
|
||
|
||
--[[ | ||
!! READ BEFORE IMPLEMENTING THIS TO UPSTREAM !! | ||
This fork-specific class has hardcoded values. De-hardcode and allow for | ||
customization before implementing to upstream. | ||
This only allows for smooth movement of the top sprite. Consider the following | ||
prior to implementing this class to upstream: | ||
- allow ZD-style skull animations (sprite states) | ||
- allow multiple animations/sprite positions | ||
- allow multiple effects | ||
- etc... | ||
]] | ||
|
||
---Initializes a new Hole. | ||
---@param path Path | ||
function Hole:new(path) | ||
self.path = path | ||
self.pos = Vec2.round(path.nodes[#path.nodes].pos) | ||
|
||
self.skullHoleSprite = _Game.resourceManager:getSprite("sprites/game/skull_hole.json") | ||
self.skullMaskSprite = _Game.resourceManager:getSprite("sprites/game/skull_mask.json") | ||
self.skullFrameSprite = _Game.resourceManager:getSprite("sprites/game/skull_frame.json") | ||
self.skullTopSprite = _Game.resourceManager:getSprite("sprites/game/skull_top.json") | ||
self.skullBottomSprite = _Game.resourceManager:getSprite("sprites/game/skull_bottom.json") | ||
self.skullMaskShader = love.graphics.newShader [[ | ||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) { | ||
if (Texel(texture, texture_coords).rgb == vec3(0.0)) { | ||
// a discarded pixel wont be applied as the stencil. | ||
discard; | ||
} | ||
return vec4(1.0); | ||
} | ||
]] | ||
|
||
self.topSpriteOffset = 0 | ||
-- the bottom sprite doesn't move | ||
end | ||
|
||
|
||
|
||
function Hole:update(dt) | ||
local dangerProgress = self.path:getDangerProgress() | ||
|
||
-- top sprite | ||
local topSpriteOffsetBuffer = dangerProgress*20 | ||
if self.topSpriteOffset < topSpriteOffsetBuffer then | ||
self.topSpriteOffset = math.min(self.topSpriteOffset + 20 * dt, topSpriteOffsetBuffer) | ||
elseif self.topSpriteOffset > topSpriteOffsetBuffer then | ||
self.topSpriteOffset = math.max(self.topSpriteOffset - 4 * dt, topSpriteOffsetBuffer) | ||
end | ||
|
||
-- ring of fire | ||
-- the ring of fire uses some sort of animation that changes depending on the state, | ||
-- an opacity value won't do | ||
end | ||
|
||
|
||
|
||
function Hole:draw() | ||
self.skullHoleSprite:draw(self.pos, Vec2(0.5,0.5)) | ||
love.graphics.stencil(function() | ||
love.graphics.setShader(self.skullMaskShader) | ||
self.skullMaskSprite:draw(self.pos, Vec2(0.5,0.5)) | ||
love.graphics.setShader() | ||
end, "replace", 1) | ||
love.graphics.setStencilTest("greater", 0) | ||
|
||
local skullTopPos = Vec2(self.pos.x, (self.pos.y-3) - self.topSpriteOffset) | ||
local skullBotPos = Vec2(self.pos.x, self.pos.y+10) | ||
|
||
self.skullTopSprite:draw(skullTopPos, Vec2(0.5,0.5)) | ||
self.skullBottomSprite:draw(skullBotPos, Vec2(0.5, 0.5)) | ||
|
||
love.graphics.setStencilTest() | ||
self.skullFrameSprite:draw(self.pos, Vec2(0.5,0.5)) | ||
end | ||
|
||
|
||
|
||
return Hole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters