@@ -18,6 +18,8 @@ else() | |||
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.") | |||
endif() | |||
set(LIBRARIES sfml-graphics sfml-system sfml-window sfml-audio dl) | |||
# We want to be able to use C++20 designated initializers, | |||
# but Clang doesn't support them yet. | |||
# Remove once Clang 9.1 or something comes out. | |||
@@ -32,7 +34,7 @@ add_subdirectory(libswan) | |||
add_subdirectory(core.mod) | |||
add_executable(swan src/main.cc) | |||
target_link_libraries(swan libswan) | |||
target_link_libraries(swan libswan ${LIBRARIES}) | |||
set(assets | |||
assets/icon.png |
@@ -4,7 +4,7 @@ add_library(core.mod SHARED | |||
src/entities/EntPlayer.cc | |||
src/entities/EntItemStack.cc) | |||
set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "") | |||
target_link_libraries(core.mod libswan) | |||
target_link_libraries(core.mod libswan ${LIBRARIES}) | |||
set(assets | |||
assets/entities/player-still.png |
@@ -6,13 +6,23 @@ EntItemStack::EntItemStack(const Swan::Context &ctx, const Swan::SRF ¶ms): | |||
readSRF(ctx, params); | |||
} | |||
void EntItemStack::draw(const Swan::Context &ctx, Swan::Win &win) { | |||
body_.outline(win); | |||
} | |||
void EntItemStack::update(const Swan::Context &ctx, float dt) { | |||
body_.gravity(); | |||
body_.update(dt); | |||
body_.collide(ctx.plane); | |||
} | |||
void EntItemStack::readSRF(const Swan::Context &ctx, const Swan::SRF &srf) { | |||
auto &arr = dynamic_cast<const Swan::SRFArray &>(srf); | |||
auto *pos = dynamic_cast<Swan::SRFFloatArray *>(arr.val[0].get()); | |||
auto *name = dynamic_cast<Swan::SRFString *>(arr.val[1].get()); | |||
body_.pos_.set(pos->val[0], pos->val[1]); | |||
item_ = &ctx.world.getItem(name->val); | |||
item_ = &ctx.world.getItem(name->val); | |||
} | |||
Swan::SRF *EntItemStack::writeSRF(const Swan::Context &ctx) { |
@@ -12,6 +12,8 @@ public: | |||
EntItemStack(const Swan::Context &ctx, const Swan::SRF ¶ms); | |||
void draw(const Swan::Context &ctx, Swan::Win &win) override; | |||
void update(const Swan::Context &ctx, float dt) override; | |||
void readSRF(const Swan::Context &ctx, const Swan::SRF &srf) override; | |||
Swan::SRF *writeSRF(const Swan::Context &ctx) override; | |||
@@ -13,6 +13,6 @@ add_library(libswan SHARED | |||
src/WorldPlane.cc) | |||
target_include_directories(libswan PUBLIC "include/swan") | |||
set_target_properties(libswan PROPERTIES OUTPUT_NAME swan) | |||
target_link_libraries(libswan sfml-graphics sfml-system sfml-window sfml-audio dl) | |||
target_link_libraries(libswan ${LIBRARIES}) | |||
install(TARGETS libswan DESTINATION swan/libswan) |
@@ -44,7 +44,7 @@ struct Win { | |||
} | |||
Vec2 getSize() { | |||
sf::Vector2 v = window_->getSize(); | |||
sf::Vector2u v = window_->getSize(); | |||
return Vec2(v.x, v.y) / (TILE_SIZE * scale_); | |||
} | |||
}; |
@@ -100,7 +100,7 @@ void WorldPlane::breakBlock(TilePos pos) { | |||
if (t.dropped_item != "") { | |||
spawnEntity("core::item-stack", SRFArray{ | |||
new SRFFloatArray{ pos.x_ + 0.5f, pos.y_ + 0.5f }, | |||
new SRFFloatArray{ (float)pos.x_, (float)pos.y_ }, | |||
new SRFString{ t.dropped_item }, | |||
}); | |||
} |