-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplosions.h
More file actions
84 lines (59 loc) · 2.44 KB
/
explosions.h
File metadata and controls
84 lines (59 loc) · 2.44 KB
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
//Explosion STRUCT AND ASSOCIATED FUNCTIONS
//---------------------------------------------------------------------------------------------------------------------------------------------
#ifndef EXPLOSION_H
#define EXPLOSION_H
typedef struct Explosion{
//5 char arrays to store characters of the 4 frames of the explosion plus one for the empty space
char empty[8];
char frame1[5][8];
char frame2[5][8];
char frame3[5][8];
char frame4[5][8];
int currentFrame;
int x,y;
int timeBetweenFrames; //number of game loops between each frame
int frameCounter;
}Explosion ;
void DestroyExplosion(Explosion *explosion){
free(explosion);
}
Explosion* NewExplosion(int x, int y){
Explosion *explosion = malloc(sizeof(Explosion));
char empty[8] = " ";
char frame1[5][8] = {" -.- ", " #@# ", ".#@#@#.", " -@# ", " -.- "};
char frame2[5][8] = {"*-@#*--", " -#)- ", ")-#!!* ", " -+ #* ", " *_* "};
char frame3[5][8] = {" . ", " #@ ", " .#!@# ", " @##. ", " - "};
char frame4[5][8] = {" ", " -@# "," #@. "," .- ", " "};
strcpy(explosion->empty, empty);
for(int i = 0; i < 5; i++){
strcpy(explosion->frame1[i], frame1[i]);
strcpy(explosion->frame2[i], frame2[i]);
strcpy(explosion->frame3[i], frame3[i]);
strcpy(explosion->frame4[i], frame4[i]);
}
explosion->timeBetweenFrames = 2;
explosion->frameCounter = 0;
explosion->currentFrame = 0;
explosion->x = x+3; //position is offset so x and y is in the middle of the particle
explosion->y = y-2;
return explosion;
}
void AnimateExplosion(Explosion *explosion){ //using time delay increment frame counter to draw the different frames
explosion->frameCounter += 1;
int frame = explosion->frameCounter / explosion->timeBetweenFrames;
if(explosion->frameCounter % explosion->timeBetweenFrames == 0)
{
explosion->currentFrame = frame;
}
}
//reorders the explosion array to ensure active explosions are stored at the front end of the array with no gaps
void ReorderExplosionArray(Explosion *arr[], int index, int maxExplosions){
if(index == maxExplosions-1) //if the destroyed explosion was at the end of the array do nothing
{
return;
}
for(int i = index+1; i < maxExplosions; i++){
arr[i-1] = arr[i];
}
}
#endif