diff --git a/CMakeLists.txt b/CMakeLists.txt index c7babe0..fa5b8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ add_executable(smb src/systems/ScoreSystem.cpp src/scenes/GameScene.cpp src/scenes/EditorScene.cpp + src/scenes/IntroScene.cpp ) diff --git a/assets/font.ttf b/assets/font.ttf index 408784e..6ce26eb 100644 Binary files a/assets/font.ttf and b/assets/font.ttf differ diff --git a/include/Game.h b/include/Game.h index eed3719..e9e76f2 100644 --- a/include/Game.h +++ b/include/Game.h @@ -6,6 +6,7 @@ #include "ecs/ecs.h" #include "scenes/GameScene.h" #include "scenes/EditorScene.h" +#include "scenes/IntroScene.h" #include "Constants.h" class Game { diff --git a/include/scenes/IntroScene.h b/include/scenes/IntroScene.h new file mode 100644 index 0000000..047e1ce --- /dev/null +++ b/include/scenes/IntroScene.h @@ -0,0 +1,11 @@ +#include "scenes/Scene.h" + +class IntroScene : public Scene { + +public: + IntroScene(SDL_Window* window); + +private: + void update() override; + +}; \ No newline at end of file diff --git a/include/systems/RenderSystem.h b/include/systems/RenderSystem.h index cb66228..bbc9294 100644 --- a/include/systems/RenderSystem.h +++ b/include/systems/RenderSystem.h @@ -17,6 +17,8 @@ class RenderSystem : public System { void onAddedToWorld(World* world) override; + void setBackgroundColor(int r, int g, int b); + void tick(World* world) override; void onRemovedFromWorld(World* world) override; @@ -35,5 +37,9 @@ class RenderSystem : public System { void renderText(std::vector entities); - TTF_Font * font; + TTF_Font* font; + + int r = SKY_RED; + int g = SKY_GREEN; + int b = SKY_BLUE; }; diff --git a/src/Game.cpp b/src/Game.cpp index 38a875b..0f8169a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,8 +1,6 @@ #include "Game.h" -bool restartGame = false; - void Game::init(const char* title, int width, int height, bool fullscreen) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) { SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); @@ -19,13 +17,17 @@ void Game::init(const char* title, int width, int height, bool fullscreen) { } isRunning = true; - currentScene = new GameScene(window); + currentScene = new IntroScene(window); } void Game::update() { currentScene->update(); - if (restartGame) {} + if (dynamic_cast(currentScene)) { + SDL_Delay(3000); + delete currentScene; + currentScene = new GameScene(window); + } } bool Game::running() const { return isRunning; } diff --git a/src/scenes/EditorScene.cpp b/src/scenes/EditorScene.cpp index abe189d..4c70561 100644 --- a/src/scenes/EditorScene.cpp +++ b/src/scenes/EditorScene.cpp @@ -8,29 +8,28 @@ EditorScene::EditorScene(SDL_Window* window) { world->registerSystem(new PhysicsSystem()); - //FIRST COLUMN (left aligned) auto title = world->create(); title->assign("MAP EDITOR MODE"); title->assign(10, 10, 60, 8); auto instructions1 = world->create(); - instructions1->assign("up down keys change tiles"); - instructions1->assign(10, 20, 80, 5); + instructions1->assign("- Press up/down keys to change tiles"); + instructions1->assign(10, 20, 92, 5); auto instructions2 = world->create(); - instructions2->assign("press keys a and d to pan camera"); - instructions2->assign(10, 26, 90, 5); + instructions2->assign("- Press keys 'a' and 'd' to pan camera"); + instructions2->assign(10, 26, 96, 5); auto instructions3 = world->create(); - instructions3->assign("press s to save the map to disk"); - instructions3->assign(10, 32, 86, 5); + instructions3->assign("- Press 's' to save the map to disk"); + instructions3->assign(10, 32, 90, 5); auto instructions4 = world->create(); - instructions4->assign("click to add and remove tiles"); + instructions4->assign("- Click to add and remove tiles"); instructions4->assign(10, 38, 80, 5); auto instructions5 = world->create(); - instructions5->assign("press e to exit the editor"); + instructions5->assign("- Press 'e' to exit the editor"); instructions5->assign(10, 44, 80, 5); } diff --git a/src/scenes/IntroScene.cpp b/src/scenes/IntroScene.cpp new file mode 100644 index 0000000..a7dfa29 --- /dev/null +++ b/src/scenes/IntroScene.cpp @@ -0,0 +1,38 @@ +#include "scenes/IntroScene.h" + +IntroScene::IntroScene(SDL_Window* window) { + world = new World(); + auto renderSystem = new RenderSystem(window, SNES_RESOLUTION_WIDTH, SNES_RESOLUTION_HEIGHT); + renderSystem->setBackgroundColor(0, 0, 0); + world->registerSystem(renderSystem); + world->registerSystem(new ScoreSystem()); + + auto worldName = world->create(); + worldName->assign("WORLD 1-1"); + auto width = 72; + worldName->assign(SNES_RESOLUTION_WIDTH / 2 - width / 2, + SNES_RESOLUTION_HEIGHT / 2 - 30, width, + 8); + + auto mario = world->create(); + mario->assign(TextureId::MARIO_STAND); + mario->assign(""); + mario->assign(SNES_RESOLUTION_WIDTH / 2 - TILE_SIZE / 2 - 20, SNES_RESOLUTION_HEIGHT / 2, + TILE_SIZE, + TILE_SIZE); + + auto x = world->create(); + x->assign("x"); + x->assign(SNES_RESOLUTION_WIDTH / 2 - 4, SNES_RESOLUTION_HEIGHT / 2 + 6, 8, 8); + + auto three = world->create(); + three->assign("3"); + three->assign(SNES_RESOLUTION_WIDTH / 2 - 4 + 20, SNES_RESOLUTION_HEIGHT / 2 + 6, 8, 8); +} + +void IntroScene::update() { + Scene::update(); + world->tick(); +} + + diff --git a/src/systems/RenderSystem.cpp b/src/systems/RenderSystem.cpp index 0ba34b5..b83cf4b 100644 --- a/src/systems/RenderSystem.cpp +++ b/src/systems/RenderSystem.cpp @@ -32,7 +32,7 @@ void RenderSystem::tick(World* world) { void RenderSystem::onAddedToWorld(World* world) { auto* entity = world->create(); - SDL_SetRenderDrawColor(renderer, SKY_RED, SKY_GREEN, SKY_BLUE, 255); + SDL_SetRenderDrawColor(renderer, r, g, b, 255); entity->assign(GAME_RESOLUTION_WIDTH / 2, GAME_RESOLUTION_HEIGHT / 2, GAME_RESOLUTION_WIDTH, @@ -110,3 +110,9 @@ void RenderSystem::renderText(std::vector entities) { SDL_RenderCopy(renderer, textComponent->texture, NULL, &dstRect); } } + +void RenderSystem::setBackgroundColor(int r, int g, int b) { + this->r = r; + this->g = g; + this->b = b; +} diff --git a/src/systems/ScoreSystem.cpp b/src/systems/ScoreSystem.cpp index fc5ac3d..e01096a 100644 --- a/src/systems/ScoreSystem.cpp +++ b/src/systems/ScoreSystem.cpp @@ -4,9 +4,9 @@ void ScoreSystem::onAddedToWorld(World* world) { System::onAddedToWorld(world); auto paddingH = 22; - auto paddingV = 12; - auto textHeight = 10; - auto spacingV = -3; + auto paddingV = 16; + auto textHeight = 8; + auto spacingV = -0; auto availableWidth = SNES_RESOLUTION_WIDTH - paddingH * 2; auto columns = 4; @@ -14,7 +14,7 @@ void ScoreSystem::onAddedToWorld(World* world) { //FIRST COLUMN (left aligned) auto marioEntity = world->create(); - marioEntity->assign("mario"); + marioEntity->assign("MARIO"); marioEntity->assign(paddingH, paddingV, 40, textHeight); scoreEntity = world->create(); @@ -42,25 +42,25 @@ void ScoreSystem::onAddedToWorld(World* world) { coinIco->assign(""); coinIco->assign( paddingH + columnWidth + (columnWidth - w) / 2 - 4, - paddingV + textHeight + spacingV + 1, 5, 8 + paddingV + textHeight + spacingV, 5, 8 ); // THIRD COLUMN (center aligned) auto worldEntity = world->create(); - worldEntity->assign("world"); + worldEntity->assign("WORLD"); w = 40; worldEntity->assign(paddingH + columnWidth * 2 + (columnWidth - w) / 2, paddingV, w, textHeight); auto worldNumberEntity = world->create(); - worldNumberEntity->assign("1 1"); - w = 20; + worldNumberEntity->assign("1-1"); + w = 24; worldNumberEntity->assign(paddingH + columnWidth * 2 + (columnWidth - w) / 2, paddingV + textHeight + spacingV, w, textHeight); // FOURTH COLUMN (right aligned) auto timeEntity = world->create(); - timeEntity->assign("time"); + timeEntity->assign("TIME"); timeEntity->assign(SNES_RESOLUTION_WIDTH - paddingH - 32, paddingV, 32, textHeight); timeLeftEntity = world->create();