-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollision.c
107 lines (86 loc) · 3.03 KB
/
collision.c
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
#include "collision.h"
#include <stdio.h>
#include <stdlib.h>
#include <tari/collisionhandler.h>
#include <tari/math.h>
#include <tari/memoryhandler.h>
static struct {
int enemyCollisionList;
int enemyAttackCollisionList;
int playerCollisionList;
int playerAttackCollisionList;
int gIDs;
} gData;
void loadCollision() {
gData.enemyCollisionList = addCollisionListToHandler();
gData.playerCollisionList = addCollisionListToHandler();
gData.enemyAttackCollisionList = addCollisionListToHandler();
gData.playerAttackCollisionList = addCollisionListToHandler();
addCollisionHandlerCheck(gData.enemyCollisionList, gData.playerAttackCollisionList);
addCollisionHandlerCheck(gData.playerCollisionList, gData.enemyAttackCollisionList);
}
CollisionData makeHittableCollisionData() {
CollisionData ret;
ret.force = makePosition(0,0,0);
ret.strength = 0;
ret.id = gData.gIDs++;
return ret;
}
CollisionData makePunchCollisionData(int strength, Acceleration force) {
CollisionData ret;
ret.force = force;
ret.strength = strength;
ret.id = gData.gIDs++;
return ret;
}
int getEnemyCollisionListID() {
return gData.enemyCollisionList;
}
int getEnemyAttackCollisionListID() {
return gData.enemyAttackCollisionList;
}
int getPlayerCollisionListID() {
return gData.playerCollisionList;
}
int getPlayerAttackCollisionListID() {
return gData.playerAttackCollisionList;
}
void updateCollisionDataID(CollisionData* cData) {
cData->id = gData.gIDs++;
}
void constraintIntoLevel(Position* p, Position* screenPositionReference) {
*p = vecAdd(*p, vecScale(*screenPositionReference, -1));
p->x = max(p->x, -55);
p->x = min(p->x, 320-64);
p->y = max(p->y, 20);
p->y = min(p->y, 240-128);
*p = vecAdd(*p, *screenPositionReference);
}
void adjustZ(Position* p) {
double t = getLinearInterpolationFactor(0, 240, p->y);
p->z = interpolateLinear(3, 4, t);
}
ScriptPosition loadSingleCollisionAnimation(void* caller, ScriptPosition position) {
CollisionAnimation* cAnimation = caller;
Position topLeft;
Position bottomRight;
position = getNextScriptDouble(position, &topLeft.x);
position = getNextScriptDouble(position, &topLeft.y);
position = getNextScriptDouble(position, &topLeft.z);
position = getNextScriptDouble(position, &bottomRight.x);
position = getNextScriptDouble(position, &bottomRight.y);
position = getNextScriptDouble(position, &bottomRight.z);
CollisionRect rect = makeCollisionRect(topLeft, bottomRight);
Collider* col = allocMemory(sizeof(Collider));
*col = makeColliderFromRect(rect);
vector_push_back_owned(&cAnimation->mFrames, col);
return position;
}
ScriptPosition loadPunchCollisionAnimation(ScriptPosition position, CollisionAnimation* collisionAnimation, Animation animation) {
ScriptRegion collisionRegion = getScriptRegionAtPosition(position);
*collisionAnimation = makeEmptyCollisionAnimation();
executeOnScriptRegion(collisionRegion, loadSingleCollisionAnimation, collisionAnimation);
collisionAnimation->mAnimation = animation;
position = getPositionAfterScriptRegion(position.mRegion, collisionRegion);
return position;
}