-
Notifications
You must be signed in to change notification settings - Fork 0
/
collisiontest.h
executable file
·95 lines (85 loc) · 2 KB
/
collisiontest.h
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
//*********************************************************************************************************
//Collision Test Header
//Defines/declares CollisionTest functions
//Used to test collisions of sprite with Mappy blocks
//*********************************************************************************************************
#ifndef COLLISION_TEST_H
#define COLLISION_TEST_H
#include <string>
#include "sprite.h"
//Test right collision
bool rCol(SPRITE *spr);
//Test left collision
bool lCol(SPRITE *spr);
//Test top collision
bool tCol(SPRITE *spr);
//Test right collision
bool bCol(SPRITE *spr);
//Primary collision test function
bool col(SPRITE *spr, std::string s);
//Test right collision
bool rCol(SPRITE *spr) {
BLKSTR *blockdata;
blockdata = MapGetBlockInPixels(spr->x + spr->width*.90, spr->y + spr->height / 2);
if (blockdata->tl || blockdata->user1) {
return true;
}
else {
return false;
}
}
//Test left collision
bool lCol(SPRITE *spr) {
BLKSTR *blockdata;
blockdata = MapGetBlockInPixels(spr->x + spr->width*.10, spr->y + spr->height / 2);
if (blockdata->tl || blockdata->user1) {
return true;
}
else {
return false;
}
}
//Test top collision
bool tCol(SPRITE *spr) {
BLKSTR *blockdata;
blockdata = MapGetBlockInPixels(spr->x + spr->width*.5, spr->y);
if (blockdata->tl) {
return true;
}
}
//Test right collision
bool bCol(SPRITE *spr) {
BLKSTR *blockdata;
blockdata = MapGetBlockInPixels(spr->x + spr->width*.5, spr->y + spr->height);
if (blockdata->tl) {
return true;
}
}
//Primary collision test function
//col(SPRITE *spr, int i) - Accepts a sprite and and string "t" "b" "l" or "r" to test top bottom left or right block collision
bool col(SPRITE *spr, std::string s) {
if (s == "t") {
if (tCol(spr) == true) {
return true;
}
}
if (s == "b") {
if (bCol(spr) == true) {
return true;
}
}
if (s == "l") {
if (lCol(spr) == true) {
return true;
}
}
if (s == "r") {
if (rCol(spr) == true) {
return true;
}
}
else {
return false;
}
}
#endif