-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.h
69 lines (61 loc) · 1.91 KB
/
Item.h
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
#ifndef MAIN_IT_EM_H
#define MAIN_IT_EM_H
#include "Sprite.h"
typedef std::function<void(bool)> item_action; // bool : true => player take it; false => player throw it;
typedef std::function<bool(void)> item_can_take;
typedef std::function<void(void)> item_use;
enum class E_ItemTypes
{
Nothing,
Key,
Boots,
Ring,
Potion,
Book,
Other
};
struct Item
{
E_ItemTypes item_type = E_ItemTypes::Nothing;
int item_lvl = -2;
Point pos = Point{0, 0};
Sprite spr;
item_action ia;
item_can_take ict;
item_use use;
bool can_be_used = false;
bool inventory = false;
Item() {}
//Item(Item && itm) : item_type(itm.item_type), item_lvl(itm.item_lvl), pos(itm.pos), spr(itm.spr), ia(itm.ia), ict(itm.ict), inventory(itm.inventory){}
//Item(E_ItemTypes i_type, Point _pos, Sprite _spr, item_can_take _ict, item_action _ia) : item_type(i_type), spr(_spr), pos(_pos), ia(_ia), ict(_ict) {}
Item(E_ItemTypes i_type, int i_lvl, Point _pos);
Item(int i_lvl, Point _pos);
void empty_ia(bool on) {}
bool IsPointIn(Point p)
{
int w = spr.Width();
int h = spr.Height();
int p_x = pos.x * TILE_SZ + (TILE_SZ - w) / 2;
int p_y = pos.y * TILE_SZ + (TILE_SZ - h) / 2;
if (p.x < p_x)return false;
if (p.y < p_y)return false;
if (p.x > p_x + w)return false;
if (p.y > p_y + h)return false;
return true;
}
bool IsRectIn(Point p, Size sz)
{
int w = spr.Width();
int h = spr.Height();
int p_x = pos.x * TILE_SZ + (TILE_SZ - w) / 2;
int p_y = pos.y * TILE_SZ + (TILE_SZ - h) / 2;
if (p.x < p_x && p.x + sz.w < p_x)return false;
if (p.x > p_x && p.x > p_x + w)return false;
if (p.y < p_y && p.y + sz.h < p_y)return false;
if (p.y > p_y && p.y > p_y + h)return false;
return true;
}
private:
void CreateHelper();
};
#endif