-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.cpp
More file actions
144 lines (144 loc) · 4.55 KB
/
object.cpp
File metadata and controls
144 lines (144 loc) · 4.55 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//#include "object.h"
//#include "globals.h"
//#include <iostream>
//
//Object::Object(std::initializer_list<Param> list) {
// int intIndex = 0;
// for (const auto& p : list) {
//
// std::visit([&](auto&& arg) {
// using T = std::decay_t<decltype(arg)>;
//
// if constexpr (std::is_same_v<T, int>) {
// switch (intIndex++) {
// case 0: this->x = arg; break;
// case 1: this->y = arg; break;
// }
// }
// else if constexpr (std::is_same_v<T, uint32_t>) {
// this->color = arg;
// }
// else if constexpr (std::is_same_v<T, ObjectID>) {
// this->id = arg;
// }
// else if constexpr (std::is_same_v<T, Shape>) {
// this->shape = arg;
// }
//
// }, p);
// }
//}
//
//rectangle::rectangle(std::initializer_list<Param> list) {
// int intIndex = 0;
//
// for (const auto& p : list) {
// std::visit([&](auto&& arg) {
// using T = std::decay_t<decltype(arg)>;
//
// if constexpr (std::is_same_v<T, int>) {
// // sequentially assign ints:
// // 0->x, 1->y, 2->w, 3->h, 4->size, 5->speed
// switch (intIndex++) {
// case 0: this->x = arg; break;
// case 1: this->y = arg; break;
// case 2: this->w = arg; break;
// case 3: this->h = arg; break;
// }
// }
// else if constexpr (std::is_same_v<T, uint32_t>) {
// this->color = arg;
// }
// else if constexpr (std::is_same_v<T, ObjectID>) {
// this->id = arg;
// }
// }, p);
// }
//
//}
//
//bool rectangle::checkCollision() {
// {
// for (int py = y; py < y + h; py++)
// {
// if (py < 0 || py >= h) continue;
// for (int px = x; px < x + w; px++)
// {
// if (px < 0 || px >= w) continue;
//
// ObjectID id = static_cast<ObjectID>(hitboxBuffer[py * width + px]);
//
// if (id == ObjectID::EMPTY || this->id == id) continue;
//
// switch (id)
// {
// case ObjectID::PLAYER: // logging
// std::cout << "Player hit \n";
// return true;
//
// case ObjectID::ENEMY:
// std::cout << "Enemy hit \n";
// return true;
//
// case ObjectID::SOLID:
// std::cout << "Solid hit \n";
// return true;
// default:
// return true;
// }
// }
// }
// return false;
// }
//}
//
//circle::circle(std::initializer_list<Param> list) {
// int intIndex = 0;
// this->shape = Shape::CIRCLE;
//
// for (const auto& p : list) {
// std::visit([&](auto&& arg) {
// using T = std::decay_t<decltype(arg)>;
// if constexpr (std::is_same_v<T, int>) {
// switch (intIndex++) {
// case 0: this->x = arg; break;
// case 1: this->y = arg; break;
// case 2: this->r = arg; break;
// }
// }
// else if constexpr (std::is_same_v<T, uint32_t>) {
// this->color = arg;
// }
// else if constexpr (std::is_same_v<T, ObjectID>) {
// this->id = arg;
// }
// }, p);
// }
//}
//
//bool circle::checkCollision() {
// int r2 = r * r;
//
// for (int dy = -r; dy <= r; dy++) {
// int py = y + dy; // center-based
// if (py < 0 || py >= height) continue;
//
// for (int dx = -r; dx <= r; dx++) {
// int px = x + dx;
// if (px < 0 || px >= width) continue;
//
// if (dx * dx + dy * dy > r2) continue;
//
// ObjectID id = static_cast<ObjectID>(hitboxBuffer[py * width + px]);
// if (id == ObjectID::EMPTY || id == this->id) continue;
//
// switch (id) {
// case ObjectID::PLAYER: std::cout << "Player hit\n"; return true;
// case ObjectID::ENEMY: std::cout << "Enemy hit\n"; return true;
// case ObjectID::SOLID: std::cout << "Solid hit\n"; return true;
// default: return true;
// }
// }
// }
// return false;
//}