feat: implement textured line clear effects and refine UI alignment
- **Visual Effects**: Upgraded line clear particles to use the game's block texture instead of simple circles, matching the reference web game's aesthetic. - **Particle Physics**: Tuned particle velocity, gravity, and fade rates for a more dynamic explosion effect. - **Rendering Integration**: Updated [main.cpp](cci:7://file:///d:/Sites/Work/tetris/src/main.cpp:0:0-0:0) and `GameRenderer` to pass the block texture to the effect system and correctly trigger animations upon line completion. - **Menu UI**: Fixed [MenuState](cci:1://file:///d:/Sites/Work/tetris/src/states/MenuState.cpp:19:0-19:55) layout calculations to use fixed logical dimensions (1200x1000), ensuring consistent centering and alignment of the logo, buttons, and settings icon across different window sizes. - **Code Cleanup**: Refactored `PlayingState` to delegate effect triggering to the rendering layer where correct screen coordinates are available.
This commit is contained in:
64
src/core/interfaces/IAssetLoader.h
Normal file
64
src/core/interfaces/IAssetLoader.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for asset loading operations
|
||||
*
|
||||
* Provides a common interface for loading different types of assets,
|
||||
* enabling dependency injection and easier testing.
|
||||
*/
|
||||
class IAssetLoader {
|
||||
public:
|
||||
virtual ~IAssetLoader() = default;
|
||||
|
||||
/**
|
||||
* @brief Load a texture from file (interface method)
|
||||
* @param path Path to the texture file
|
||||
* @return Pointer to loaded SDL_Texture, nullptr on failure
|
||||
*/
|
||||
virtual SDL_Texture* loadTextureFromPath(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* @brief Load a font from file (interface method)
|
||||
* @param name Font identifier/name
|
||||
* @param path Path to the font file
|
||||
* @param size Font size in pixels
|
||||
* @return true if font was loaded successfully, false otherwise
|
||||
*/
|
||||
virtual bool loadFontAsset(const std::string& name, const std::string& path, int size) = 0;
|
||||
|
||||
/**
|
||||
* @brief Load an audio file (interface method)
|
||||
* @param name Audio identifier/name
|
||||
* @param path Path to the audio file
|
||||
* @return true if audio was loaded successfully, false otherwise
|
||||
*/
|
||||
virtual bool loadAudioAsset(const std::string& name, const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get a previously loaded texture (interface method)
|
||||
* @param name Texture identifier/name
|
||||
* @return Pointer to SDL_Texture, nullptr if not found
|
||||
*/
|
||||
virtual SDL_Texture* getTextureAsset(const std::string& name) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if an asset exists
|
||||
* @param name Asset identifier/name
|
||||
* @return true if asset exists, false otherwise
|
||||
*/
|
||||
virtual bool hasAsset(const std::string& name) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Unload a specific asset
|
||||
* @param name Asset identifier/name
|
||||
*/
|
||||
virtual void unloadAsset(const std::string& name) = 0;
|
||||
|
||||
/**
|
||||
* @brief Unload all assets
|
||||
*/
|
||||
virtual void unloadAll() = 0;
|
||||
};
|
||||
55
src/core/interfaces/IAudioSystem.h
Normal file
55
src/core/interfaces/IAudioSystem.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for audio system operations
|
||||
*
|
||||
* Provides a common interface for audio playback, enabling
|
||||
* dependency injection and easier testing.
|
||||
*/
|
||||
class IAudioSystem {
|
||||
public:
|
||||
virtual ~IAudioSystem() = default;
|
||||
|
||||
/**
|
||||
* @brief Play a sound effect
|
||||
* @param name Sound effect name/identifier
|
||||
*/
|
||||
virtual void playSound(const std::string& name) = 0;
|
||||
|
||||
/**
|
||||
* @brief Play background music
|
||||
* @param name Music track name/identifier
|
||||
*/
|
||||
virtual void playMusic(const std::string& name) = 0;
|
||||
|
||||
/**
|
||||
* @brief Stop currently playing music
|
||||
*/
|
||||
virtual void stopMusic() = 0;
|
||||
|
||||
/**
|
||||
* @brief Set master volume for all audio
|
||||
* @param volume Volume level (0.0 to 1.0)
|
||||
*/
|
||||
virtual void setMasterVolume(float volume) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set music volume
|
||||
* @param volume Volume level (0.0 to 1.0)
|
||||
*/
|
||||
virtual void setMusicVolume(float volume) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set sound effects volume
|
||||
* @param volume Volume level (0.0 to 1.0)
|
||||
*/
|
||||
virtual void setSoundVolume(float volume) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if music is currently playing
|
||||
* @return true if music is playing, false otherwise
|
||||
*/
|
||||
virtual bool isMusicPlaying() const = 0;
|
||||
};
|
||||
73
src/core/interfaces/IGameRules.h
Normal file
73
src/core/interfaces/IGameRules.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for game rules
|
||||
*
|
||||
* Provides a common interface for different Tetris rule implementations,
|
||||
* enabling different game modes and rule variations.
|
||||
*/
|
||||
class IGameRules {
|
||||
public:
|
||||
virtual ~IGameRules() = default;
|
||||
|
||||
/**
|
||||
* @brief Calculate score for cleared lines
|
||||
* @param linesCleared Number of lines cleared simultaneously
|
||||
* @param level Current game level
|
||||
* @return Score points to award
|
||||
*/
|
||||
virtual int calculateScore(int linesCleared, int level) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get gravity speed for a given level
|
||||
* @param level Game level
|
||||
* @return Time in milliseconds for one gravity drop
|
||||
*/
|
||||
virtual double getGravitySpeed(int level) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if level should increase
|
||||
* @param totalLines Total lines cleared so far
|
||||
* @param currentLevel Current game level
|
||||
* @return true if level should increase, false otherwise
|
||||
*/
|
||||
virtual bool shouldLevelUp(int totalLines, int currentLevel) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Calculate next level based on lines cleared
|
||||
* @param totalLines Total lines cleared so far
|
||||
* @param startLevel Starting level
|
||||
* @return New level
|
||||
*/
|
||||
virtual int calculateLevel(int totalLines, int startLevel) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get soft drop speed multiplier
|
||||
* @return Multiplier for gravity when soft dropping
|
||||
*/
|
||||
virtual double getSoftDropMultiplier() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get hard drop score per cell
|
||||
* @return Points awarded per cell for hard drop
|
||||
*/
|
||||
virtual int getHardDropScore() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Get soft drop score per cell
|
||||
* @return Points awarded per cell for soft drop
|
||||
*/
|
||||
virtual int getSoftDropScore() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if T-spins are enabled in this rule set
|
||||
* @return true if T-spins are supported, false otherwise
|
||||
*/
|
||||
virtual bool supportsTSpins() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if hold feature is enabled in this rule set
|
||||
* @return true if hold is supported, false otherwise
|
||||
*/
|
||||
virtual bool supportsHold() const = 0;
|
||||
};
|
||||
59
src/core/interfaces/IInputHandler.h
Normal file
59
src/core/interfaces/IInputHandler.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for input handling operations
|
||||
*
|
||||
* Provides a common interface for input processing,
|
||||
* enabling dependency injection and easier testing.
|
||||
*/
|
||||
class IInputHandler {
|
||||
public:
|
||||
virtual ~IInputHandler() = default;
|
||||
|
||||
/**
|
||||
* @brief Process SDL events
|
||||
* @param event SDL event to process
|
||||
* @return true if event was handled, false otherwise
|
||||
*/
|
||||
virtual bool processEvent(const SDL_Event& event) = 0;
|
||||
|
||||
/**
|
||||
* @brief Update input state (called per frame)
|
||||
* @param deltaTime Time elapsed since last frame in milliseconds
|
||||
*/
|
||||
virtual void update(double deltaTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if a key is currently pressed (interface method)
|
||||
* @param scancode SDL scancode of the key
|
||||
* @return true if key is pressed, false otherwise
|
||||
*/
|
||||
virtual bool isKeyCurrentlyPressed(SDL_Scancode scancode) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if a key was just pressed this frame
|
||||
* @param scancode SDL scancode of the key
|
||||
* @return true if key was just pressed, false otherwise
|
||||
*/
|
||||
virtual bool isKeyJustPressed(SDL_Scancode scancode) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if a key was just released this frame
|
||||
* @param scancode SDL scancode of the key
|
||||
* @return true if key was just released, false otherwise
|
||||
*/
|
||||
virtual bool isKeyJustReleased(SDL_Scancode scancode) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if quit was requested (e.g., Alt+F4, window close)
|
||||
* @return true if quit was requested, false otherwise
|
||||
*/
|
||||
virtual bool isQuitRequested() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Reset input state (typically called at frame start)
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
56
src/core/interfaces/IRenderer.h
Normal file
56
src/core/interfaces/IRenderer.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for rendering operations
|
||||
*
|
||||
* Provides a common interface for different rendering implementations,
|
||||
* enabling dependency injection and easier testing.
|
||||
*/
|
||||
class IRenderer {
|
||||
public:
|
||||
virtual ~IRenderer() = default;
|
||||
|
||||
/**
|
||||
* @brief Clear the render target with specified color (interface method)
|
||||
* @param r Red component (0-255)
|
||||
* @param g Green component (0-255)
|
||||
* @param b Blue component (0-255)
|
||||
* @param a Alpha component (0-255)
|
||||
*/
|
||||
virtual void clearScreen(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
|
||||
|
||||
/**
|
||||
* @brief Present the rendered frame to the display
|
||||
*/
|
||||
virtual void present() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the underlying SDL renderer for direct operations
|
||||
* @return Pointer to SDL_Renderer
|
||||
* @note This is provided for compatibility with existing code
|
||||
*/
|
||||
virtual SDL_Renderer* getSDLRenderer() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the current window size (interface method)
|
||||
* @param width Output parameter for window width
|
||||
* @param height Output parameter for window height
|
||||
*/
|
||||
virtual void getWindowDimensions(int& width, int& height) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Set the render viewport
|
||||
* @param viewport Viewport rectangle
|
||||
*/
|
||||
virtual void setViewport(const SDL_Rect* viewport) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set the render scale
|
||||
* @param scaleX Horizontal scale factor
|
||||
* @param scaleY Vertical scale factor
|
||||
*/
|
||||
virtual void setScale(float scaleX, float scaleY) = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user