@@ -9,9 +9,8 @@ ItemStackEntity::ItemStackEntity( | |||
static std::uniform_real_distribution vx(-2.3f, 2.3f); | |||
static std::uniform_real_distribution vy(-2.3f, -1.2f); | |||
item_ = &ctx.world.getItem(item); | |||
body_.pos = pos; | |||
body_.pos.y += 0.5 - body_.size.y / 2; | |||
item_ = &ctx.world.getItem(item); | |||
physics_.vel += Swan::Vec2{ vx(ctx.world.random_), vy(ctx.world.random_) }; | |||
} | |||
@@ -9,6 +9,7 @@ public: | |||
PlayerEntity(const Swan::Context &ctx, const PackObject &obj); | |||
Inventory &get(InventoryTrait::Tag) override { return inventory_; } | |||
Body &get(BodyTrait::Tag) override { return body_; } | |||
void draw(const Swan::Context &ctx, Swan::Win &win) override; | |||
void update(const Swan::Context &ctx, float dt) override; |
@@ -70,7 +70,7 @@ public: | |||
void onTileBreak(const Swan::Context &ctx, Swan::TilePos pos, Swan::Tile &tile) { | |||
if (tile.dropped_item_) { | |||
ctx.plane.spawnEntity<ItemStackEntity>( | |||
ctx, pos, *tile.dropped_item_); | |||
ctx, (Swan::Vec2)pos + Swan::Vec2{0.5, 0.5}, *tile.dropped_item_); | |||
} | |||
} | |||
@@ -3,6 +3,7 @@ | |||
#include <vector> | |||
#include <string> | |||
#include <typeindex> | |||
#include <type_traits> | |||
#include "common.h" | |||
#include "log.h" | |||
@@ -131,6 +132,11 @@ inline EntityRef EntityCollection::spawn(Args&&... args) { | |||
ent->index_ = idx; | |||
ent->generation_ = generation; | |||
if constexpr (std::is_base_of_v<BodyTrait, Ent>) { | |||
BodyTrait::Body &body = ent->get(BodyTrait::Tag{}); | |||
body.pos -= body.size / 2; | |||
} | |||
return { this, idx, generation }; | |||
} | |||