-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcollectable.h
103 lines (88 loc) · 2.68 KB
/
collectable.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "splashkit.h"
#include <memory>
class Collectable
{
protected:
bitmap image;
bool collected = false;
point_2d position;
rectangle hitbox;
int cell;
drawing_options opts;
public:
Collectable(bitmap cell_sheet, point_2d position)
{
this->image = cell_sheet;
this->position = position;
this->opts = option_defaults();
};
~Collectable(){};
void draw()
{
if(!collected)
{
draw_bitmap(image, position.x, position.y, opts);
//draw_rectangle(COLOR_GREEN, this->hitbox);
}
};
virtual void make_hitbox()
{
rectangle hitbox;
hitbox.x = this->position.x;
hitbox.y = this->position.y;
hitbox.height = bitmap_cell_height(this->image);
hitbox.width = bitmap_cell_width(this->image);
this->hitbox = hitbox;
};
virtual string collision(rectangle one)
{
bool x_overlaps = (rectangle_left(one) < rectangle_right(this->hitbox)) && (rectangle_right(one) > rectangle_left(this->hitbox));
bool y_overlaps = (rectangle_top(one) < rectangle_bottom(this->hitbox)) && (rectangle_bottom(one) > rectangle_top(this->hitbox));
bool collision = x_overlaps && y_overlaps;
if (collision)
return "Collision";
else
return "None";
};
virtual void effect(std::shared_ptr<Player> player) = 0;
bool get_collected()
{
return this->collected;
};
void set_collected(bool new_value)
{
this->collected = new_value;
};
rectangle get_hitbox()
{
return this->hitbox;
};
};
class HeartCollectable : public Collectable
{
public:
HeartCollectable(bitmap cell_sheet, point_2d position, int cell) : Collectable(cell_sheet, position)
{
this->cell = cell;
this->opts.draw_cell = this->cell;
make_hitbox();
};
~HeartCollectable(){};
void effect(std::shared_ptr<Player> player)
{
//write_line("Heart Effect");
if(player->player_health < 3)
player->player_health += 1;
else
collected = false;
};
void make_hitbox() override
{
rectangle hitbox;
hitbox.x = this->position.x + 24;
hitbox.y = this->position.y + 50;
hitbox.height = 14;
hitbox.width = 16;
this->hitbox = hitbox;
};
};