gamedev-benkyokai/2.brickbreaker/src/brick.cc

68 行
1.8 KiB
C++
Raw Blame 履歴

このファイルには曖昧(ambiguous)なUnicode文字が含まれています

このファイルには、他の文字と見間違える可能性があるUnicode文字が含まれています。 それが意図的なものと考えられる場合は、この警告を無視して構いません。 それらの文字を表示するにはエスケープボタンを使用します。

#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
#include <iostream>
#include "render.hh"
#include "player.hh"
#include "ball.hh"
#include "brick.hh"
void Brick::resetBricks(Render &r, Player &p, Ball &bl) {
srand(static_cast<unsigned int>(time(nullptr)));
r.c1r = rand() % 256;
r.c1g = rand() % 256;
r.c1b = rand() % 256;
r.c2r = rand() % 256;
r.c2g = rand() % 256;
r.c2b = rand() % 256;
r.c3r = rand() % 256;
r.c3g = rand() % 256;
r.c3b = rand() % 256;
r.c4r = rand() % 256;
r.c4g = rand() % 256;
r.c4b = rand() % 256;
r.c5r = rand() % 256;
r.c5g = rand() % 256;
r.c5b = rand() % 256;
r.c6r = rand() % 256;
r.c6g = rand() % 256;
r.c6b = rand() % 256;
if (r.level > 1) {
Mix_HaltMusic();
}
std::string music = "ass/" + std::to_string(r.level) + ".ogg";
r.music = Mix_LoadMUS(music.c_str());
if (Mix_PlayMusic(r.music, -1) < 0) {
std::cout << "OGGファイルのエラー" << Mix_GetError() << '\n';
r.running = false;
TTF_CloseFont(r.font);
SDL_DestroyRenderer(r.renderer);
SDL_DestroyWindow(r.window);
SDL_Quit();
Mix_CloseAudio();
TTF_Quit();
}
for (int i = 0; i < Brick::col * Brick::row; i++) {
Brick::bricks[i] = 1;
}
bl.size -= 2;
bl.ballspeed += 1.4f;
p.player.w -= 1.4f;
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.xvelocity = 0;
bl.ball.x = r.width / 2 - (bl.size / 2);
}
void Brick::setBricks(int i) {
Brick::brick.x = (((i%Brick::col) + 1) * Brick::gaps) + ((i%Brick::col) * Brick::brick.w) - (Brick::gaps/2);
Brick::brick.y = Brick::brick.h * 3 + (((i%Brick::row) + 1) * Brick::gaps) + ((i%Brick::row) * Brick::brick.h) - (Brick::gaps/2);
}