} | } | ||||
void ItemStackEntity::draw(const Swan::Context &ctx, Swan::Win &win) { | void ItemStackEntity::draw(const Swan::Context &ctx, Swan::Win &win) { | ||||
SDL_Rect rect = item_->image_.frameRect(); | |||||
SDL_Rect rect = item_->image.frameRect(); | |||||
SDL_Texture *tex = item_->image_.texture_.get(); | |||||
SDL_Texture *tex = item_->image.texture_.get(); | |||||
Swan::TexColorMod darken(tex, 220, 220, 220); | Swan::TexColorMod darken(tex, 220, 220, 220); | ||||
win.showTexture(body_.pos, tex, &rect, | win.showTexture(body_.pos, tex, &rect, | ||||
Swan::Entity::PackObject ItemStackEntity::serialize(const Swan::Context &ctx, msgpack::zone &zone) { | Swan::Entity::PackObject ItemStackEntity::serialize(const Swan::Context &ctx, msgpack::zone &zone) { | ||||
return { | return { | ||||
{ "pos", msgpack::object(body_.pos, zone) }, | { "pos", msgpack::object(body_.pos, zone) }, | ||||
{ "tile", msgpack::object(item_->name_, zone) }, | |||||
{ "tile", msgpack::object(item_->name, zone) }, | |||||
}; | }; | ||||
} | } |
} | } | ||||
// Fall down faster than we went up | // Fall down faster than we went up | ||||
if (!physics_.on_ground && (!jumpPressed || physics_.vel.y > 0)) | |||||
if (!physics_.onGround && (!jumpPressed || physics_.vel.y > 0)) | |||||
physics_.force += Swan::Vec2(0, DOWN_FORCE); | physics_.force += Swan::Vec2(0, DOWN_FORCE); | ||||
if (state_ != oldState) | if (state_ != oldState) |
registerTile({ | registerTile({ | ||||
.name = "stone", | .name = "stone", | ||||
.image = "core/tile/stone", | .image = "core/tile/stone", | ||||
.dropped_item = "core::stone", | |||||
.droppedItem = "core::stone", | |||||
}); | }); | ||||
registerTile({ | registerTile({ | ||||
.name = "dirt", | .name = "dirt", | ||||
.image = "core/tile/dirt", | .image = "core/tile/dirt", | ||||
.dropped_item = "core::dirt", | |||||
.droppedItem = "core::dirt", | |||||
}); | }); | ||||
registerTile({ | registerTile({ | ||||
.name = "grass", | .name = "grass", | ||||
.image = "core/tile/grass", | .image = "core/tile/grass", | ||||
.dropped_item = "core::dirt", | |||||
.droppedItem = "core::dirt", | |||||
}); | }); | ||||
registerTile({ | registerTile({ | ||||
.name = "tree-trunk", | .name = "tree-trunk", | ||||
.image = "core/tile/tree-trunk", | .image = "core/tile/tree-trunk", | ||||
.dropped_item = "core::tree-trunk", | |||||
.droppedItem = "core::tree-trunk", | |||||
}); | }); | ||||
registerTile({ | registerTile({ | ||||
.name = "leaves", | .name = "leaves", | ||||
registerTile({ | registerTile({ | ||||
.name = "torch", | .name = "torch", | ||||
.image = "core/tile/torch", | .image = "core/tile/torch", | ||||
.is_solid = false, | |||||
.light_level = 80/255.0, | |||||
.isSolid = false, | |||||
.lightLevel = 80/255.0, | |||||
}); | }); | ||||
registerItem({ | registerItem({ | ||||
} | } | ||||
void onTileBreak(const Swan::Context &ctx, Swan::TilePos pos, Swan::Tile &tile) { | void onTileBreak(const Swan::Context &ctx, Swan::TilePos pos, Swan::Tile &tile) { | ||||
if (tile.droppedItem_) { | |||||
if (tile.droppedItem) { | |||||
ctx.plane.spawnEntity<ItemStackEntity>( | ctx.plane.spawnEntity<ItemStackEntity>( | ||||
ctx, (Swan::Vec2)pos + Swan::Vec2{0.5, 0.5}, *tile.droppedItem_); | |||||
ctx, (Swan::Vec2)pos + Swan::Vec2{0.5, 0.5}, *tile.droppedItem); | |||||
} | } | ||||
} | } | ||||
timer_ += interval_; | timer_ += interval_; | ||||
frame_ += 1; | frame_ += 1; | ||||
if (frame_ >= resource_.num_frames_) | |||||
if (frame_ >= resource_.numFrames_) | |||||
frame_ = 0; | frame_ = 0; | ||||
} | } | ||||
} | } |