message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.") | message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.") | ||||
endif() | endif() | ||||
set(LIBRARIES sfml-graphics sfml-system sfml-window sfml-audio dl) | |||||
# We want to be able to use C++20 designated initializers, | # We want to be able to use C++20 designated initializers, | ||||
# but Clang doesn't support them yet. | # but Clang doesn't support them yet. | ||||
# Remove once Clang 9.1 or something comes out. | # Remove once Clang 9.1 or something comes out. | ||||
add_subdirectory(core.mod) | add_subdirectory(core.mod) | ||||
add_executable(swan src/main.cc) | add_executable(swan src/main.cc) | ||||
target_link_libraries(swan libswan) | |||||
target_link_libraries(swan libswan ${LIBRARIES}) | |||||
set(assets | set(assets | ||||
assets/icon.png | assets/icon.png |
src/entities/EntPlayer.cc | src/entities/EntPlayer.cc | ||||
src/entities/EntItemStack.cc) | src/entities/EntItemStack.cc) | ||||
set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "") | 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 | set(assets | ||||
assets/entities/player-still.png | assets/entities/player-still.png |
readSRF(ctx, params); | 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) { | void EntItemStack::readSRF(const Swan::Context &ctx, const Swan::SRF &srf) { | ||||
auto &arr = dynamic_cast<const Swan::SRFArray &>(srf); | auto &arr = dynamic_cast<const Swan::SRFArray &>(srf); | ||||
auto *pos = dynamic_cast<Swan::SRFFloatArray *>(arr.val[0].get()); | auto *pos = dynamic_cast<Swan::SRFFloatArray *>(arr.val[0].get()); | ||||
auto *name = dynamic_cast<Swan::SRFString *>(arr.val[1].get()); | auto *name = dynamic_cast<Swan::SRFString *>(arr.val[1].get()); | ||||
body_.pos_.set(pos->val[0], pos->val[1]); | 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) { | Swan::SRF *EntItemStack::writeSRF(const Swan::Context &ctx) { |
EntItemStack(const Swan::Context &ctx, const Swan::SRF ¶ms); | 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; | void readSRF(const Swan::Context &ctx, const Swan::SRF &srf) override; | ||||
Swan::SRF *writeSRF(const Swan::Context &ctx) override; | Swan::SRF *writeSRF(const Swan::Context &ctx) override; | ||||
src/WorldPlane.cc) | src/WorldPlane.cc) | ||||
target_include_directories(libswan PUBLIC "include/swan") | target_include_directories(libswan PUBLIC "include/swan") | ||||
set_target_properties(libswan PROPERTIES OUTPUT_NAME 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) | install(TARGETS libswan DESTINATION swan/libswan) |
} | } | ||||
Vec2 getSize() { | Vec2 getSize() { | ||||
sf::Vector2 v = window_->getSize(); | |||||
sf::Vector2u v = window_->getSize(); | |||||
return Vec2(v.x, v.y) / (TILE_SIZE * scale_); | return Vec2(v.x, v.y) / (TILE_SIZE * scale_); | ||||
} | } | ||||
}; | }; |
if (t.dropped_item != "") { | if (t.dropped_item != "") { | ||||
spawnEntity("core::item-stack", SRFArray{ | 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 }, | new SRFString{ t.dropped_item }, | ||||
}); | }); | ||||
} | } |