You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
74 lines
1.9 KiB
#pragma once |
|
#include <SDL2/SDL.h> |
|
#include <vector> |
|
#include <string> |
|
#include "Game.hpp" |
|
#include "Synth.hpp" |
|
|
|
struct Particle { |
|
float x = 0.0f; |
|
float y = 0.0f; |
|
float vx = 0.0f; |
|
float vy = 0.0f; |
|
float life = 1.0f; // 1.0 down to 0.0 |
|
float decay = 1.0f; // decay rate per second |
|
float size = 4.0f; |
|
SDL_Color color = {255, 255, 255, 255}; |
|
}; |
|
|
|
struct Star { |
|
float x = 0.0f; |
|
float y = 0.0f; |
|
float speed = 0.0f; |
|
float size = 0.0f; |
|
float alpha = 0.0f; |
|
}; |
|
|
|
class Renderer { |
|
public: |
|
Renderer(); |
|
~Renderer(); |
|
|
|
bool init(SDL_Renderer* renderer, int targetW, int targetH); |
|
void update(float dt); |
|
|
|
// Master rendering routine |
|
void render(const Game& game, Synth& synth); |
|
|
|
// Spawn effects |
|
void spawnLineClearParticles(const Game& game); |
|
void spawnLandDustParticles(int gridX, int gridY, PieceType type); |
|
|
|
// Screenshot API |
|
void takeScreenshot(const std::string& filename); |
|
|
|
private: |
|
SDL_Renderer* mRenderer = nullptr; |
|
SDL_Texture* mFontTexture = nullptr; |
|
SDL_Surface* mFontSurface = nullptr; |
|
SDL_Surface* mBackbufferSurface = nullptr; |
|
SDL_Surface* mScaledSurface = nullptr; |
|
SDL_Texture* mBackbufferTexture = nullptr; |
|
|
|
int mTargetW = 800; |
|
int mTargetH = 600; |
|
float mTime = 0.0f; |
|
float mShakeIntensity = 0.0f; |
|
|
|
// Drifting starfield |
|
std::vector<Star> mStars; |
|
std::vector<Particle> mParticles; |
|
|
|
void initStars(); |
|
void buildFontTexture(); |
|
|
|
// Drawing helpers |
|
void drawText(const std::string& text, int x, int y, int scale, SDL_Color color, bool center = false, bool glow = false); |
|
void drawBlock(int gridX, int gridY, PieceType type, bool isGhost = false, float alphaOverride = 1.0f); |
|
void drawGrid(const Game& game); |
|
void drawUI(const Game& game); |
|
void drawVisualizer(Synth& synth, int x, int y, int w, int h); |
|
|
|
// Helpers |
|
SDL_Color getPieceColor(PieceType type); |
|
};
|
|
|