I've always loved making games and using SFML, and up until a few days ago, I've had to re-write code over and over again. So I decided to write a game engine so I can reuse my code.
I've never done something like this before. I've read about it, and I watched a few videos. I'd love if you could look around, give me some ideas. Keep in mind I've only worked on this for less than a week.
So far, I've just re-skinned SFML functions and classes using my own classes, but I've changed some functions around and made things a bit simpler.
Is it, for example, any good creating my own Sprite
class that is basically a re-skin of the SFML sprite
class, with perhaps some added functionality, or should my resource manager just return an SFML sprite
, which the user of the engine can just use all the in-built functionality for the sf::Sprite
?
Here is a very simple program that creates a sprite and a text and draws them on the screen. And we can use WASD to move the sprite.
#include <Tengine2D\ResourceManager.hpp>
#include <Tengine2D\Window.hpp>
#include <Tengine2D\Keyboard.hpp>
#include <Tengine2D\Clock.hpp>
#include <Tengine2D\Text.hpp>
#include <Tengine2D\Vector2.hpp>
#include <Tengine2D\GameState.hpp>
#include <Tengine2D\Camera.hpp>
#include <iostream>
int screenWidth = 1600;
int screenHeight = 640;
t2d::Clock _clock;
t2d::GameState gameState;
int main()
{
t2d::Window _window;
_window.create(screenWidth, screenHeight, "BELLO!");
gameState = t2d::GameState::PLAY;
// Text
t2d::ResourceManager::createText("Text", "Fonts/times.ttf");
t2d::ResourceManager::getText("Text").setCharacterSize(50);
t2d::ResourceManager::getText("Text").setStyle(t2d::TextStyle::Bold);
t2d::ResourceManager::getText("Text").setColor(t2d::Color::Magenta);
t2d::ResourceManager::getText("Text").setPosition(screenWidth / 4.0f, screenHeight / 2.0f);
t2d::ResourceManager::getText("Text").setString("Hello World");
// Sprite
t2d::ResourceManager::createSprite("RedPlayer", "Sprites/RedPlayer.png");
t2d::ResourceManager::getSprite("RedPlayer").setPosition(screenWidth / 4.0f, screenHeight / 2.0f);
while (gameState != t2d::GameState::QUIT)
{
float delta = _clock.restart().asSeconds();
while (_window.pollEvent())
{
if(t2d::Keyboard::keyPressed(t2d::Keyboard::Escape))
{
gameState = t2d::GameState::QUIT;
}
}
if (t2d::Keyboard::isKeyPressed(t2d::Keyboard::D))
{
t2d::ResourceManager::getSprite("RedPlayer").translate(400 * delta, 0.0f);
}
if (t2d::Keyboard::isKeyPressed(t2d::Keyboard::A))
{
t2d::ResourceManager::getSprite("RedPlayer").translate(-400 * delta, 0.0f);
}
if (t2d::Keyboard::isKeyPressed(t2d::Keyboard::S))
{
t2d::ResourceManager::getSprite("RedPlayer").translate(0.0f, 400 * delta);
}
if (t2d::Keyboard::isKeyPressed(t2d::Keyboard::W))
{
t2d::ResourceManager::getSprite("RedPlayer").translate(0.0f, -400 * delta);
}
_window.clear(t2d::Color(150, 150, 5, 255));
_window.draw(t2d::ResourceManager::getSprite("RedPlayer"));
_window.draw(t2d::ResourceManager::getText("Text"));
_window.display();
}
return 0;
}