Skip to content

Commit

Permalink
Create World 1-1
Browse files Browse the repository at this point in the history
  • Loading branch information
feresr committed May 23, 2020
1 parent 9086817 commit bc82ce5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
Binary file modified assets/map-generated
Binary file not shown.
4 changes: 2 additions & 2 deletions include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ constexpr int SNES_RESOLUTION_WIDTH = 256;
constexpr int SNES_RESOLUTION_HEIGHT = 224;

constexpr int TILE_SIZE = 16;
constexpr int MAP_WIDTH = 100;
constexpr int MAP_HEIGHT = 14;
constexpr int DEFAULT_MAP_WIDTH = 230;
constexpr int DEFAULT_MAP_HEIGHT = 14;

constexpr int SKY_RED = 90;
constexpr int SKY_GREEN = 147;
Expand Down
2 changes: 1 addition & 1 deletion include/systems/EditorSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct InputState {
class EditorSystem : public System {

public:
explicit EditorSystem() = default;
explicit EditorSystem();

void onAddedToWorld(World* world) override;

Expand Down
24 changes: 23 additions & 1 deletion src/systems/EditorSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@ void EditorSystem::onAddedToWorld(World* world) {
SDL_AddEventWatch(InputWatcher, &inputState);

auto* entity = world->create();
entity->assign<TileSetComponent>(MAP_WIDTH, MAP_HEIGHT);
entity->assign<TileSetComponent>(DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT);
tileSet = entity->get<TileSetComponent>();

cursor = world->create();
cursor->assign<TextureComponent>(TextureId::EMPTY);
cursor->assign<TileComponent>();
cursor->assign<TransformComponent>(0, 0, TILE_SIZE, TILE_SIZE);

//Load current map
std::ifstream infile("assets/map-generated", std::ios::out | std::ios::binary);
if (infile) {
int mw;
int mh;
infile.read(reinterpret_cast<char*>(&mw), sizeof(uint16_t));
infile.read(reinterpret_cast<char*>(&mh), sizeof(uint16_t));
TileType texture;

for (int x = 0; x < DEFAULT_MAP_WIDTH; x++) {
for (int y = 0; y < DEFAULT_MAP_HEIGHT; y++) {
infile.read(reinterpret_cast<char*>(&texture), sizeof(TileType));
tileSet->set(x, y, texture);
}
}
infile.close();
}
}

void EditorSystem::onRemovedFromWorld(World* world) {
Expand Down Expand Up @@ -68,6 +86,10 @@ void EditorSystem::saveToDisk() {
outfile.close();
}

EditorSystem::EditorSystem() {

}


int InputWatcher(void* userData, SDL_Event* event) {
auto* m = (InputState*) userData;
Expand Down
2 changes: 1 addition & 1 deletion src/systems/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void RenderSystem::onAddedToWorld(World* world) {

TTF_Init();
font = TTF_OpenFont("assets/font.ttf", 25);
TTF_SetFontKerning(font, 0);
TTF_SetFontKerning(font, 1);
}

void RenderSystem::onRemovedFromWorld(World* world) {
Expand Down

0 comments on commit bc82ce5

Please sign in to comment.