-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbobCol.cpp
138 lines (106 loc) · 2.97 KB
/
bobCol.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <vector>
#include <limits.h>
#ifdef __amigaos4__
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/retroMode.h>
#include <AmosKittens.h>
#endif
#ifdef __linux__
#include "os/linux/stuff.h"
#include <retromode.h>
#include <retromode_lib.h>
#endif
extern std::vector<int> collided;
extern std::vector<struct retroSpriteObject *> bobs;
extern struct retroSpriteObject *getBob(unsigned int id);
extern struct retroSpriteObject *getBobOnScreen(unsigned int id,int screen);
extern int inBob( struct retroMask *thisMask, int minX,int minY, int maxX, int maxY, struct retroSpriteObject *otherBob );
extern bool has_collided(int id);
int bobColRange( unsigned short bob, unsigned short start, unsigned short end )
{
struct retroSpriteObject *thisBob;
struct retroSpriteObject *otherBob;
struct retroFrameHeader *frame;
int minX, maxX, minY, maxY;
int n,r, i;
thisBob = getBob(bob);
if ( ! thisBob )
{
Printf("bobCol bob %ld not found\n",bob);
Delay(30);
return 0;
}
if (instance.sprites == NULL) return 0;
i = thisBob -> image -1;
// check if inside range.
if (i < 0) return 0;
if (i >= instance.sprites -> number_of_frames) return 0;
frame = &instance.sprites -> frames[ i ];
minX = thisBob -> x - frame -> XHotSpot;
minY = thisBob -> y - frame -> XHotSpot;
maxX = minX + frame -> width;
maxY = minY + frame -> height;
for ( n=start ; n<=end ; n++ )
{
otherBob = getBobOnScreen(n , thisBob -> screen_id );
// filter out bad data....
if ( ! otherBob) continue;
if (otherBob == thisBob) continue;
i = otherBob -> image -1;
if (i <0) continue;
if (i >= instance.sprites -> number_of_frames) continue;
// check if bob is inside.
r = inBob( frame -> mask, minX,minY,maxX,maxY, otherBob );
if (r)
{
if (has_collided(otherBob -> id) == false) collided.push_back( otherBob -> id );
return r;
}
}
return 0;
}
int bobColAll( unsigned short bob )
{
struct retroSpriteObject *thisBob;
struct retroSpriteObject *otherBob;
struct retroFrameHeader *frame;
int minX, maxX, minY, maxY;
unsigned int n;
int r;
thisBob = getBob(bob);
if ( ! thisBob )
{
Printf("bobCol bob %ld not found\n",bob);
Delay(30);
return 0;
}
if (thisBob -> image == 0) return 0;
frame = &instance.sprites -> frames[ thisBob -> image-1 ];
minX = thisBob -> x - frame -> XHotSpot;
minY = thisBob -> y - frame -> XHotSpot;
maxX = minX + frame -> width;
maxY = minY + frame -> height;
for (n=0;n<bobs.size();n++)
{
otherBob = bobs[n];
// filter out bad data....
if ( ! otherBob) continue;
if (otherBob -> screen_id != thisBob -> screen_id ) continue;
if (otherBob == thisBob) continue;
if (otherBob -> image <1) continue;
// check if bob is inside.
r = inBob( frame -> mask, minX,minY,maxX,maxY, otherBob );
if (r)
{
if (has_collided(otherBob -> id) == false) collided.push_back( otherBob -> id );
return r;
}
}
return 0;
}