ソフトロックを無理にした
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
brickbreaker
|
||||||
2
main.cc
2
main.cc
@@ -60,7 +60,7 @@ int main(void) {
|
|||||||
if (!r.gameover) {
|
if (!r.gameover) {
|
||||||
r.update(r, p, bl, br);
|
r.update(r, p, bl, br);
|
||||||
}
|
}
|
||||||
r.input(p);
|
r.input(r, p, bl, br);
|
||||||
r.render(p, bl, br);
|
r.render(p, bl, br);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class Ball {
|
|||||||
|
|
||||||
float xvelocity;
|
float xvelocity;
|
||||||
float yvelocity;
|
float yvelocity;
|
||||||
|
float xvelSave;
|
||||||
|
float yvelSave;
|
||||||
|
|
||||||
SDL_Rect ball;
|
SDL_Rect ball;
|
||||||
|
|
||||||
|
|||||||
38
src/brick.cc
38
src/brick.cc
@@ -29,7 +29,6 @@ void Brick::resetBricks(Render &r, Player &p, Ball &bl) {
|
|||||||
r.c6g = rand() % 256;
|
r.c6g = rand() % 256;
|
||||||
r.c6b = rand() % 256;
|
r.c6b = rand() % 256;
|
||||||
|
|
||||||
|
|
||||||
if (r.level > 1) {
|
if (r.level > 1) {
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
}
|
}
|
||||||
@@ -51,13 +50,42 @@ void Brick::resetBricks(Render &r, Player &p, Ball &bl) {
|
|||||||
Brick::bricks[i] = 1;
|
Brick::bricks[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bl.size -= 2;
|
int pw = 620 / 4;
|
||||||
bl.ballspeed += 1.4f;
|
|
||||||
p.player.w -= 1.4f;
|
if (r.level == 1) {
|
||||||
|
bl.size = 16;
|
||||||
|
bl.ballspeed = 8.f;
|
||||||
|
p.player.w = pw;
|
||||||
|
} else if (r.level == 2) {
|
||||||
|
bl.size = 14;
|
||||||
|
bl.ballspeed = 9.4f;
|
||||||
|
p.player.w = pw - 1.4;
|
||||||
|
} else if (r.level == 3) {
|
||||||
|
bl.size = 12;
|
||||||
|
bl.ballspeed = 10.8f;
|
||||||
|
p.player.w = pw - (1.4 * 2);
|
||||||
|
} else if (r.level == 4) {
|
||||||
|
bl.size = 10;
|
||||||
|
bl.ballspeed = 12.2f;
|
||||||
|
p.player.w = pw - (1.4 * 3);
|
||||||
|
} else if (r.level == 5) {
|
||||||
|
bl.size = 8;
|
||||||
|
bl.ballspeed = 13.6f;
|
||||||
|
p.player.w = pw - (1.4 * 4);
|
||||||
|
} else if (r.level == 6) {
|
||||||
|
bl.size = 6;
|
||||||
|
bl.ballspeed = 15.f;
|
||||||
|
p.player.w = pw - (1.4 * 5);
|
||||||
|
} else if (r.level == 7) {
|
||||||
|
bl.size = 4;
|
||||||
|
bl.ballspeed = 16.4f;
|
||||||
|
p.player.w = pw - (1.4 * 6);
|
||||||
|
}
|
||||||
|
|
||||||
p.player.x = (r.width / 2) - (p.player.w / 2);
|
p.player.x = (r.width / 2) - (p.player.w / 2);
|
||||||
bl.ball.y = p.player.y - (p.player.h * 4);
|
|
||||||
bl.yvelocity = bl.ballspeed / 2;
|
bl.yvelocity = bl.ballspeed / 2;
|
||||||
bl.xvelocity = 0;
|
bl.xvelocity = 0;
|
||||||
|
bl.ball.y = p.player.y - (p.player.h * 4);
|
||||||
bl.ball.x = r.width / 2 - (bl.size / 2);
|
bl.ball.x = r.width / 2 - (bl.size / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Player {
|
|||||||
int scoreMultiplier = 1;
|
int scoreMultiplier = 1;
|
||||||
int livesCount = 3;
|
int livesCount = 3;
|
||||||
|
|
||||||
Player(Render& r) {
|
Player(Render &r) {
|
||||||
player.h = 12;
|
player.h = 12;
|
||||||
player.y = r.height - player.h - 32;
|
player.y = r.height - player.h - 32;
|
||||||
player.w = r.width / 4;
|
player.w = r.width / 4;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "player.hh"
|
#include "player.hh"
|
||||||
#include "brick.hh"
|
#include "brick.hh"
|
||||||
|
|
||||||
#define PI 3.14
|
#define DEBUG false
|
||||||
|
|
||||||
void Render::gameOver(Player &p, Brick &br, bool winner) {
|
void Render::gameOver(Player &p, Brick &br, bool winner) {
|
||||||
if (winner) {
|
if (winner) {
|
||||||
@@ -41,10 +41,16 @@ void Render::update(Render &r, Player &p, Ball &bl, Brick &br) {
|
|||||||
if (SDL_HasIntersection(&bl.ball, &p.player)) {
|
if (SDL_HasIntersection(&bl.ball, &p.player)) {
|
||||||
double rel = (p.player.x + ((float)p.player.w/2)) - ((float)bl.ball.x + ((float)bl.size/2));
|
double rel = (p.player.x + ((float)p.player.w/2)) - ((float)bl.ball.x + ((float)bl.size/2));
|
||||||
double norm = rel / ((float)p.player.w/2);
|
double norm = rel / ((float)p.player.w/2);
|
||||||
double bounce = norm * (5*PI/12);
|
double bounce = norm * (5 * M_PI / 12);
|
||||||
|
if (fabs(bounce - bounceSave) <= .04) bounce += .4;
|
||||||
|
|
||||||
bl.yvelocity = -bl.ballspeed * cos(bounce);
|
bl.yvelocity = -bl.ballspeed * cos(bounce);
|
||||||
bl.xvelocity = bl.ballspeed * -sin(bounce);
|
bl.xvelocity = bl.ballspeed * -sin(bounce);
|
||||||
|
|
||||||
|
if (bl.yvelocity == bl.yvelSave || -bl.yvelocity == bl.yvelSave) bl.xvelocity += .4f;
|
||||||
|
bl.yvelSave = bl.yvelocity;
|
||||||
|
|
||||||
|
bounceSave = bounce;
|
||||||
p.scoreMultiplier = 1;
|
p.scoreMultiplier = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,9 +64,12 @@ void Render::update(Render &r, Player &p, Ball &bl, Brick &br) {
|
|||||||
}
|
}
|
||||||
if (bl.ball.x <= 0 || bl.ball.x + bl.size >= Render::width) {
|
if (bl.ball.x <= 0 || bl.ball.x + bl.size >= Render::width) {
|
||||||
bl.xvelocity = -bl.xvelocity;
|
bl.xvelocity = -bl.xvelocity;
|
||||||
|
if (bl.xvelocity == bl.xvelSave || -bl.xvelocity == bl.xvelSave) bl.yvelocity += .4f;
|
||||||
|
bl.xvelSave = bl.xvelocity;
|
||||||
}
|
}
|
||||||
bl.ball.x += bl.xvelocity;
|
bl.ball.x += bl.xvelocity;
|
||||||
bl.ball.y += bl.yvelocity;
|
bl.ball.y += bl.yvelocity;
|
||||||
|
|
||||||
if (p.player.x < 0) {
|
if (p.player.x < 0) {
|
||||||
p.player.x = 0;
|
p.player.x = 0;
|
||||||
}
|
}
|
||||||
@@ -112,7 +121,7 @@ void Render::update(Render &r, Player &p, Ball &bl, Brick &br) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::input(Player &p) {
|
void Render::input(Render &r, Player &p, Ball &bl, Brick &br) {
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
const Uint8 *keystates = SDL_GetKeyboardState(NULL);
|
const Uint8 *keystates = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
@@ -123,6 +132,56 @@ void Render::input(Player &p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keystates[SDL_SCANCODE_Q]) Render::running = false;
|
if (keystates[SDL_SCANCODE_Q]) Render::running = false;
|
||||||
|
#if DEBUG
|
||||||
|
if (keystates[SDL_SCANCODE_E]) p.livesCount = 3;
|
||||||
|
if (keystates[SDL_SCANCODE_R]) {
|
||||||
|
if (level <= 7) {
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
bl.resetBall(r, p);
|
||||||
|
gameover = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_O]) {
|
||||||
|
bl.ball.x = 250.f;
|
||||||
|
bl.ball.y = 400.f;
|
||||||
|
bl.xvelocity = 0.f;
|
||||||
|
bl.yvelocity = 8.f;
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_P]) {
|
||||||
|
bl.ball.x = 250.f;
|
||||||
|
bl.ball.y = 400.f;
|
||||||
|
bl.xvelocity = 8.f;
|
||||||
|
bl.yvelocity = 0.f;
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_1]) {
|
||||||
|
Render::level = 1;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_2]) {
|
||||||
|
Render::level = 2;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_3]) {
|
||||||
|
Render::level = 3;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_4]) {
|
||||||
|
Render::level = 4;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_5]) {
|
||||||
|
Render::level = 5;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_6]) {
|
||||||
|
Render::level = 6;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
if (keystates[SDL_SCANCODE_7]) {
|
||||||
|
Render::level = 7;
|
||||||
|
br.resetBricks(r, p, bl);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (!Render::gameover) {
|
if (!Render::gameover) {
|
||||||
if (keystates[SDL_SCANCODE_LEFT]) p.player.x -= Render::xpos;
|
if (keystates[SDL_SCANCODE_LEFT]) p.player.x -= Render::xpos;
|
||||||
if (keystates[SDL_SCANCODE_RIGHT]) p.player.x += Render::xpos;
|
if (keystates[SDL_SCANCODE_RIGHT]) p.player.x += Render::xpos;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Render {
|
|||||||
Mix_Music* music;
|
Mix_Music* music;
|
||||||
|
|
||||||
void update(Render &r, Player &p, Ball &bl, Brick &br);
|
void update(Render &r, Player &p, Ball &bl, Brick &br);
|
||||||
void input(Player &p);
|
void input(Render &r, Player &p, Ball &bl, Brick &br);
|
||||||
void render(Player &p, Ball &bl, Brick &br);
|
void render(Player &p, Ball &bl, Brick &br);
|
||||||
|
|
||||||
Render() {
|
Render() {
|
||||||
@@ -47,6 +47,7 @@ class Render {
|
|||||||
private:
|
private:
|
||||||
void gameOver(Player &p, Brick &br, bool winner);
|
void gameOver(Player &p, Brick &br, bool winner);
|
||||||
void write(Player &p, Brick &br, std::string text, int x, int y);
|
void write(Player &p, Brick &br, std::string text, int x, int y);
|
||||||
|
double bounceSave;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user