A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EntItemStack.cc 924B

123456789101112131415161718192021222324252627282930313233
  1. #include "EntItemStack.h"
  2. EntItemStack::EntItemStack(const Swan::Context &ctx, const Swan::SRF &params):
  3. body_(SIZE, MASS) {
  4. readSRF(ctx, params);
  5. }
  6. void EntItemStack::draw(const Swan::Context &ctx, Swan::Win &win) {
  7. body_.outline(win);
  8. }
  9. void EntItemStack::update(const Swan::Context &ctx, float dt) {
  10. body_.gravity();
  11. body_.update(dt);
  12. body_.collide(ctx.plane);
  13. }
  14. void EntItemStack::readSRF(const Swan::Context &ctx, const Swan::SRF &srf) {
  15. auto &arr = dynamic_cast<const Swan::SRFArray &>(srf);
  16. auto *pos = dynamic_cast<Swan::SRFFloatArray *>(arr.val[0].get());
  17. auto *name = dynamic_cast<Swan::SRFString *>(arr.val[1].get());
  18. body_.pos_.set(pos->val[0], pos->val[1]);
  19. item_ = &ctx.world.getItem(name->val);
  20. }
  21. Swan::SRF *EntItemStack::writeSRF(const Swan::Context &ctx) {
  22. return new Swan::SRFArray{
  23. new Swan::SRFFloatArray{ body_.pos_.x_, body_.pos_.y_ },
  24. new Swan::SRFString{ item_->name },
  25. };
  26. }