Skip to content

Commit

Permalink
Add Into scene, change font
Browse files Browse the repository at this point in the history
  • Loading branch information
feresr committed May 24, 2020
1 parent 5e6436b commit 10a4efe
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 24 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_executable(smb
src/systems/ScoreSystem.cpp
src/scenes/GameScene.cpp
src/scenes/EditorScene.cpp
src/scenes/IntroScene.cpp
)


Expand Down
Binary file modified assets/font.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions include/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions include/scenes/IntroScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "scenes/Scene.h"

class IntroScene : public Scene {

public:
IntroScene(SDL_Window* window);

private:
void update() override;

};
8 changes: 7 additions & 1 deletion include/systems/RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,5 +37,9 @@ class RenderSystem : public System {

void renderText(std::vector<Entity*> entities);

TTF_Font * font;
TTF_Font* font;

int r = SKY_RED;
int g = SKY_GREEN;
int b = SKY_BLUE;
};
10 changes: 6 additions & 4 deletions src/Game.cpp
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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<IntroScene*>(currentScene)) {
SDL_Delay(3000);
delete currentScene;
currentScene = new GameScene(window);
}
}

bool Game::running() const { return isRunning; }
Expand Down
17 changes: 8 additions & 9 deletions src/scenes/EditorScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@ EditorScene::EditorScene(SDL_Window* window) {
world->registerSystem(new PhysicsSystem());


//FIRST COLUMN (left aligned)
auto title = world->create();
title->assign<TextComponent>("MAP EDITOR MODE");
title->assign<TransformComponent>(10, 10, 60, 8);

auto instructions1 = world->create();
instructions1->assign<TextComponent>("up down keys change tiles");
instructions1->assign<TransformComponent>(10, 20, 80, 5);
instructions1->assign<TextComponent>("- Press up/down keys to change tiles");
instructions1->assign<TransformComponent>(10, 20, 92, 5);

auto instructions2 = world->create();
instructions2->assign<TextComponent>("press keys a and d to pan camera");
instructions2->assign<TransformComponent>(10, 26, 90, 5);
instructions2->assign<TextComponent>("- Press keys 'a' and 'd' to pan camera");
instructions2->assign<TransformComponent>(10, 26, 96, 5);

auto instructions3 = world->create();
instructions3->assign<TextComponent>("press s to save the map to disk");
instructions3->assign<TransformComponent>(10, 32, 86, 5);
instructions3->assign<TextComponent>("- Press 's' to save the map to disk");
instructions3->assign<TransformComponent>(10, 32, 90, 5);

auto instructions4 = world->create();
instructions4->assign<TextComponent>("click to add and remove tiles");
instructions4->assign<TextComponent>("- Click to add and remove tiles");
instructions4->assign<TransformComponent>(10, 38, 80, 5);

auto instructions5 = world->create();
instructions5->assign<TextComponent>("press e to exit the editor");
instructions5->assign<TextComponent>("- Press 'e' to exit the editor");
instructions5->assign<TransformComponent>(10, 44, 80, 5);
}

Expand Down
38 changes: 38 additions & 0 deletions src/scenes/IntroScene.cpp
Original file line number Diff line number Diff line change
@@ -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<TextComponent>("WORLD 1-1");
auto width = 72;
worldName->assign<TransformComponent>(SNES_RESOLUTION_WIDTH / 2 - width / 2,
SNES_RESOLUTION_HEIGHT / 2 - 30, width,
8);

auto mario = world->create();
mario->assign<TextureComponent>(TextureId::MARIO_STAND);
mario->assign<TextComponent>("");
mario->assign<TransformComponent>(SNES_RESOLUTION_WIDTH / 2 - TILE_SIZE / 2 - 20, SNES_RESOLUTION_HEIGHT / 2,
TILE_SIZE,
TILE_SIZE);

auto x = world->create();
x->assign<TextComponent>("x");
x->assign<TransformComponent>(SNES_RESOLUTION_WIDTH / 2 - 4, SNES_RESOLUTION_HEIGHT / 2 + 6, 8, 8);

auto three = world->create();
three->assign<TextComponent>("3");
three->assign<TransformComponent>(SNES_RESOLUTION_WIDTH / 2 - 4 + 20, SNES_RESOLUTION_HEIGHT / 2 + 6, 8, 8);
}

void IntroScene::update() {
Scene::update();
world->tick();
}


8 changes: 7 additions & 1 deletion src/systems/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CameraComponent>(GAME_RESOLUTION_WIDTH / 2,
GAME_RESOLUTION_HEIGHT / 2,
GAME_RESOLUTION_WIDTH,
Expand Down Expand Up @@ -110,3 +110,9 @@ void RenderSystem::renderText(std::vector<Entity*> 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;
}
18 changes: 9 additions & 9 deletions src/systems/ScoreSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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;
auto columnWidth = availableWidth / columns;

//FIRST COLUMN (left aligned)
auto marioEntity = world->create();
marioEntity->assign<TextComponent>("mario");
marioEntity->assign<TextComponent>("MARIO");
marioEntity->assign<TransformComponent>(paddingH, paddingV, 40, textHeight);

scoreEntity = world->create();
Expand Down Expand Up @@ -42,25 +42,25 @@ void ScoreSystem::onAddedToWorld(World* world) {
coinIco->assign<TextComponent>("");
coinIco->assign<TransformComponent>(
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<TextComponent>("world");
worldEntity->assign<TextComponent>("WORLD");
w = 40;
worldEntity->assign<TransformComponent>(paddingH + columnWidth * 2 + (columnWidth - w) / 2,
paddingV, w, textHeight);

auto worldNumberEntity = world->create();
worldNumberEntity->assign<TextComponent>("1 1");
w = 20;
worldNumberEntity->assign<TextComponent>("1-1");
w = 24;
worldNumberEntity->assign<TransformComponent>(paddingH + columnWidth * 2 + (columnWidth - w) / 2,
paddingV + textHeight + spacingV, w, textHeight);

// FOURTH COLUMN (right aligned)
auto timeEntity = world->create();
timeEntity->assign<TextComponent>("time");
timeEntity->assign<TextComponent>("TIME");
timeEntity->assign<TransformComponent>(SNES_RESOLUTION_WIDTH - paddingH - 32, paddingV, 32, textHeight);

timeLeftEntity = world->create();
Expand Down

0 comments on commit 10a4efe

Please sign in to comment.