-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise.c
63 lines (51 loc) · 1.43 KB
/
noise.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
#include "noise.h"
#include <tari/soundeffect.h>
#include <tari/timer.h>
#include <tari/math.h>
typedef struct {
Duration mNow;
Duration mDuration;
int mSFX;
int mAnimation;
} Noise;
static struct {
TextureData mTexture;
int mSoundEffect;
int mIsActive;
} gData;
void loadScreenNoise() {
gData.mTexture = loadTexture("assets/effects/NOISE.pkg");
gData.mSoundEffect = loadSoundEffect("assets/sfx/noise/noise.wav");
gData.mIsActive = 0;
}
static void stopScreenNoise(Noise* e) {
stopSoundEffect(e->mSFX);
removeHandledAnimation(e->mAnimation);
freeMemory(e);
gData.mIsActive = 0;
}
static void updateScreenNoise(void* tCaller) {
Noise* e = tCaller;
int dx = randfromInteger(-100, 100);
int dy = randfromInteger(-100, 100);
Position p = makePosition(-200 + dx, -200 + dy, 17);
setAnimationPosition(e->mAnimation, p);
if (handleDurationAndCheckIfOver(&e->mNow, e->mDuration)) {
stopScreenNoise(e);
}
else {
addTimerCB(0, updateScreenNoise, e);
}
}
void addScreenNoise(Duration d)
{
if (gData.mIsActive) return;
Noise* e = allocMemory(sizeof(Noise));
e->mNow = 0;
e->mDuration = d;
e->mAnimation = playAnimationLoop(makePosition(-100, -100, 15), &gData.mTexture, createOneFrameAnimation(), makeRectangleFromTexture(gData.mTexture));
setAnimationSize(e->mAnimation, makePosition(1024, 1024, 1), makePosition(0, 0, 0));
e->mSFX = playSoundEffect(gData.mSoundEffect);
addTimerCB(0, updateScreenNoise, e);
gData.mIsActive = 1;
}