-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbobSpriteCol.cpp
152 lines (116 loc) · 3.77 KB
/
bobSpriteCol.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
139
140
141
142
143
144
145
146
147
148
149
150
151
#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
#include "commandsScreens.h"
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);
extern int XSprite_formula(int x);
extern int YSprite_formula(int y);
extern int from_XSprite_formula(int x);
extern int from_YSprite_formula(int y);
extern int inSprite( struct retroMask *thisMask, int minX,int minY, int maxX, int maxY, struct retroSpriteObject *otherBob );
#define getSprite(num) &(instance.video -> sprites[num])
int bobSpriteColAll( unsigned short bob )
{
struct retroScreen *screen;
struct retroSpriteObject *thisBob;
struct retroSpriteObject *otherSprite;
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 ];
screen = instance.screens[thisBob -> screen_id ];
if (screen == NULL) return 0;
minX = thisBob -> x - frame -> XHotSpot ;
minY = thisBob -> y - frame -> XHotSpot ;
maxX = XSprite_formula(XHard_formula( screen, minX + frame -> width ));
maxY = YSprite_formula(YHard_formula( screen, minY + frame -> height ));
minX = XSprite_formula(XHard_formula( screen, minX ));
minY = YSprite_formula(YHard_formula( screen, minY ));
for (n=0;n<instance.sprites -> number_of_frames;n++)
{
otherSprite = getSprite(n);
// filter out bad data....
if ( ! otherSprite) continue;
if (otherSprite == thisBob) continue;
if (otherSprite -> image <1) continue;
// check if bob is inside.
r = inSprite( frame -> mask, minX,minY,maxX,maxY, otherSprite );
if (r)
{
if (has_collided(otherSprite -> id) == false) collided.push_back( otherSprite -> id );
return r;
}
}
return 0;
}
int bobSpriteColRange( unsigned short bob, unsigned short start, unsigned short end )
{
struct retroScreen *screen;
struct retroSpriteObject *thisBob;
struct retroSpriteObject *otherSprite;
struct retroFrameHeader *frame;
int minX, maxX, minY, maxY;
int n,r;
thisBob = getBob(bob);
if ( ! thisBob )
{
Printf("bobCol bob %ld not found\n",bob);
Delay(30);
return 0;
}
if (thisBob -> image < 1) return 0; // does not have image.
frame = &instance.sprites -> frames[ thisBob -> image-1 ];
screen = instance.screens[thisBob -> screen_id ];
if (screen == NULL) return 0;
minX = thisBob -> x - frame -> XHotSpot ;
minY = thisBob -> y - frame -> XHotSpot ;
maxX = XSprite_formula(XHard_formula( screen, minX + frame -> width ));
maxY = YSprite_formula(YHard_formula( screen, minY + frame -> height ));
minX = XSprite_formula(XHard_formula( screen, minX ));
minY = YSprite_formula(YHard_formula( screen, minY ));
for ( n=start ; n<=end ; n++ )
{
otherSprite = getSprite(n);
// filter out bad data....
if ( ! otherSprite) continue;
if (otherSprite == thisBob) continue;
if (otherSprite -> image <1) continue;
// check if bob is inside.
r = inSprite( frame -> mask, minX,minY,maxX,maxY, otherSprite );
if (r)
{
if (has_collided(otherSprite -> id) == false) collided.push_back( otherSprite -> id );
return r;
}
}
return 0;
}