77 行
1.6 KiB
C++
77 行
1.6 KiB
C++
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_ttf.h>
|
|
#include <SDL2/SDL_mixer.h>
|
|
#include <iostream>
|
|
|
|
#include "src/render.hh"
|
|
#include "src/ball.hh"
|
|
#include "src/player.hh"
|
|
#include "src/brick.hh"
|
|
|
|
int main(void) {
|
|
Render r;
|
|
Player p(r);
|
|
Ball bl(r, p);
|
|
Brick br(r);
|
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
|
std::cout << "SDL_Init()に失敗" << '\n';
|
|
return -1;
|
|
}
|
|
|
|
if (SDL_CreateWindowAndRenderer(r.width, r.height, 0, &r.window, &r.renderer) < 0) {
|
|
std::cout << "SDL_CreateWindowAndRenderer()に失敗" << '\n';
|
|
SDL_Quit();
|
|
return -1;
|
|
}
|
|
|
|
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
|
|
std::cout << "Mix_OpenAudio()に失敗" << '\n';
|
|
SDL_DestroyRenderer(r.renderer);
|
|
SDL_DestroyWindow(r.window);
|
|
SDL_Quit();
|
|
return -1;
|
|
}
|
|
|
|
SDL_SetWindowTitle(r.window, "ブリックブレイカー");
|
|
|
|
TTF_Init();
|
|
r.font = TTF_OpenFont("font.ttf", r.fontsize);
|
|
if (!r.font) {
|
|
std::cout << "フォントを読込に失敗" << '\n';
|
|
SDL_DestroyRenderer(r.renderer);
|
|
SDL_DestroyWindow(r.window);
|
|
Mix_CloseAudio();
|
|
SDL_Quit();
|
|
return -1;
|
|
}
|
|
|
|
static int lastTime = 0;
|
|
br.resetBricks(r, p, bl);
|
|
|
|
while (r.running) {
|
|
r.lastFrame = SDL_GetTicks();
|
|
if (r.lastFrame >= lastTime + 1000) {
|
|
lastTime = r.lastFrame;
|
|
r.fps = r.frameCount;
|
|
r.frameCount = 0;
|
|
}
|
|
|
|
if (!r.gameover) {
|
|
r.update(r, p, bl, br);
|
|
}
|
|
r.input(p);
|
|
r.render(p, bl, br);
|
|
}
|
|
|
|
TTF_CloseFont(r.font);
|
|
SDL_DestroyRenderer(r.renderer);
|
|
SDL_DestroyWindow(r.window);
|
|
SDL_Quit();
|
|
Mix_FreeMusic(r.music);
|
|
Mix_CloseAudio();
|
|
TTF_Quit();
|
|
|
|
return 0;
|
|
}
|