commit 7f4f31d5
Added a tree. With two sprites
Changed files
diff --git a/data/sprites/items.sprite b/data/sprites/items.sprite
index 896ab01..58763a0 100644
--- a/data/sprites/items.sprite
+++ b/data/sprites/items.sprite
@@ -10,6 +10,30 @@
"frame_time" : 100,
"originx" : 16,
"originy" : 50
+},
+
+"tree_pine_trunk" : {
+ "texture" : "trunk",
+ "topx" : 96,
+ "topy" : 0,
+ "height" : 96,
+ "width" : 96,
+ "number_of_frames" : 1,
+ "frame_time" : 100,
+ "originx" : 48,
+ "originy" : 48
+},
+
+"tree_pine_top" : {
+ "texture" : "treetop",
+ "topx" : 96,
+ "topy" : 96,
+ "height" : 128,
+ "width" : 96,
+ "number_of_frames" : 1,
+ "frame_time" : 100,
+ "originx" : 48,
+ "originy" : 128
}
-}
\ No newline at end of file
+}
diff --git a/data/textures/treetop.png b/data/textures/treetop.png
new file mode 100644
index 0000000..5a79014
Binary files /dev/null and b/data/textures/treetop.png differ
diff --git a/data/textures/trunk.png b/data/textures/trunk.png
new file mode 100644
index 0000000..119f546
Binary files /dev/null and b/data/textures/trunk.png differ
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp
index 8e8017e..bfc1cf6 100644
--- a/src/saland/GameDraw.cpp
+++ b/src/saland/GameDraw.cpp
@@ -106,6 +106,10 @@ void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const
}
const sago::SagoSprite& mySprite = sHolder->GetSprite(entity->sprite);
mySprite.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
+ if (entity->sprite2[0]) {
+ const sago::SagoSprite& mySprite2 = sHolder->GetSprite(entity->sprite2);
+ mySprite2.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
+ }
}
void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Human* entity, float time, int offsetX, int offsetY, bool drawCollision) {
diff --git a/src/saland/GameItems.cpp b/src/saland/GameItems.cpp
index 2ba92b6..7d411b2 100644
--- a/src/saland/GameItems.cpp
+++ b/src/saland/GameItems.cpp
@@ -26,6 +26,7 @@ https://github.com/sago007/saland
static ItemDef itemDef;
const ItemDef& getItem(const std::string& itemName) {
+ itemDef.sprite2 = "";
if (itemName == "barrel") {
itemDef.radius = 16.0f;
itemDef.sprite = "item_barrel";
@@ -37,5 +38,11 @@ const ItemDef& getItem(const std::string& itemName) {
itemDef.sprite = "item_food_potato";
itemDef.isStatic = false;
}
+ if (itemName == "tree_pine") {
+ itemDef.radius = 20.0f;
+ itemDef.sprite = "tree_pine_trunk";
+ itemDef.sprite2 = "tree_pine_top";
+ itemDef.isStatic = true;
+ }
return itemDef;
}
\ No newline at end of file
diff --git a/src/saland/GameItems.hpp b/src/saland/GameItems.hpp
index 81304e0..343e33d 100644
--- a/src/saland/GameItems.hpp
+++ b/src/saland/GameItems.hpp
@@ -30,6 +30,7 @@ struct ItemDef {
float radius = 1.0f;
std::string itemid = "";
std::string sprite = "";
+ std::string sprite2 = "";
bool isStatic = true;
};
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp
index e428900..ab12e00 100644
--- a/src/saland/GameRegion.cpp
+++ b/src/saland/GameRegion.cpp
@@ -51,7 +51,7 @@ void GameRegion::SpawnMonster(const MonsterDef& def, float destX, float destY) {
b2CircleShape circleShape;
circleShape.m_p.Set(0, 0); //position, relative to body position
- circleShape.m_radius = 0.5f; //radius 16 pixel (32 pixel = 1)
+ circleShape.m_radius = def.radius/32.0f; //32 pixel = 1 unit
b2FixtureDef batDef;
batDef.shape = &circleShape;
@@ -64,6 +64,7 @@ void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) {
std::shared_ptr<MiscItem> barrel = std::make_shared<MiscItem>();
barrel.get()->Radius = def.radius;
barrel.get()->sprite = def.sprite;
+ barrel.get()->sprite2 = def.sprite2;
barrel.get()->X = destX;
barrel.get()->Y = destY;
placeables.push_back(barrel);
@@ -71,7 +72,7 @@ void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) {
if (def.isStatic) {
b2CircleShape circleShape;
circleShape.m_p.Set(0, 0); //position, relative to body position
- circleShape.m_radius = 0.5f; //radius 16 pixel (32 pixel = 1)
+ circleShape.m_radius = def.radius/32.0f; //32 pixel = 1 unit
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &circleShape; //this is a pointer to the shape above
myFixtureDef.density = 10.0f;
@@ -127,6 +128,10 @@ void GameRegion::Init(int x, int y, const std::string& worldName, bool forceRese
SpawnItem(barrelDef, 100.0f, 100.0f+64.0f);
+ const ItemDef& pineDef = getItem("tree_pine");
+ SpawnItem(pineDef, 200.0f, 400.0f);
+
+
const ItemDef& potatoDef = getItem("food_potato");
SpawnItem(potatoDef, 600.0f, 20.0f);
diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp
index 8edbd2b..21b4597 100644
--- a/src/saland/model/placeables.hpp
+++ b/src/saland/model/placeables.hpp
@@ -44,6 +44,7 @@ public:
class MiscItem : public Placeable {
public:
std::string sprite;
+ std::string sprite2;
std::string id = "unknown";
std::string name = "Unknamed item";
double base_value = 1.0;