-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.c
106 lines (86 loc) · 2.22 KB
/
player.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
#include "player.h"
#include <tari/input.h>
#include <tari/datastructures.h>
#include <tari/memoryhandler.h>
#include <tari/timer.h>
#include <tari/collisionhandler.h>
#include <tari/soundeffect.h>
#include <tari/stagehandler.h>
#include <tari/wrapper.h>
#include "collision.h"
#include "stage.h"
#include "preciouspeople.h"
#include "explosion.h"
#include "mirkling.h"
typedef struct {
int mCollisionID;
Position mPosition;
Collider mCollider;
CollisionData mCollisionData;
} Shot;
static struct {
int mCanShoot;
double mRotationAngle;
Position mRotationCenter;
} gData;
static void loadPlayer(void* tData) {
(void)tData;
gData.mCanShoot = 1;
gData.mRotationAngle = 0;
gData.mRotationCenter = makePosition(0, 0, 0);
}
static void shotFinished(void* tCaller) {
Shot* s = tCaller;
removeFromCollisionHandler(getShotCollisionList(), s->mCollisionID);
destroyCollider(&s->mCollider);
freeMemory(s);
}
static void addShot(Position p, double r) {
Shot* s = allocMemory(sizeof(Shot));
s->mPosition = p;
s->mCollider = makeColliderFromCirc(makeCollisionCirc(makePosition(0,0,0), r));
s->mCollisionData = makeCollisionData(getShotCollisionList());
s->mCollisionID = addColliderToCollisionHandler(getShotCollisionList(), &s->mPosition, s->mCollider, NULL, NULL, &s->mCollisionData);
p.z = 3;
addExplosion(p, r);
addMirklingDetraction(p, r*0.6);
addTimerCB(2, shotFinished, s);
}
static Position getAdvancedShotPosition() {
Position p = getShotPosition();
p = vecAdd(p, *getStagePositionReference());
p = vecRotateZAroundCenter(p, gData.mRotationAngle, gData.mRotationCenter);
return p;
}
static void shoot() {
Position p = getAdvancedShotPosition();
addShot(p, 40 * getPreciousPeopleAmount());
}
static void updatePlayer(void* tData) {
(void)tData;
if (!gData.mCanShoot || isWrapperPaused()) return;
if (hasShotGunFlank()) {
shoot();
}
}
ActorBlueprint PlayerBP = {
.mLoad = loadPlayer,
.mUpdate = updatePlayer
};
void pausePlayerShooting()
{
gData.mCanShoot = 0;
}
void unpausePlayerShooting()
{
gData.mCanShoot = 1;
}
void setPlayerShotRotation(double tAngle, Vector3D tCenter)
{
gData.mRotationAngle = tAngle;
gData.mRotationCenter = tCenter;
}
void addPlayerShotManual(Position p, double r)
{
addShot(p, r);
}