Game logic question: Containing entities within a level or overworld

I am looking for a way to keep track of Players, Items etc on the overworld of a game map. I'm afraid to start work on the player and item code because I'm unsure how it all pans out. Is a level vectors of tiles, or vectors of tiles, players, enemies, items? If an item is dropped by a monster, is that now a tile on the map until picked up? Which casts the tile back to an item? I'm really unsure..

Here's some psuedo I've wrote trying to describe what I see

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Tile : public Renderable // A Tile can be drawn to the screen
{
private:
	Sprite sprite; // The thing to draw
	Vector2f position; // X and Y of it's position
	bool passable; // Can you walk through it?
public:
	Tile(position, passable);
	GetPosition();
	IsPassable();
	virtual Draw(Window&) { Window.draw(sprite); } // From Renderable
};

// Here is where I am struggling

enum class ItemType { QUEST, WEAPON, ARMOUR, ITEM };

class Item : public Renderable // An Item can be draw?
{
private:
        ItemType type;
	int value;
public:
	Item(value);
};

class QuestItem : public Item
{
private:
	int QuestID;
public:
	QuestItem(QuestID);
	// I am unsure if this needs it's own class, unless it has some unique use
	// I can only think of containing a vector of quest ids it's related to
};

// Now I'm going in over my head with complexity, even though it seems simple on paper
enum class TierType { WARRIOR, ROGUE, MAGE };
enum class WeaponType { ONEHANDED, TWOHANDED, OFFHAND } // OFFHAND is shield slot weapon
enum class ElementalType { AIR, EARTH, FIRE, WATER, ELECTRICITY } // Would like to implement in future, for buff and skill upgrades

class WeaponItem : public Item
{
private:
	TierType tier;
	WeaponType type;
	int damage;
public:
	WeaponItem(tier, type, damage);
	// Getters
	// Setters
}

// ...

class Player : public Renderable
{
private:
	std::vector<Item*> inventory; // In reality the item will be std::shared_ptr
	std::vector<Item*> worn_inventory;
public:
};

class Map : public Renderable // A Map can be draw, right? Or should it be separate?
{
private:
	std::vector<Tile> map;
	std::vector<Item*> items;
	std::vector<Player*> players;
public:
	Map();
	//Getters
	// Setters
	virtual Draw(Window&)
	{
		for(every tile in map) Window.draw(tile); // Draw map
		for(every item in items) Window.draw(item); // Draw items
		// What about drawing spells and projectiles? If a player casts a spell where does that happen?
		for(every player in players) Window.draw(player); // Draw players, monsters, npcs
		
	}
};


I've been trying to think about the is-a or has-a relationship of objects but regarding to the overworld of a game and what the player see's it's a real struggle to pinpoint where objects should be. Is it down to the engine to manage players and items or is it down to the engine state?


Any incite into handling this would be much appreciated. Examples based upon the code above would also be gladly reviewed.
Last edited on
Reading all of this makes me think you are getting a bit ahead of your self here.

If you want to make a game, start at the beginning. I am going to assume this is a 2d game. What expansion library did you plan to use?

Do you have sprite artwork yet?

Did you get a character sprite to appear on screen yet?

Next add some controls. Get you character to move. Animate the movements.

Have you got that far yet?

Add a second object. Now get some collision detection going.

A game usually starts at a simple core like this and expands outward.

By the time you get this far you have already figured out how to place items on a map and collect them. So start at the beginning... Good luck.

Topic archived. No new replies allowed.