Browse Source

air

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
d9a4bd8b8f

BIN
core.mod/assets-src/tiles/air.xcf View File


BIN
core.mod/assets/tiles/air.png View File


+ 1
- 0
core.mod/src/mod.cc View File

@@ -4,6 +4,7 @@
extern "C" void mod_init(Swan::Mod &mod) {
mod.init("core");

mod.registerTile("air", "assets/tiles/air.png");
mod.registerTile("stone", "assets/tiles/stone.png");
mod.registerTile("dirt", "assets/tiles/dirt.png");
mod.registerTile("grass", "assets/tiles/grass.png");

+ 1
- 0
libswan/CMakeLists.txt View File

@@ -1,5 +1,6 @@
include_directories("${CMAKE_CURRENT_LIST_DIR}/include/swan")
add_library(libswan SHARED
src/Chunk.cc
src/Body.cc
src/Game.cc
src/Mod.cc

+ 6
- 18
libswan/include/swan/Chunk.h View File

@@ -28,30 +28,18 @@ public:
drawBlock(tmap, x, y, id);
}

void drawBlock(TileMap &tmap, int x, int y, Tile::TileID id) {
Tile *t = tmap.get(id);
fprintf(stderr, "Drawing %s to %i,%i in chunk %i,%i\n", t->name_.c_str(), x, y, x_, y_);
void drawBlock(int x, int y, Tile *t) {
texture_.update(t->image_, x * TILE_SIZE, y * TILE_SIZE);
dirty_ = true;
}

void drawBlock(TileMap &tmap, int x, int y) {
drawBlock(tmap, x, y, tiles_[x][y]);
}

void clear() {
memset(tiles_, 0, sizeof(tiles_));
void drawBlock(TileMap &tmap, int x, int y, Tile::TileID id) {
drawBlock(x, y, tmap.get(id));
}

void draw(Win &win) {
if (dirty_) {
sprite_.setTexture(texture_);
dirty_ = false;
}

win.setPos(Vec2(x_ * CHUNK_WIDTH, y_ * CHUNK_HEIGHT));
win.draw(sprite_);
}
void redraw(TileMap &tmap);
void fill(TileMap &tmap, Tile::TileID id);
void draw(Win &win);
};

}

+ 33
- 0
libswan/src/Chunk.cc View File

@@ -0,0 +1,33 @@
#include "Chunk.h"

namespace Swan {

void Chunk::redraw(TileMap &tmap) {
for (int x = 0; x < CHUNK_WIDTH; ++x) {
for (int y = 0; y < CHUNK_HEIGHT; ++y) {
drawBlock(tmap, x, y, tiles_[x][y]);
}
}
}

void Chunk::fill(TileMap &tmap, Tile::TileID id) {
Tile *air = tmap.get(0);
for (int x = 0; x < CHUNK_WIDTH; ++x) {
for (int y = 0; y < CHUNK_HEIGHT; ++y) {
tiles_[x][y] = id;
drawBlock(x, y, air);
}
}
}

void Chunk::draw(Win &win) {
if (dirty_) {
sprite_.setTexture(texture_);
dirty_ = false;
}

win.setPos(Vec2(x_ * CHUNK_WIDTH, y_ * CHUNK_HEIGHT));
win.draw(sprite_);
}

}

+ 1
- 1
libswan/src/Mod.cc View File

@@ -19,7 +19,7 @@ void Mod::registerTile(const std::string &name, const std::string &asset) {

std::string asset_path = path_ + "/" + asset;
if (!t.image_.loadFromFile(asset_path)) {
fprintf(stderr, "Tile %s: Failed to load image %s!\n", t.name_.c_str(), asset_path.c_str());
fprintf(stderr, "Tile %s: Failed to load image %s\n", t.name_.c_str(), asset_path.c_str());
}
}


+ 1
- 1
libswan/src/WorldPlane.cc View File

@@ -21,7 +21,7 @@ void WorldPlane::setTile(int x, int y, Tile::TileID id) {
if (chunk == NULL) {
chunks_.push_back(Chunk(chx, chy));
chunk = &chunks_.back();
chunk->clear();
chunk->fill(world_->tile_map_, 0);
}

chunk->setTile(world_->tile_map_, rx, ry, id);

+ 1
- 1
src/main.cc View File

@@ -72,7 +72,7 @@ int main() {
game.tick();
}

window.clear(sf::Color(135, 206, 250));
window.clear();
game.draw(win);
window.display();
}

Loading…
Cancel
Save