-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.pde
More file actions
165 lines (135 loc) · 4.89 KB
/
Projectile.pde
File metadata and controls
165 lines (135 loc) · 4.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
COMP 3490 Fall 2022
Assignment 3
Tara Boulanger
7922331
Projectile
This is the file containing the code to create each of the individual
projectiles in a string fire. Their color and direction is different based
on who's shooting.
*/
public class Projectile {
//Center location of this fireball
int centerX;
int centerY;
final int PROJECTILE_Z = NEAR+19; //Z location of it
final color FILL_COLOR = color(0.88,0.78,0.6); //Beige for before textures
final int SIZE = 20;
//2D boundaries
final int TOP_BOUNDARY = 0;
final int BOTTOM_BOUNDARY = -height;
//3D boundaries
final int TOP_BOUNDARY_3D = height/4;
final int BOTTOM_BOUNDARY_3D = -height*4/5;
//How fast it moves
final int MOVE_FACTOR = 4;
boolean moving;
boolean alive;
boolean enemy;
//The radius of this fireball
float radius = pow(SIZE/2,2);
//Texture things
final int NUM_FRAMES = 8;
final float ANIMATION_PER_FRAME = 1.0/10.0;
PImage[] enemyFireMove = new PImage[NUM_FRAMES];
PImage[] blueFireMove = new PImage[NUM_FRAMES];
int frameIndex = 0;
float frame = 0;
int sceneCount = 0;
//Constructor for this fireball. Takes in the starting location and whether it's
//an enemy projectile or not.
Projectile ( int centerX, int centerY, boolean enemy ) {
this.centerX = centerX;
this.centerY = centerY;
alive = true;
this.enemy = enemy;
setupTextures(); //Setup the textures of the fireball
}//end Projectile constructor
//Used for moving the projectile, either up or down depending on if it's an enemy
//fireball or not. It takes in nothing and returns nothing.
void moveProjectile() {
//If it's alive
if ( alive ) {
//If it's an enemy's projectile, move down. Blue's goes up
if ( enemy ) {
centerY -= MOVE_FACTOR;
} else {
centerY += MOVE_FACTOR;
}//end if-else
}//end if
}//end moveProjectile
//Used for drawing the fireball in 2D. Takes in nothing, returns nothing.
//The image changes based off of whether it's Grey's or Blue's. Commented
//out code is used for the old fireballs.
void drawProjectile2D() {
/*beginShape(QUAD);
fill(FILL_COLOR);
vertex(centerX-SIZE/2,centerY-SIZE/2); //Top left
vertex(centerX+SIZE/2,centerY-SIZE/2); //Top right
vertex(centerX+SIZE/2,centerY+SIZE/2); //Bottom right
vertex(centerX-SIZE/2,centerY+SIZE/2); //Bottom left
endShape();*/
if ( enemy ) {
image( enemyFireMove[frameIndex] , centerX-SIZE/2 , centerY-SIZE/2 , SIZE , SIZE );
} else {
image( blueFireMove[frameIndex] , centerX-SIZE/2 , centerY-SIZE/2 , SIZE , SIZE );
}//end if-else
}//end drawProjectile2D
//Used for drawing the fireball in 3D. Takes in nothing, returns nothing.
//The image changes based off of whether it's Grey's or Blue's. Commented
//out code is used for the old fireballs.
void drawProjectile3D() {
/*beginShape(QUAD);
fill(FILL_COLOR);
vertex(centerX-SIZE/2,centerY-SIZE/2,PROJECTILE_Z); //Top left
vertex(centerX+SIZE/2,centerY-SIZE/2,PROJECTILE_Z); //Top right
vertex(centerX+SIZE/2,centerY+SIZE/2,PROJECTILE_Z); //Bottom right
vertex(centerX-SIZE/2,centerY+SIZE/2,PROJECTILE_Z); //Bottom left
endShape();*/
if ( enemy ) {
image( enemyFireMove[frameIndex] , centerX-SIZE/2 , centerY-SIZE/2 , SIZE , SIZE );
} else {
image( blueFireMove[frameIndex] , centerX-SIZE/2 , centerY-SIZE/2 , SIZE , SIZE );
}//end if-else
}//end drawProjectile3D
//Used for both moving the fireballs and checking if it's alive or not. Takes
//nothing, gives nothing.
void run() {
moveProjectile();
living();
}//end run
//Used to check if the projectile is still alive, depends on 2D and 3D.
//Takes in nothing, returns nothing.
void living() {
if ( doProjection ) {
if ( centerY < BOTTOM_BOUNDARY_3D ) alive = false;
if ( centerY > TOP_BOUNDARY_3D ) alive = false;
} else {
if ( centerY < BOTTOM_BOUNDARY ) alive = false;
if ( centerY > TOP_BOUNDARY ) alive = false;
}//end if-else
}//end borders
//Used to setup the textures of the fireballs. Depends on if it's Grey or Blue
//shooting. Gives nothing, takes nothing.
void setupTextures() {
for ( int i=1; i<=NUM_FRAMES; i++ ) {
if ( enemy ) {
enemyFireMove[i-1] = loadImage("ep" + i + ".png");
} else {
blueFireMove[i-1] = loadImage("cp" + i + ".png");
}//end if-else
}//end for
}//end setupTextures
//Used to get the right frames for each of the fireballs at a specific point.
void updateAnimation() {
frame = ( frame + ANIMATION_PER_FRAME ) % NUM_FRAMES;
frameIndex = (int)frame;
if ( frameIndex == 0 ) {
sceneCount = ( sceneCount+1 ) % NUM_FRAMES;
}//end if
}//end updateAnimation
//Updates the state of the fireball.
void dead() {
alive = false;
}//end dead
}//end Projectile class