init
This commit is contained in:
50
demo/DemoScene.h
Normal file
50
demo/DemoScene.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "hd2d/Camera.h"
|
||||
#include "hd2d/Scene.h"
|
||||
#include "hd2d/Weather.h"
|
||||
|
||||
#include <array>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
// Meadow diorama: terraced grass, a cliff ridge with steps, a pond crossed by
|
||||
// a stone bridge with burning braziers, 3D trees/bushes/rocks, weather and a
|
||||
// WASD-controlled pixel-art player sprite.
|
||||
class DemoScene {
|
||||
public:
|
||||
bool load(const std::string& assetDir);
|
||||
// `move`: x = screen right, y = screen up (camera-relative), length <= 1.
|
||||
void update(float dt, float time, glm::vec2 move, const hd2d::Camera& camera);
|
||||
void placePlayer(glm::vec2 xz);
|
||||
|
||||
hd2d::Scene scene;
|
||||
glm::vec3 playerPos{0.0f};
|
||||
hd2d::Weather weather; // call weather.update() each frame before rendering
|
||||
|
||||
private:
|
||||
struct Obstacle {
|
||||
glm::vec2 pos;
|
||||
float radius;
|
||||
};
|
||||
void buildTerrain();
|
||||
void scatterProps();
|
||||
bool walkable(glm::vec2 from, glm::vec2 to) const;
|
||||
bool occupied(glm::vec2 p, float r) const;
|
||||
float groundHeight(glm::vec2 p) const; // terrain or bridge deck
|
||||
|
||||
hd2d::Terrain terrain_;
|
||||
hd2d::Water water_;
|
||||
hd2d::ParticleSystem particles_;
|
||||
hd2d::BillboardBatch tallGrass_, tufts_, flowers_, player_; // pixel-art sprites
|
||||
hd2d::ModelLibrary models_; // 3D scenery
|
||||
std::array<hd2d::ModelBatch, 2> oaks_, pines_, bushes_, rocks_; // two model variants each
|
||||
hd2d::ModelBatch bridge_;
|
||||
hd2d::GroundOcclusion groundAO_;
|
||||
std::vector<Obstacle> obstacles_;
|
||||
std::vector<unsigned char> tallGrassMask_;
|
||||
std::mt19937 rng_{42};
|
||||
float playerSpeed_ = 4.2f;
|
||||
float walkPhase_ = 0.0f;
|
||||
float stepTimer_ = 0.0f;
|
||||
float facing_ = 0.0f;
|
||||
};
|
||||
Reference in New Issue
Block a user