-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathIrregularBBox.cpp
120 lines (93 loc) · 2.47 KB
/
IrregularBBox.cpp
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
#include "../nx.h"
#include "IrregularBBox.h"
#include "IrregularBBox.fdh"
bool IrregularBBox::init(Object *associatedObject, int max_rectangles)
{
memset(&bbox, 0, sizeof(bbox));
this->num_bboxes = max_rectangles;
this->assoc_object = associatedObject;
if (num_bboxes >= IB_MAX_BBOXES)
{
num_bboxes = IB_MAX_BBOXES;
staterr("IrregularBBox::Init(): too many rectangles (%d given): max is %d", max_rectangles, IB_MAX_BBOXES);
return 1;
}
for(int i=0;i<num_bboxes;i++)
{
bbox[i] = CreateObject(0, 0, OBJ_BBOX_PUPPET);
bbox[i]->sprite = SPR_BBOX_PUPPET_1 + i;
bbox[i]->hp = 1000;
bbox[i]->damage = 0;
bbox[i]->invisible = true;
}
return 0;
}
void IrregularBBox::destroy()
{
for(int i=0;i<num_bboxes;i++)
{
bbox[i]->Delete();
bbox[i] = NULL;
}
num_bboxes = 0;
assoc_object = NULL;
}
/*
void c------------------------------() {}
*/
void IrregularBBox::set_damage(int dmg)
{
for(int i=0;i<num_bboxes;i++)
bbox[i]->damage = dmg;
}
// link damage hits on the bbox to damage on it's associated object, o
void IrregularBBox::transmit_hits()
{
if (!assoc_object) return;
for(int i=0;i<num_bboxes;i++)
{
if (bbox[i]->hp < 1000)
{
assoc_object->DealDamage(1000 - bbox[i]->hp);
bbox[i]->hp = 1000;
}
}
}
/*
void c------------------------------() {}
*/
void IrregularBBox::place(void (*placefunc)(void *userparm), void *userparm)
{
// first assume all disabled
for(int i=0;i<num_bboxes;i++)
{
bbox[i]->y = -1024; // effectively disables it
}
// ask object to place it's bboxes as it wishes for this frame
// by using set_bbox().
(*placefunc)(userparm);
}
void IrregularBBox::set_bbox(int index, int x, int y, int w, int h, uint32_t flags)
{
if (index < 0 || index >= num_bboxes)
{
staterr("IrregularBBox::set_bbox: index out of range: %d", index);
return;
}
Object *box = bbox[index];
// coordinates passed in here are for the right-facing frame,
// if we are currently left-facing then flip them.
if (assoc_object->dir == LEFT)
x = sprites[assoc_object->sprite].w - x - w;
box->x = assoc_object->x + (x << CSF);
box->y = assoc_object->y + (y << CSF);
sprites[box->sprite].bbox.x1 = 0;
sprites[box->sprite].bbox.y1 = 0;
sprites[box->sprite].bbox.x2 = (w - 1);
sprites[box->sprite].bbox.y2 = (h - 1);
box->flags &= ~(FLAG_SHOOTABLE | FLAG_INVULNERABLE);
box->flags |= flags;
// nitpicking perfect sync for this frame since we are not aftermove
box->x += assoc_object->xinertia;
box->y += assoc_object->yinertia;
}