diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-18 15:48:14 +0200 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-18 15:48:14 +0200 | 
| commit | d8289105193707daede1a5b59137f18e20f20aeb (patch) | |
| tree | 939908b9c4c6f7aaef8aa61ee2e04be3e85610b6 /CreateArtistTileBehavior.cpp | |
| parent | 76e61d68bbf568ec0d7fc4632e52d4de5496b003 (diff) | |
(2/2) rename
Diffstat (limited to 'CreateArtistTileBehavior.cpp')
| -rw-r--r-- | CreateArtistTileBehavior.cpp | 46 | 
1 files changed, 46 insertions, 0 deletions
diff --git a/CreateArtistTileBehavior.cpp b/CreateArtistTileBehavior.cpp new file mode 100644 index 0000000..ae0cd7c --- /dev/null +++ b/CreateArtistTileBehavior.cpp @@ -0,0 +1,46 @@ +#include <memory> +#include <random> + +#include "CreateArtistTileBehavior.h" +#include "StepTileBehavior.h" +#include "Tile.h" +#include "Museum.h" + +using std::uniform_int_distribution; +using std::uniform_real_distribution; +using std::random_device; +using std::mt19937; +using namespace std; + +CreateArtistTileBehavior CreateArtistTileBehavior::instance { CreateArtistTileBehavior::type }; + +random_device dev{}; +mt19937 rng(dev()); +uniform_int_distribution<int> random_bool(0, 1); +uniform_real_distribution<float> random_float(-1, 1); + +void CreateArtistTileBehavior::update(Tile & tile) { +	unsigned int new_artists = this->interactions - this->last_interactions; +	this->last_interactions = this->interactions; + +	for (unsigned int i = 0; i < new_artists; i++) { +		if (i >= 2) break; +		ArtistData new_data = { +			.x = static_cast<float>(tile.data.x), +			.y = static_cast<float>(tile.data.y), +		}; +		float velocity = random_float(rng); +		random_bool(rng) ? new_data.vx = velocity : new_data.vy = velocity; +		this->museum->people.add_artist(new_data); +	} + +	if (this->interactions < 2) return; +	tile.set_type(StepTileBehavior::type); +} + +unique_ptr<TileBehavior> CreateArtistTileBehavior::clone(Museum & museum) { +	auto instance = new CreateArtistTileBehavior(); +	instance->museum = &museum; +	return unique_ptr<TileBehavior>(instance); +} +  |