Added a sticky paddle flag on death and new level, spacebar to (re)start game, ESC to exit, combined brick layouts (levels) into one function
This commit is contained in:
parent
bf52ead7cc
commit
6be9da289c
@ -22,7 +22,7 @@
|
||||
int loadTextures(GLuint *texture, const char *imageLoc);
|
||||
void surfaceToTexture(GLuint *texture, SDL_Surface *surface);
|
||||
|
||||
void updateScore(int *playerScore, brick *bricks, int brickCount);
|
||||
void updateScore(int *playerScore, brick *bricks, int *brickCount, int *level, ball *theBall);
|
||||
|
||||
int main(void) {
|
||||
|
||||
@ -85,12 +85,6 @@ int main(void) {
|
||||
* Creates the main renderer (tied to main window)
|
||||
*/
|
||||
|
||||
//SDL_Renderer * renderer1 = SDL_CreateRenderer(window1, -1, 0);
|
||||
//if (renderer1==NULL) {
|
||||
// fprintf(stderr, "[FAILED] Creating renderer renderer1 for window1");
|
||||
// return 3;
|
||||
//}
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); // Specifies the version of the OpenGL context
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5); // (here, 1.5) -- hello, 2003!
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); // Allows deprecated functions to be used
|
||||
@ -109,8 +103,8 @@ int main(void) {
|
||||
glShadeModel(GL_SMOOTH); // GL_FLAT for flat shading instead
|
||||
glEnable(GL_DEPTH_TEST); // Enables depth comparisons
|
||||
glEnable(GL_TEXTURE_2D); // Enables use of textures
|
||||
glAlphaFunc(GL_GREATER, 0);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0); // How we plan on treating aplha
|
||||
glEnable(GL_ALPHA_TEST); // Enables alpha testing (needed for transparent textures)
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
@ -136,45 +130,57 @@ int main(void) {
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
char subSteps = 2; // Draw every N+1 frames, thereby calculating movement more precisely
|
||||
char subSteps = 1; // Draw every N+1 frames, thereby calculating movement more precisely
|
||||
int targetFPS = 60; // Limit FPS to this value, to stop unneccessary calculations
|
||||
|
||||
char moveX=0;
|
||||
char moveX=0; // Toggled between -1, 0 and 1 by keypresses later
|
||||
|
||||
brick bricks[2048];
|
||||
int playerScore = 0;
|
||||
int level = 1;
|
||||
int playerLives = 3;
|
||||
|
||||
brick bricks[2048]; // Sets up array for the bricks to be stored in, max no. bricks is 2048
|
||||
int brickCount;
|
||||
colour brickColours[4];
|
||||
colour brickColours[7]; //brickColours[n] corresponds to the colour of a brick with type n+1
|
||||
brickColours[6] = (colour) { .r = 0.9000 /*255*/, .g = 0.9000 /*64 */, .b = 0.9000 /*167*/, .a = 1 };
|
||||
brickColours[5] = (colour) { .r = 0.8000 /*255*/, .g = 0.8000 /*64 */, .b = 0.8000 /*167*/, .a = 1 };
|
||||
brickColours[4] = (colour) { .r = 0.7000 /*255*/, .g = 0.7000 /*64 */, .b = 0.7000 /*167*/, .a = 1 };
|
||||
brickColours[3] = (colour) { .r = 1.0000 /*255*/, .g = 0.2510 /*64 */, .b = 0.6549 /*167*/, .a = 1 };
|
||||
brickColours[2] = (colour) { .r = 0.4588 /*117*/, .g = 0.5490 /*140*/, .b = 1.0000 /*255*/, .a = 1 };
|
||||
brickColours[1] = (colour) { .r = 0.3490 /*89 */, .g = 0.8706 /*222*/, .b = 1.0000 /*255*/, .a = 1 };
|
||||
brickColours[0] = (colour) { .r = 1.0000 /*255*/, .g = 0.7569 /*193*/, .b = 0.1216 /*31 */, .a = 1 };
|
||||
initialiseBricks(&bricks, &brickCount);
|
||||
initialiseBricks(&bricks, &brickCount, level); // Sets up the bricks for level one
|
||||
|
||||
colour paddleCol;
|
||||
paddleCol.r = 1.0; paddleCol.g = 1.0; paddleCol.b = 1.0; paddleCol.a = 1.0; // RGBA of paddle and ball
|
||||
|
||||
colour bgcol1; colour bgcol2;
|
||||
bgcol1.r = 0.7216; /*184*/ bgcol2.r = 0.0824; /*21 */ // RGBA values for the gradient, bgcol1 refers to the bottom colour and bgcol2 to the top
|
||||
bgcol1.g = 0.2471; /*63 */ bgcol2.g = 0.0901; /*23 */
|
||||
bgcol1.b = 0.6078; /*155*/ bgcol2.b = 0.4431; /*113*/
|
||||
bgcol1.a = 1.0000; /*255*/ bgcol2.a = 1.0000; /*255*/
|
||||
|
||||
ball theBall = {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.vX = 1.5f,
|
||||
.vX = 1.5f, // Change to desired X / Y speeds
|
||||
.vY = -5.0f,
|
||||
.initVX = theBall.vX,
|
||||
.initVY = theBall.vY,
|
||||
.radius = 4,
|
||||
.isColliding = 0,
|
||||
.stickToPaddle = 1
|
||||
};
|
||||
}; // Initialising the ball
|
||||
|
||||
paddle thePaddle = {
|
||||
.width = 50,
|
||||
.height = 10,
|
||||
.x = (winWidth/2)-(thePaddle.width/2)
|
||||
};
|
||||
}; // Initialising the paddle
|
||||
|
||||
char txtL[4] = "000";
|
||||
char txtL[4] = "000"; // Placeholder text
|
||||
char txtR[4] = "000";
|
||||
|
||||
int playerScore = 0;
|
||||
int level = 1;
|
||||
int playerLives = 3;
|
||||
|
||||
/*
|
||||
* ----------------
|
||||
* Font stuff
|
||||
@ -251,7 +257,13 @@ int main(void) {
|
||||
moveX=1;
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
theBall.stickToPaddle = 0;
|
||||
if (playerLives>0) theBall.stickToPaddle = 0;
|
||||
else {
|
||||
playerLives = 3;
|
||||
level = 1;
|
||||
theBall.stickToPaddle = 1;
|
||||
initialiseBricks(&bricks, &brickCount, level);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -279,7 +291,7 @@ int main(void) {
|
||||
sprintf(txtR, "%03d", level);
|
||||
updatePaddle(tickrate, &thePaddle, moveX, winWidth, winHeight);
|
||||
updateBall(tickrate, &theBall, &thePaddle, winWidth, winHeight, &bricks, brickCount, &playerLives);
|
||||
updateScore(&playerScore, &bricks, brickCount);
|
||||
updateScore(&playerScore, &bricks, &brickCount, &level, &theBall);
|
||||
}
|
||||
|
||||
if (step % (subSteps+1) == 0) {
|
||||
@ -302,15 +314,6 @@ int main(void) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
colour paddleCol;
|
||||
paddleCol.r = 1.0; paddleCol.g = 1.0; paddleCol.b = 1.0; paddleCol.a = 1.0;
|
||||
|
||||
colour bgcol1; colour bgcol2;
|
||||
bgcol1.r = 0.7216; /*184*/ bgcol2.r = 0.0824; /*21 */
|
||||
bgcol1.g = 0.2471; /*63 */ bgcol2.g = 0.0901; /*23 */
|
||||
bgcol1.b = 0.6078; /*155*/ bgcol2.b = 0.4431; /*113*/
|
||||
bgcol1.a = 1.0000; /*255*/ bgcol2.a = 1.0000; /*255*/
|
||||
|
||||
if (playerLives==0) {
|
||||
drawText("Game Over", font_main, textColour, (coord){ .x=0, .y=-128});
|
||||
}
|
||||
@ -396,9 +399,10 @@ void surfaceToTexture(GLuint *texture, SDL_Surface *surface) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
void updateScore(int *playerScore, brick *bricks, int brickCount) {
|
||||
void updateScore(int *playerScore, brick *bricks, int *brickCount, int *level, ball *theBall) {
|
||||
*playerScore = 0;
|
||||
for (int i = 0; i < brickCount; i++) {
|
||||
char allBricksDestroyed = 1;
|
||||
for (int i = 0; i < *brickCount; i++) {
|
||||
if (bricks[i].destroyed == 1) {
|
||||
switch (bricks[i].brickType) {
|
||||
case 1:
|
||||
@ -414,6 +418,13 @@ void updateScore(int *playerScore, brick *bricks, int brickCount) {
|
||||
*playerScore += 7;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
allBricksDestroyed = 0;
|
||||
}
|
||||
}
|
||||
if (allBricksDestroyed==1) {
|
||||
*level += 1;
|
||||
initialiseBricks(bricks, brickCount, *level);
|
||||
theBall->stickToPaddle = 1;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,9 @@
|
||||
#include "include/structs.h"
|
||||
|
||||
void initialiseBricks(brick *bricks, int *brickCount) {
|
||||
void initialiseBricks(brick *bricks, int *brickCount, int level) {
|
||||
|
||||
switch (level) {
|
||||
case 1:
|
||||
bricks[0] = (brick) { .brickType = 1, .x = 17, .y = 130, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[1] = (brick) { .brickType = 1, .x = 49, .y = 130, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[2] = (brick) { .brickType = 1, .x = 81, .y = 130, .width = 30, .height = 10, .destroyed = 0 };
|
||||
@ -67,7 +70,7 @@ void initialiseBricks(brick *bricks, int *brickCount) {
|
||||
bricks[63] = (brick) { .brickType = 3, .x = 241, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[64] = (brick) { .brickType = 3, .x = 273, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[65] = (brick) { .brickType = 3, .x = 305, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[66] = (brick) { .brickType = 3, .x = 337, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[66] = (brick) { .brickType = 5, .x = 337, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[67] = (brick) { .brickType = 3, .x = 369, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[68] = (brick) { .brickType = 3, .x = 401, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[69] = (brick) { .brickType = 3, .x = 433, .y = 178, .width = 30, .height = 10, .destroyed = 0 };
|
||||
@ -87,7 +90,7 @@ void initialiseBricks(brick *bricks, int *brickCount) {
|
||||
bricks[83] = (brick) { .brickType = 3, .x = 433, .y = 190, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[84] = (brick) { .brickType = 4, .x = 17, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[85] = (brick) { .brickType = 4, .x = 49, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[86] = (brick) { .brickType = 4, .x = 81, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[86] = (brick) { .brickType = 6, .x = 81, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[87] = (brick) { .brickType = 4, .x = 113, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[88] = (brick) { .brickType = 4, .x = 145, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[89] = (brick) { .brickType = 4, .x = 177, .y = 202, .width = 30, .height = 10, .destroyed = 0 };
|
||||
@ -104,7 +107,7 @@ void initialiseBricks(brick *bricks, int *brickCount) {
|
||||
bricks[100] = (brick) { .brickType = 4, .x = 81, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[101] = (brick) { .brickType = 4, .x = 113, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[102] = (brick) { .brickType = 4, .x = 145, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[103] = (brick) { .brickType = 4, .x = 177, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[103] = (brick) { .brickType = 7, .x = 177, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[104] = (brick) { .brickType = 4, .x = 209, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[105] = (brick) { .brickType = 4, .x = 241, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[106] = (brick) { .brickType = 4, .x = 273, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
@ -113,10 +116,9 @@ void initialiseBricks(brick *bricks, int *brickCount) {
|
||||
bricks[109] = (brick) { .brickType = 4, .x = 369, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[110] = (brick) { .brickType = 4, .x = 401, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
bricks[111] = (brick) { .brickType = 4, .x = 433, .y = 214, .width = 30, .height = 10, .destroyed = 0 };
|
||||
*brickCount = 112;
|
||||
}
|
||||
|
||||
void initialiseBricks2(brick *bricks, int *brickCount) {
|
||||
*brickCount = 1;
|
||||
break;
|
||||
case 2:
|
||||
bricks[0] = (brick) { .brickType = 1, .x = 290, .y = 240 - 370, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[1] = (brick) { .brickType = 1, .x = 280, .y = 240 - 370, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[2] = (brick) { .brickType = 1, .x = 270, .y = 240 - 370, .width = 8, .height = 8, .destroyed = 0 };
|
||||
@ -134,7 +136,7 @@ void initialiseBricks2(brick *bricks, int *brickCount) {
|
||||
bricks[14] = (brick) { .brickType = 1, .x = 260, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[15] = (brick) { .brickType = 1, .x = 250, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[16] = (brick) { .brickType = 1, .x = 240, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[17] = (brick) { .brickType = 1, .x = 230, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[17] = (brick) { .brickType = 5, .x = 230, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[18] = (brick) { .brickType = 1, .x = 220, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[19] = (brick) { .brickType = 1, .x = 210, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[20] = (brick) { .brickType = 1, .x = 200, .y = 240 - 360, .width = 8, .height = 8, .destroyed = 0 };
|
||||
@ -569,7 +571,7 @@ void initialiseBricks2(brick *bricks, int *brickCount) {
|
||||
bricks[449] = (brick) { .brickType = 1, .x = 180, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[450] = (brick) { .brickType = 1, .x = 170, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[451] = (brick) { .brickType = 1, .x = 160, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[452] = (brick) { .brickType = 1, .x = 150, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[452] = (brick) { .brickType = 7, .x = 150, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[453] = (brick) { .brickType = 1, .x = 140, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[454] = (brick) { .brickType = 1, .x = 130, .y = 240 - 140, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[455] = (brick) { .brickType = 1, .x = 340, .y = 240 - 130, .width = 8, .height = 8, .destroyed = 0 };
|
||||
@ -1062,7 +1064,7 @@ void initialiseBricks2(brick *bricks, int *brickCount) {
|
||||
bricks[942] = (brick) { .brickType = 2, .x = 330, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[943] = (brick) { .brickType = 2, .x = 320, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[944] = (brick) { .brickType = 2, .x = 310, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[945] = (brick) { .brickType = 2, .x = 300, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[945] = (brick) { .brickType = 6, .x = 300, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[946] = (brick) { .brickType = 2, .x = 280, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[947] = (brick) { .brickType = 2, .x = 220, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[948] = (brick) { .brickType = 2, .x = 210, .y = 240 - 60, .width = 8, .height = 8, .destroyed = 0 };
|
||||
@ -1100,4 +1102,121 @@ void initialiseBricks2(brick *bricks, int *brickCount) {
|
||||
bricks[980] = (brick) { .brickType = 2, .x = 280, .y = 240 - 10, .width = 8, .height = 8, .destroyed = 0 };
|
||||
bricks[981] = (brick) { .brickType = 2, .x = 270, .y = 240 - 10, .width = 8, .height = 8, .destroyed = 0 };
|
||||
*brickCount = 982;
|
||||
break;
|
||||
case 3:
|
||||
bricks[0] = (brick) { .brickType = 5, .x = 17, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[1] = (brick) { .brickType = 1, .x = 49, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[2] = (brick) { .brickType = 1, .x = 81, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[3] = (brick) { .brickType = 1, .x = 113, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[4] = (brick) { .brickType = 1, .x = 145, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[5] = (brick) { .brickType = 1, .x = 177, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[6] = (brick) { .brickType = 1, .x = 209, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[7] = (brick) { .brickType = 1, .x = 241, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[8] = (brick) { .brickType = 1, .x = 273, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[9] = (brick) { .brickType = 1, .x = 305, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[10] = (brick) { .brickType = 1, .x = 337, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[11] = (brick) { .brickType = 1, .x = 369, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[12] = (brick) { .brickType = 1, .x = 401, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[13] = (brick) { .brickType = 1, .x = 433, .y = 130, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[14] = (brick) { .brickType = 1, .x = 17, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[15] = (brick) { .brickType = 1, .x = 49, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[16] = (brick) { .brickType = 1, .x = 81, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[17] = (brick) { .brickType = 1, .x = 113, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[18] = (brick) { .brickType = 1, .x = 145, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[19] = (brick) { .brickType = 1, .x = 177, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[20] = (brick) { .brickType = 6, .x = 209, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[21] = (brick) { .brickType = 1, .x = 241, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[22] = (brick) { .brickType = 1, .x = 273, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[23] = (brick) { .brickType = 1, .x = 305, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[24] = (brick) { .brickType = 1, .x = 337, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[25] = (brick) { .brickType = 1, .x = 369, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[26] = (brick) { .brickType = 1, .x = 401, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[27] = (brick) { .brickType = 1, .x = 433, .y = 142, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[28] = (brick) { .brickType = 2, .x = 17, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[29] = (brick) { .brickType = 2, .x = 49, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[30] = (brick) { .brickType = 2, .x = 81, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[31] = (brick) { .brickType = 2, .x = 113, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[32] = (brick) { .brickType = 2, .x = 145, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[33] = (brick) { .brickType = 2, .x = 177, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[34] = (brick) { .brickType = 2, .x = 209, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[35] = (brick) { .brickType = 2, .x = 241, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[36] = (brick) { .brickType = 2, .x = 273, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[37] = (brick) { .brickType = 7, .x = 305, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[38] = (brick) { .brickType = 2, .x = 337, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[39] = (brick) { .brickType = 2, .x = 369, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[40] = (brick) { .brickType = 2, .x = 401, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[41] = (brick) { .brickType = 2, .x = 433, .y = 154, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[42] = (brick) { .brickType = 2, .x = 17, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[43] = (brick) { .brickType = 2, .x = 49, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[44] = (brick) { .brickType = 2, .x = 81, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[45] = (brick) { .brickType = 2, .x = 113, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[46] = (brick) { .brickType = 2, .x = 145, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[47] = (brick) { .brickType = 2, .x = 177, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[48] = (brick) { .brickType = 2, .x = 209, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[49] = (brick) { .brickType = 2, .x = 241, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[50] = (brick) { .brickType = 2, .x = 273, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[51] = (brick) { .brickType = 2, .x = 305, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[52] = (brick) { .brickType = 2, .x = 337, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[53] = (brick) { .brickType = 2, .x = 369, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[54] = (brick) { .brickType = 2, .x = 401, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[55] = (brick) { .brickType = 2, .x = 433, .y = 166, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[56] = (brick) { .brickType = 3, .x = 17, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[57] = (brick) { .brickType = 3, .x = 49, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[58] = (brick) { .brickType = 3, .x = 81, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[59] = (brick) { .brickType = 3, .x = 113, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[60] = (brick) { .brickType = 3, .x = 145, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[61] = (brick) { .brickType = 3, .x = 177, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[62] = (brick) { .brickType = 3, .x = 209, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[63] = (brick) { .brickType = 3, .x = 241, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[64] = (brick) { .brickType = 3, .x = 273, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[65] = (brick) { .brickType = 3, .x = 305, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[66] = (brick) { .brickType = 3, .x = 337, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[67] = (brick) { .brickType = 3, .x = 369, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[68] = (brick) { .brickType = 3, .x = 401, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[69] = (brick) { .brickType = 3, .x = 433, .y = 178, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[70] = (brick) { .brickType = 3, .x = 17, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[71] = (brick) { .brickType = 3, .x = 49, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[72] = (brick) { .brickType = 3, .x = 81, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[73] = (brick) { .brickType = 3, .x = 113, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[74] = (brick) { .brickType = 3, .x = 145, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[75] = (brick) { .brickType = 3, .x = 177, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[76] = (brick) { .brickType = 3, .x = 209, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[77] = (brick) { .brickType = 3, .x = 241, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[78] = (brick) { .brickType = 3, .x = 273, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[79] = (brick) { .brickType = 3, .x = 305, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[80] = (brick) { .brickType = 3, .x = 337, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[81] = (brick) { .brickType = 3, .x = 369, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[82] = (brick) { .brickType = 3, .x = 401, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[83] = (brick) { .brickType = 3, .x = 433, .y = 190, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[84] = (brick) { .brickType = 4, .x = 17, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[85] = (brick) { .brickType = 4, .x = 49, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[86] = (brick) { .brickType = 4, .x = 81, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[87] = (brick) { .brickType = 4, .x = 113, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[88] = (brick) { .brickType = 4, .x = 145, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[89] = (brick) { .brickType = 4, .x = 177, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[90] = (brick) { .brickType = 4, .x = 209, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[91] = (brick) { .brickType = 4, .x = 241, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[92] = (brick) { .brickType = 4, .x = 273, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[93] = (brick) { .brickType = 4, .x = 305, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[94] = (brick) { .brickType = 4, .x = 337, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[95] = (brick) { .brickType = 4, .x = 369, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[96] = (brick) { .brickType = 4, .x = 401, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[97] = (brick) { .brickType = 4, .x = 433, .y = 202, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[98] = (brick) { .brickType = 4, .x = 17, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[99] = (brick) { .brickType = 4, .x = 49, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[100] = (brick) { .brickType = 4, .x = 81, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[101] = (brick) { .brickType = 4, .x = 113, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[102] = (brick) { .brickType = 4, .x = 145, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[103] = (brick) { .brickType = 4, .x = 177, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[104] = (brick) { .brickType = 4, .x = 209, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[105] = (brick) { .brickType = 4, .x = 241, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[106] = (brick) { .brickType = 4, .x = 273, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[107] = (brick) { .brickType = 4, .x = 305, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[108] = (brick) { .brickType = 4, .x = 337, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[109] = (brick) { .brickType = 4, .x = 369, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[110] = (brick) { .brickType = 4, .x = 401, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
bricks[111] = (brick) { .brickType = 4, .x = 433, .y = 214, .width = 32, .height = 10, .destroyed = 0 };
|
||||
*brickCount = 112;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1,2 +1 @@
|
||||
void initialiseBricks(brick *bricks, int *brickCount);
|
||||
void initialiseBricks2(brick *bricks, int *brickCount);
|
||||
void initialiseBricks(brick *bricks, int *brickCount, int level);
|
||||
@ -21,10 +21,10 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth,
|
||||
double paddleRY = 20 - (double)(winHeight / 2); // (Default is absolute, offset from the top left corner of window)
|
||||
|
||||
coord paddleQ[4] = {
|
||||
{ .x = paddleRX,.y = paddleRY }, // Sets up a quad (coord array) to pass to vertexWithinQuad function later
|
||||
{ .x = paddleRX,.y = paddleRY - thePaddle->height },
|
||||
{ .x = paddleRX + thePaddle->width,.y = paddleRY - thePaddle->height },
|
||||
{ .x = paddleRX + thePaddle->width,.y = paddleRY },
|
||||
{ .x = paddleRX, .y = paddleRY }, // Sets up a quad (coord array) to pass to vertexWithinQuad function later
|
||||
{ .x = paddleRX, .y = paddleRY - thePaddle->height },
|
||||
{ .x = paddleRX + thePaddle->width, .y = paddleRY - thePaddle->height },
|
||||
{ .x = paddleRX + thePaddle->width, .y = paddleRY },
|
||||
};
|
||||
|
||||
// Collision with paddle
|
||||
@ -74,10 +74,10 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth,
|
||||
|
||||
if (bricks[i].destroyed == 0) {
|
||||
coord brick[4] = {
|
||||
{ .x = bricks[i].x - (winWidth / 2),.y = bricks[i].y },
|
||||
{ .x = bricks[i].x - (winWidth / 2),.y = bricks[i].y - bricks[i].height },
|
||||
{ .x = bricks[i].x - (winWidth / 2) + bricks[i].width,.y = bricks[i].y - bricks[i].height },
|
||||
{ .x = bricks[i].x - (winWidth / 2) + bricks[i].width,.y = bricks[i].y },
|
||||
{ .x = bricks[i].x - (winWidth / 2), .y = bricks[i].y }, // Set up quad for brick
|
||||
{ .x = bricks[i].x - (winWidth / 2), .y = bricks[i].y - bricks[i].height },
|
||||
{ .x = bricks[i].x - (winWidth / 2) + bricks[i].width, .y = bricks[i].y - bricks[i].height },
|
||||
{ .x = bricks[i].x - (winWidth / 2) + bricks[i].width, .y = bricks[i].y },
|
||||
};
|
||||
|
||||
for (int j = 0, k = 3; j < 4; j++, k++) {
|
||||
@ -96,6 +96,17 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth,
|
||||
theBall->vY *= -1.0;
|
||||
}
|
||||
bricks[i].destroyed = 1;
|
||||
switch (bricks[i].brickType) {
|
||||
case 5:
|
||||
thePaddle->width *= 1.5;
|
||||
break;
|
||||
case 6:
|
||||
theBall->vY *= 0.5;
|
||||
break;
|
||||
case 7:
|
||||
theBall->radius *= 1.6;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -110,8 +121,7 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth,
|
||||
theBall->vY *= -1.0;
|
||||
}
|
||||
if (ballNY < (-1.0*winHeight / 2)) { // Collision with floor
|
||||
theBall->x = 0;
|
||||
theBall->y = 0;
|
||||
theBall->stickToPaddle = 1;
|
||||
theBall->vX = theBall->initVX;
|
||||
theBall->vY = theBall->initVY;
|
||||
*playerLives -= 1;
|
||||
@ -123,6 +133,9 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth,
|
||||
theBall->y += theBall->vY * 0.1 * tickrate;
|
||||
}
|
||||
else {
|
||||
|
||||
// If the ball is 'stuck to paddle' (i.e. post-death/level change)
|
||||
|
||||
theBall->x = thePaddle->x - (double)(winWidth / 2) + (thePaddle->width) / 2;
|
||||
theBall->y = 26 - (double)(winHeight / 2);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user