Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

Debug/
packages/
**/out/**
SampleGame/out/
55 changes: 55 additions & 0 deletions RedEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
project(RedEngine)

# raylib
find_package(raylib QUIET)
if (NOT raylib_FOUND)
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG b6c8d343dca2ef19c23c50975328a028124cf3cb
)
FetchContent_GetProperties(raylib)
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO)
FetchContent_Populate(raylib)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
endif()
endif()

# raylib-cpp
find_package(raylib-cpp QUIET)
if (NOT raylib-cpp_FOUND)
include(FetchContent)
FetchContent_Declare(
raylib-cpp
URL https://github.com/RobLoach/raylib-cpp/archive/master.tar.gz
)
FetchContent_GetProperties(raylib-cpp)
if (NOT raylib-cpp_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO)
FetchContent_Populate(raylib-cpp)
set(BUILD_RAYLIB_CPP_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_subdirectory(${raylib-cpp_SOURCE_DIR} ${raylib-cpp_BINARY_DIR})
endif()
endif()

# RedLib
find_library(RedLib RedLib)
add_subdirectory(../RedLib ../RedLib-build)

include_directories("Header Files" "../RedLib/Header Files")

# This is the main part:
set(PROJECT_NAME RedEngine)
set(PROJECT_SOURCES "Source Files/Animation.cpp" "Source Files/AnimationData.cpp" "Source Files/AnimationManager.cpp" "Source Files/Color.cpp" "Source Files/Event.cpp" "Source Files/EventListener.cpp" "Source Files/EventSystem.cpp" "Source Files/KeyboardEvent.cpp" "Source Files/MouseEvent.cpp" "Source Files/GraphicsBuffer.cpp" "Source Files/GraphicsBufferManager.cpp" "Source Files/GraphicsSystem.cpp" "Source Files/InputSystem.cpp" "Source Files/Sprite.cpp" "Source Files/Camera2D.cpp")
add_library(${PROJECT_NAME} ${PROJECT_SOURCES})
set(raylib_VERBOSE 1)
target_include_directories(RedEngine PUBLIC ../RedLib ../RedLib-build)
target_link_libraries(${PROJECT_NAME} PUBLIC raylib RedLib)
# That's it! You should have an example executable that you can run. Have fun!
31 changes: 31 additions & 0 deletions RedEngine/Header Files/Animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "Trackable.h"
#include <vector>

class Sprite;
class GraphicsBuffer;
class AnimationData;

class Animation : public Trackable
{

public:
friend class AnimationManager;

void update(double deltaTime);

Sprite* getCurrentSprite();

private:
Animation() = delete;
Animation(AnimationData* data, int fps);
~Animation();

AnimationData* mAnimData;
int mCurrentFrame;

int mFPS;
double mTimePerFrame;
double mTimer;

};
25 changes: 25 additions & 0 deletions RedEngine/Header Files/AnimationData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "Trackable.h"
#include <vector>

class Sprite;
class GraphicsBuffer;

class AnimationData : public Trackable
{

public:
friend class AnimationManager;

Sprite* getSprite(int index);
int getFrameCount() { return mSprites.size(); }

private:
AnimationData() = delete;
AnimationData(Sprite* frames, int numOfFrames);
AnimationData(GraphicsBuffer* gb, int rows, int columns, float scale = 1.0f);
~AnimationData();

std::vector<Sprite*> mSprites;
bool mOwnsSprites;

};
52 changes: 52 additions & 0 deletions RedEngine/Header Files/AnimationManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "Trackable.h"
#include <vector>
#include <unordered_map>
#include <string>

class Animation;
class AnimationData;
class Sprite;
class GraphicsBuffer;

class AnimationManager : public Trackable
{

public:
AnimationManager();
~AnimationManager();

int getNumOfAnimations() { return mAnimations.size(); }
int getNumOfAnimData() { return mAnimData.size(); }

Animation* createAnimation(AnimationData* data, int fps);
Animation* createAndManageAnimation(AnimationData* data, int fps);

AnimationData* createAnimationData(Sprite* frames, int numOfFrames);
AnimationData* createAnimationData(GraphicsBuffer* gb, int rows, int columns, float scale = 1.0f);
AnimationData* createAndManageAnimationData(std::string key, Sprite* frames, int numOfFrames);
AnimationData* createAndManageAnimationData(std::string key, GraphicsBuffer* gb, int rows, int columns, float scale = 1.0f);

void addAnimation(Animation* anim);
void removeAnimation(Animation* anim);
void removeAndDeleteAnimation(Animation* anim);
void deleteAnimation(Animation* anim);

void addAnimationData(std::string key, AnimationData* data);
void removeAnimationData(std::string key);
void removeAndDeleteAnimationData(std::string key);
void deleteAnimationData(AnimationData* data);

int findAnimation(Animation* anim);
Animation* getAnimationAt(int index);

std::string findAnimationDataKey(AnimationData* data);
AnimationData* getAnimationData(std::string key);

void update(float deltaTime);

void clear();

private:
std::vector<Animation*> mAnimations;
std::unordered_map<std::string, AnimationData*> mAnimData;
};
21 changes: 21 additions & 0 deletions RedEngine/Header Files/Camera2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Trackable.h"
#include "Vector2D.h"

class RCamera2D : public Trackable
{

public:
RCamera2D();
RCamera2D(Vector2D location);
~RCamera2D();

void setLoc(Vector2D location) { mLoc = location; }

Vector2D getLoc() { return mLoc; }

private:
Vector2D mLoc;

};
24 changes: 24 additions & 0 deletions RedEngine/Header Files/Color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "LibraryIncludes.h"
#include "Trackable.h"

const int MAX_COLOR_VALUE = 255;

class RColor : public Trackable
{

public:
friend class GraphicsSystem;

RColor();
~RColor();
RColor(int, int, int, int);
RColor(float, float, float, float);

private:
int mR, mG, mB, mA;

raylib::Color getRayColor();

};
28 changes: 28 additions & 0 deletions RedEngine/Header Files/Event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "Trackable.h"

enum EventType
{
INVALID_EVENT_TYPE = -1,
KEYBOARD_EVENT,
MOUSE_ACTION_EVENT,
PLAYER_MOVE_EVENT,
NUM_EVENT_TYPES
};

class Event : public Trackable
{

public:
Event(EventType);
virtual ~Event();

EventType getType() const { return mType; }

private:
Event() = delete;

EventType mType;

};
16 changes: 16 additions & 0 deletions RedEngine/Header Files/EventListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Trackable.h"

class Event;

class EventListener : public Trackable
{

public:
EventListener();
virtual ~EventListener();

virtual void handleEvent(const Event&) = 0;

};
28 changes: 28 additions & 0 deletions RedEngine/Header Files/EventSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "Trackable.h"
#include "Event.h"
#include <map>

class EventListener;

class EventSystem : public Trackable
{

public:
static void cleanupInstance();
static EventSystem* getInstance();

void addListener(EventType, EventListener*);
bool removeListener(EventType, EventListener*);
void removeListenerFromAllEvents(EventListener*);
void fireEvent(const Event&);

private:
EventSystem();
~EventSystem();

static EventSystem* mspInstance;
std::multimap<EventType, EventListener*> mListenerMap;

};
27 changes: 27 additions & 0 deletions RedEngine/Header Files/GraphicsBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "LibraryIncludes.h"
#include "Trackable.h"
#include "Vector2D.h"

class GraphicsBuffer : public Trackable
{
public:
friend class GraphicsSystem;
friend class GraphicsBufferManager;

void loadFromFile(std::string filename);

void unload();

int getWidth() { return mWidth; }
int getHeight() { return mHeight; }

private:
GraphicsBuffer() = delete;
GraphicsBuffer(std::string filename);
~GraphicsBuffer();

raylib::Texture* mTexture;
int mWidth, mHeight;

};
31 changes: 31 additions & 0 deletions RedEngine/Header Files/GraphicsBufferManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Trackable.h"
#include <unordered_map>

class GraphicsBuffer;

class GraphicsBufferManager : public Trackable
{

public:
GraphicsBufferManager();
~GraphicsBufferManager();

int getNumOfGraphicsBuffers() { return mGraphicsBuffers.size(); }

GraphicsBuffer* createGraphicsBuffer(std::string filename);
GraphicsBuffer* createAndManageGraphicsBuffer(std::string key, std::string filename);

void addGraphicsBuffer(std::string key, GraphicsBuffer* gb);
void removeGraphicsBuffer(std::string key);
void removeAndDeleteGraphicsBuffer(std::string key);
void deleteGraphicsBuffer(GraphicsBuffer* gb);

std::string findGraphicsBufferKey(GraphicsBuffer* gb);
GraphicsBuffer* getGraphicsBuffer(std::string key);

void clear();

private:
std::unordered_map<std::string, GraphicsBuffer*> mGraphicsBuffers;

};
Loading