Skip to content

Commit

Permalink
Moved the Random functions into the engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfos committed Jan 1, 2018
1 parent d8df7d0 commit b3e735e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
28 changes: 5 additions & 23 deletions Code/Test/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#include "../WolfEngine/WolfEngine.h"
#include "../WolfEngine/API.h"
#include <vector>
#include <random>

float RandomRange(float start, float end)
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_real_distribution<float> distribution(start, end);
return distribution(eng);
}

int RandomRange(int start, int end)
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution<int> distribution(start, end);
return distribution(eng);
}

class Animal : public Component
{
Expand All @@ -28,12 +10,12 @@ class Animal : public Component
sr->Load("Animals.png");
sr->frameWidth = 286;
sr->frameHeight = 286;
sr->frame = RandomRange(0, 9);
sr->frame = WolfEngine::RandomRange(0, 9);

float randomScale = RandomRange(.1f, .5f);
float randomAngle = RandomRange(0.0f, 360.0f);
int randomX = RandomRange(0, WolfEngine::screenWidth);
int randomY = RandomRange(0, WolfEngine::screenHeight);
float randomScale = WolfEngine::RandomRange(.1f, .5f);
float randomAngle = WolfEngine::RandomRange(0.0f, 360.0f);
int randomX = WolfEngine::RandomRange(0, WolfEngine::screenWidth);
int randomY = WolfEngine::RandomRange(0, WolfEngine::screenHeight);
gameObject->transform->scale = {randomScale, randomScale};
gameObject->transform->angle = randomAngle;
gameObject->transform->localPosition = {randomX, randomY};
Expand Down
1 change: 1 addition & 0 deletions Code/WolfEngine/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Rendering/Map.h"
#include "Utilities/Collision.h"
#include "Utilities/Debug.h"
#include "Utilities/Random.h"
#include "Utilities/Time.h"
#include "Utilities/WolfMath.h"

Expand Down
30 changes: 30 additions & 0 deletions Code/WolfEngine/Utilities/Random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Created by Robin on 01/01/2018.
//

#include "Random.h"
#include <random>

float WolfEngine::RandomRange(float min, float max)
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_real_distribution<float> distribution(min, max);
return distribution(eng);
}

double WolfEngine::RandomRange(double min, double max)
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_real_distribution<double> distribution(min, max);
return distribution(eng);
}

int WolfEngine::RandomRange(int min, int max)
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution<int> distribution(min, max);
return distribution(eng);
}
12 changes: 12 additions & 0 deletions Code/WolfEngine/Utilities/Random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by Robin on 01/01/2018.
//

#pragma once

namespace WolfEngine
{
float RandomRange(float min, float max);
double RandomRange(double min, double max);
int RandomRange(int min, int max);
}
1 change: 1 addition & 0 deletions Code/WolfEngine/WolfEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ namespace WolfEngine
extern int Quit();

// Utility functions
/// Get the path to the 'Assets' folder
extern std::string FindAssetFolder();
};

0 comments on commit b3e735e

Please sign in to comment.