23 #ifndef TEENAGENT_OBJECTS_H 24 #define TEENAGENT_OBJECTS_H 26 #include "common/rect.h" 27 #include "graphics/surface.h" 29 #include "teenagent/teenagent.h" 33 enum {kActorUp = 1, kActorRight = 2, kActorDown = 3, kActorLeft = 4 };
36 int16 left, top, right, bottom;
38 inline Rect() : left(0), top(0), right(0), bottom(0), _base(NULL) {}
40 inline Rect(uint16 l, uint16 t, uint16 r, uint16 b) : left(l), top(t), right(r), bottom(b), _base(NULL) {}
43 return point.
x >= left && point.
x <= right && point.
y >= top && point.
y <= bottom;
50 inline bool valid()
const {
51 return left >= 0 && left < kScreenWidth && right >= 0 && right < kScreenWidth && top >= 0 && top < kScreenHeight && bottom >= 0 && bottom < kScreenHeight;
56 void dump(
int level = 0)
const {
57 debugC(level, kDebugObject,
"rect[%u, %u, %u, %u]", left, top, right, bottom);
61 left = top = right = bottom = 0;
67 inline bool intersects_hline(
int x1,
int x2,
int y)
const {
70 return y >= top && y <= bottom && x1 <= right && x2 >= left;
73 inline bool intersects_vline(
int x,
int y1,
int y2)
const {
76 return x >= left && x <= right && y1 <= bottom && y2 >= top;
79 inline bool contains(
const Rect &rect)
const {
80 return rect.left >= left && rect.right <= right && rect.top >= top && rect.bottom <= bottom;
83 static inline bool inside(
int x,
int a,
int b) {
86 return x >= a && x <= b;
90 int dy = b.
y - a.
y, dx = b.
x - a.
x;
95 int yl = (left - a.
x) * dy / dx + a.
y;
96 if (yl > top && yl < bottom && inside(yl, a.
y, b.
y) && inside(left, a.
x, b.
x)) {
100 int yr = (right - a.
x) * dy / dx + a.
y;
101 if (yr > top && yr < bottom && inside(yr, a.
y, b.
y) && inside(right, a.
x, b.
x)) {
108 int xt = (top - a.
y) * dx / dy + a.
x;
109 if (xt > left && xt < right && inside(xt, a.
x, b.
x) && inside(top, a.
y, b.
y)) {
114 int xb = (bottom - a.
y) * dx / dy + a.
x;
115 if (xb > left && xb < right && inside(xb, a.
x, b.
x) && inside(bottom, a.
y, b.
y)) {
162 byte actorOrientation;
167 Object(): _base(NULL), _nameSize(0) {
id = 0; actorOrientation = 0; enabled = 0; }
168 void dump(
int level = 0)
const;
170 void load(byte *addr);
186 void load(byte *addr);
196 uint16 actorX, actorY;
198 void load(byte *src);
199 void dump(
int level = 0)
const;
213 for (uint i = 0; i <
ARRAYSIZE(sideHint); i++) {
217 void dump(
int level = 0)
const;
218 void load(byte *src);
229 void load(byte *src);
233 template<
typename T>
inline T SIGN(T x) {
return (x > 0) ? 1 : ((x < 0) ? -1 : 0); }
#define ARRAYSIZE(x)
Definition: util.h:91
Definition: objects.h:202
int16 right
Definition: rect.h:146
Definition: objects.h:158
void SWAP(T &a, T &b)
Definition: util.h:82
Definition: objects.h:180
Definition: objects.h:225
Definition: objects.h:192
int16 left
Definition: rect.h:145
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
uint sqrDist(const Point &p) const
Definition: rect.h:110