Move through course, sprite and input
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
@@ -1,20 +1,42 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "framework/Core.h"
|
||||
#include "framework/Object.h"
|
||||
#include "framework/AssetManager.h"
|
||||
|
||||
class World;
|
||||
|
||||
namespace ly {
|
||||
class World;
|
||||
|
||||
class Actor {
|
||||
class Actor : public Object {
|
||||
public:
|
||||
Actor(World *owningWorld);
|
||||
Actor(World *owningWorld, const std::string& texturePath = "");
|
||||
virtual ~Actor();
|
||||
|
||||
void BeginPlayInternal();
|
||||
virtual void BeginPlay();
|
||||
void TickInternal(float deltaTime);
|
||||
virtual void Tick(float deltaTime);
|
||||
void SetTexture(const std::string& texturePath);
|
||||
void Render(sf::RenderWindow& window);
|
||||
|
||||
void SetActorLocation(const sf::Vector2f &newLocation);
|
||||
void SetActorRotation(const float newRotation);
|
||||
void AddActorLocationOffset(const sf::Vector2f& offset);
|
||||
void AddActorRotationOffset(const float offset);
|
||||
sf::Vector2f GetActorLocation() const;
|
||||
float GetActorRotation() const;
|
||||
sf::Vector2f GetActorForwardDirection() const;
|
||||
sf::Vector2f GetActorRightDirection() const;
|
||||
|
||||
|
||||
private:
|
||||
void CenterPivot();
|
||||
World *mOwningWorld;
|
||||
bool mHasBeganPlay;
|
||||
|
||||
sf::Sprite mSprite;
|
||||
shared<sf::Texture> mTexture;
|
||||
};
|
||||
|
||||
} // namespace ly
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace ly {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
Application(unsigned int windowWidth, unsigned int windowHeight, const std::string& title, sf::Uint32 style);
|
||||
void Run();
|
||||
|
||||
template <typename WorldType>
|
||||
@@ -24,6 +24,9 @@ private:
|
||||
float mTargetFrameRate;
|
||||
sf::Clock mTickClock;
|
||||
|
||||
sf::Clock mCleanCycleClock;
|
||||
float mCleanCycleInterval;
|
||||
|
||||
shared<World> currentWorld;
|
||||
};
|
||||
|
||||
|
||||
22
LightYearsEngine/include/framework/AssetManager.h
Normal file
22
LightYearsEngine/include/framework/AssetManager.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "framework/Core.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
namespace ly {
|
||||
class AssetManager {
|
||||
public:
|
||||
static AssetManager& Get();
|
||||
shared<sf::Texture> LoadTexture(const std::string& path);
|
||||
void CleanCycle();
|
||||
void SetAssetRootDirectory(const std::string& directory);
|
||||
|
||||
protected:
|
||||
AssetManager();
|
||||
|
||||
private:
|
||||
static unique<AssetManager> assetManager;
|
||||
Dictionary<std::string, shared<sf::Texture>> mLoadedTextureMap;
|
||||
std::string mRootDirectory;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -23,7 +23,7 @@ template<typename keyType, typename valueType, typename Pr = std::less<keyType>>
|
||||
using Map = std::map<keyType, valueType, Pr>;
|
||||
|
||||
template<typename keyType, typename valueType, typename Hasher = std::hash<keyType>>
|
||||
using Dictionary = std::map<keyType, valueType, Hasher>;
|
||||
using Dictionary = std::unordered_map<keyType, valueType, Hasher>;
|
||||
|
||||
// Logging Macro
|
||||
#define LOG(M, ...) printf(M "\n", ##__VA_ARGS__)
|
||||
|
||||
29
LightYearsEngine/include/framework/MathUtility.h
Normal file
29
LightYearsEngine/include/framework/MathUtility.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
namespace ly {
|
||||
sf::Vector2f RotationToVector(float rotation);
|
||||
float DegreesToRadians(float degrees);
|
||||
float RadiansToDegrees(float radians);
|
||||
|
||||
template<typename T>
|
||||
float GetVectorLength(const sf::Vector2<T>& vector) {
|
||||
return std::sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sf::Vector2<T>& ScaleVector(sf::Vector2<T>& vectorToScale, float scaleAmount) {
|
||||
vectorToScale.x *= scaleAmount;
|
||||
vectorToScale.y *= scaleAmount;
|
||||
return vectorToScale;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sf::Vector2<T>& Normalize(sf::Vector2<T> &vector) {
|
||||
float vectorLength = GetVectorLength<T>(vector);
|
||||
if (vectorLength == 0.f) return sf::Vector2<T>{};
|
||||
|
||||
ScaleVector(vector, 1.f/vectorLength);
|
||||
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
15
LightYearsEngine/include/framework/Object.h
Normal file
15
LightYearsEngine/include/framework/Object.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
namespace ly{
|
||||
class Object {
|
||||
public:
|
||||
Object();
|
||||
virtual ~Object();
|
||||
|
||||
void Destroy();
|
||||
bool IsPendingDestroy() const { return mIsPendingDestroy; };
|
||||
|
||||
private:
|
||||
bool mIsPendingDestroy;
|
||||
};
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "framework/Core.h"
|
||||
class Application;
|
||||
class Actor;
|
||||
#include "framework/Actor.h"
|
||||
|
||||
|
||||
namespace ly {
|
||||
|
||||
class World {
|
||||
class Application;
|
||||
|
||||
class World {
|
||||
public:
|
||||
World(Application *owningApp);
|
||||
|
||||
void BeginPlayInternal();
|
||||
void TickInternal(float deltaTime);
|
||||
void Render(sf::RenderWindow& window);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
template <typename ActorType>
|
||||
weak<ActorType> SpawnActor() {
|
||||
shared<ActorType> newActor{new ActorType{this}};
|
||||
mPendingActors.push_back(newActor);
|
||||
return newActor;
|
||||
}
|
||||
weak<ActorType> SpawnActor();
|
||||
|
||||
private:
|
||||
void BeginPlay();
|
||||
@@ -30,4 +29,14 @@ private:
|
||||
List<shared<Actor>> mActors;
|
||||
List<shared<Actor>> mPendingActors;
|
||||
};
|
||||
|
||||
template<typename ActorType>
|
||||
weak<ActorType> World::SpawnActor()
|
||||
{
|
||||
|
||||
shared<ActorType> newActor{ new ActorType(this)};
|
||||
mPendingActors.push_back(newActor);
|
||||
return newActor;
|
||||
|
||||
}
|
||||
} // namespace ly
|
||||
|
||||
Reference in New Issue
Block a user