コミットを比較

...

13 コミット

36個のファイルの変更1022行の追加3行の削除

ファイルの表示

@ -1,2 +1,3 @@
musicmanager
*.core
ass

ファイルの表示

@ -8,10 +8,29 @@ CFLAGS=-I${PREFIX}/include -L${PREFIX}/lib
LDFLAGS=-lSDL2 -lSDL2_ttf -lSDL2_image -lSDL2_mixer
FILES=main.cc src/*.cc src/*/*.cc
all:
all: ass
${CC} ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS}
clean:
rm -f ${NAME}
.PHONY: all clean
ass:
mkdir -p ass/{bgm,fnt,gfx}
odl -po ass/gfx/bg.tga\
https://076.moe/repo/ass/game-benkyokai/02/gfx/bg.tga
odl -po ass/gfx/logo.tga\
https://076.moe/repo/ass/game-benkyokai/02/gfx/logo.tga
odl -po ass/fnt/font.ttf\
https://076.moe/repo/ass/game-benkyokai/02/fnt/font.ttf
odl -po ass/bgm/internetsurviver.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/internetsurviver.ogg
odl -po ass/bgm/nativemiku.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/nativemiku.ogg
odl -po ass/bgm/titlescreen.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/titlescreen.ogg
odl -po ass/bgm/lovecall.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/lovecall.ogg
odl -po ass/bgm/sintai.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/sintai.ogg
.PHONY: all clean ass

ファイルの表示

@ -6,6 +6,18 @@
* ロゴの追加
* 背景はTargaファイルの交換
# ビルド
ビルドするには、[odl](https://gitler.moe/suwako/odl)をインストールする事が必要です。
```sh
# make
```
## アセットだけの場合
```sh
# make ass
```
# 著作権
## 利用した音楽
* メイン画面: https://pixabay.com/music/build-up-scenes-science-documentary-169621/

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

バイナリファイルは表示されません。

変更前

幅:  |  高さ:  |  サイズ: 300 KiB

ファイルの表示

@ -1,6 +1,5 @@
#include <iostream>
#include <cstdio>
#include <src/musicmanager.hh>
#include <vector>
#include <SDL2/SDL.h>
@ -12,6 +11,7 @@
#include "src/scenes/gallary.hh"
#include "src/scenes/settings.hh"
#include "src/scenes/settings_audio.hh"
#include "src/musicmanager.hh"
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;

3
0.training/3.rendermanager/.gitignore vendored ノーマルファイル
ファイルの表示

@ -0,0 +1,3 @@
rendermanager
*.core
ass

44
0.training/3.rendermanager/Makefile ノーマルファイル
ファイルの表示

@ -0,0 +1,44 @@
OS!=uname -s
ARCH!=uname -m
NAME=rendermanager
PREFIX=/usr/local
CC=clang++
CFLAGS=-I${PREFIX}/include -L${PREFIX}/lib
LDFLAGS=-lSDL2 -lSDL2_ttf -lSDL2_image -lSDL2_mixer
FILES=main.cc src/*.cc src/*/*.cc
all: ass
${CC} ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS}
clean:
rm -f ${NAME}
ass:
mkdir -p ass/{bgm,fnt,gfx,sfx}
odl -po ass/gfx/bg.tga\
https://076.moe/repo/ass/game-benkyokai/02/gfx/bg.tga
odl -po ass/gfx/logo.tga\
https://076.moe/repo/ass/game-benkyokai/02/gfx/logo.tga
odl -po ass/fnt/font.ttf\
https://076.moe/repo/ass/game-benkyokai/02/fnt/font.ttf
odl -po ass/bgm/internetsurviver.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/internetsurviver.ogg
odl -po ass/bgm/nativemiku.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/nativemiku.ogg
odl -po ass/bgm/titlescreen.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/titlescreen.ogg
odl -po ass/bgm/lovecall.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/lovecall.ogg
odl -po ass/bgm/sintai.ogg\
https://076.moe/repo/ass/game-benkyokai/02/bgm/sintai.ogg
odl -po ass/sfx/scroll.ogg\
https://076.moe/repo/ass/game-benkyokai/03/sfx/scroll.ogg
odl -po ass/sfx/select1.ogg\
https://076.moe/repo/ass/game-benkyokai/03/sfx/select1.ogg
odl -po ass/sfx/selectback.ogg\
https://076.moe/repo/ass/game-benkyokai/03/sfx/selectback.ogg
odl -po ass/sfx/selectgamestart.ogg\
https://076.moe/repo/ass/game-benkyokai/03/sfx/selectgamestart.ogg
.PHONY: all clean ass

30
0.training/3.rendermanager/README.md ノーマルファイル
ファイルの表示

@ -0,0 +1,30 @@
# 変更
* ビデオ設定の追加
* メニューをループする様に
* フルスクリーンはビデオ設定に移動
* フルスクリーンの解像度の修正
* フォント管理の追加
* グラフィック管理の追加
* レンダー管理の追加
* main.ccを綺麗に
* SFXの追加
# ビルド
ビルドするには、[odl](https://gitler.moe/suwako/odl)をインストールする事が必要です。
```sh
# make
```
## アセットだけの場合
```sh
# make ass
```
# 著作権
## 利用した音楽
* メイン画面: https://pixabay.com/music/build-up-scenes-science-documentary-169621/
* インターネットサバイバー: https://invidious.jing.rocks/watch?v=G6N943NlCbw
* ネイティブフェイス(初音ミク): https://invidious.jing.rocks/watch?v=qJeeDUH1TFc
* 死体旅行へようこそ: https://invidious.jing.rocks/watch?v=N7PcD7L5dlU
* ラブコール着信中: https://invidious.jing.rocks/watch?v=_TPwhN6XN8M

342
0.training/3.rendermanager/main.cc ノーマルファイル
ファイルの表示

@ -0,0 +1,342 @@
#include <iostream>
#include <cstdio>
#include <vector>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include "src/scenes/mainmenu.hh"
#include "src/scenes/gallary.hh"
#include "src/scenes/settings.hh"
#include "src/scenes/settings_video.hh"
#include "src/scenes/settings_audio.hh"
#include "src/musicmanager.hh"
#include "src/fontmanager.hh"
#include "src/graphicsmanager.hh"
#include "src/rendermanager.hh"
Mainmenu m;
Gallary g;
Settings s;
SettingsVideo sv;
SettingsAudio sa;
SDL_Texture *texture = NULL;
SDL_Texture *logotexture = NULL;
Musicmanager mm;
Fontmanager fm;
Graphicsmanager gm;
Rendermanager rm;
bool running = true;
int menuindex = 0;
int menudepth = 0;
const char* logoimg = "ass/gfx/logo.tga";
const char* bgimg = "ass/gfx/bg.tga";
bool isinit_sdl = false;
bool isinit_window = false;
bool isinit_renderer = false;
bool isinit_ttf = false;
bool isinit_font = false;
bool isinit_mix = false;
bool isinit_img = false;
enum MenuState {
MAINMENU,
GALLARY,
SETTINGS,
SETTINGS_VIDEO,
SETTINGS_AUDIO,
};
MenuState curmenu = MAINMENU;
void cleanup() {
SDL_DestroyTexture(logotexture);
SDL_DestroyTexture(texture);
if (isinit_mix) {
Mix_HaltMusic();
Mix_CloseAudio();
}
if (isinit_img) IMG_Quit();
if (isinit_font) TTF_CloseFont(fm.font);
if (isinit_ttf) TTF_Quit();
if (isinit_renderer) SDL_DestroyRenderer(rm.renderer);
if (isinit_window) SDL_DestroyWindow(rm.window);
if (isinit_sdl) SDL_Quit();
}
void changeScene(int i) {
if (curmenu == MAINMENU) { // メインメニュー
m.render(&fm, &mm, &rm, i, sv.width);
if (i == 0) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectg);
Mix_PlayChannel(-1, sfx, 0);
puts("ゲーム開始");
}
else if (i == 1) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
curmenu = GALLARY;
menuindex = 0;
}
else if (i == 2) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
curmenu = SETTINGS;
menuindex = 0;
}
else if (i == 3) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectb);
Mix_PlayChannel(-1, sfx, 0);
SDL_Delay(1000);
running = false;
}
} else if (curmenu == GALLARY) { // ギャラリー
g.render(&fm, &mm, &rm, i, sv.width);
if (i == 0) {
Mix_HaltMusic();
mm.music = Mix_LoadMUS("ass/bgm/internetsurviver.ogg");
mm.playmusic(mm.music);
} else if (i == 1) {
Mix_HaltMusic();
mm.music = Mix_LoadMUS("ass/bgm/nativemiku.ogg");
mm.playmusic(mm.music);
} else if (i == 2) {
Mix_HaltMusic();
mm.music = Mix_LoadMUS("ass/bgm/sintai.ogg");
mm.playmusic(mm.music);
} else if (i == 3) {
Mix_HaltMusic();
mm.music = Mix_LoadMUS("ass/bgm/lovecall.ogg");
mm.playmusic(mm.music);
} else if (i == 4) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectb);
Mix_PlayChannel(-1, sfx, 0);
curmenu = MAINMENU;
menuindex = 0;
Mix_HaltMusic();
mm.music = Mix_LoadMUS("ass/bgm/titlescreen.ogg");
mm.playmusic(mm.music);
}
} else if (curmenu == SETTINGS) { // 設定
s.render(&fm, &mm, &rm, i, sv.width);
if (i == 0) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
curmenu = SETTINGS_VIDEO;
menuindex = 0;
}
else if (i == 1) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
curmenu = SETTINGS_AUDIO;
menuindex = 0;
}
else if (i == 2) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
s.setlang();
}
else if (i == 3) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectb);
Mix_PlayChannel(-1, sfx, 0);
curmenu = MAINMENU;
menuindex = 0;
}
} else if (curmenu == SETTINGS_VIDEO) { // ビデオ設定
sv.render(&fm, &mm, &rm, i, sv.width);
if (i == 0) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
sv.changeres(&rm);
} else if (i == 1) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselect1);
Mix_PlayChannel(-1, sfx, 0);
sv.togglefs(&rm);
}
else if (i == 2) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectb);
Mix_PlayChannel(-1, sfx, 0);
curmenu = SETTINGS;
menuindex = 0;
}
} else if (curmenu == SETTINGS_AUDIO) { // オーディオ設定
sa.render(&fm, &mm, &rm, i, sv.width);
if (i == 0) mm.volume = mm.changevolume(4);
else if (i == 1) mm.volume = mm.changevolume(-4);
else if (i == 2) {
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuselectb);
Mix_PlayChannel(-1, sfx, 0);
curmenu = SETTINGS;
menuindex = 0;
}
}
if (menudepth > 1) menudepth = 1;
}
void controls(SDL_Event *e) {
if (e->type == SDL_QUIT) {
running = false;
} else if (e->type == SDL_KEYDOWN) {
if (e->key.keysym.sym == SDLK_q) running = false;
else if (e->key.keysym.sym == SDLK_k || e->key.keysym.sym == SDLK_w) {
menuindex--;
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuscroll);
Mix_PlayChannel(-1, sfx, 0);
}
else if (e->key.keysym.sym == SDLK_j || e->key.keysym.sym == SDLK_s) {
menuindex++;
Mix_Chunk *sfx = Mix_LoadWAV(mm.sfx_menuscroll);
Mix_PlayChannel(-1, sfx, 0);
}
else if (e->key.keysym.sym == SDLK_RETURN) changeScene(menuindex);
/* else if (e->key.keysym.sym == SDLK_ESCAPE) changeScene(menuindex); */
} else if (
e->type == SDL_WINDOWEVENT &&
e->window.event == SDL_WINDOWEVENT_EXPOSED
) {
SDL_Rect renderquad = { 0, 0, sv.width, sv.height };
SDL_RenderClear(rm.renderer);
SDL_RenderCopy(rm.renderer, texture, NULL, &renderquad);
SDL_RenderPresent(rm.renderer);
}
}
int main(void) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
std::cout << "SDL_Init()に失敗" << '\n';
return -1;
}
isinit_sdl = true;
rm.window = SDL_CreateWindow(
"mainmenu",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
sv.width,
sv.height,
SDL_WINDOW_SHOWN
);
if (!rm.window) {
cleanup();
std::cout << "SDL_CreateWindow()に失敗" << '\n';
return -1;
}
isinit_window = true;
SDL_DisplayMode dm;
if (SDL_GetDesktopDisplayMode(0, &dm) != 0) {
cleanup();
std::cout << "SDL_GetDesktopDisplayMode()に失敗" << '\n';
return -1;
}
sv.sw = dm.w;
sv.sh = dm.h;
rm.renderer = SDL_CreateRenderer(rm.window, -1, SDL_RENDERER_ACCELERATED);
if (!rm.renderer) {
cleanup();
std::cout << "SDL_CreateRenderer()に失敗" << '\n';
return -1;
}
isinit_renderer = true;
SDL_SetWindowTitle(rm.window, "メインメニュー");
fm.font = fm.initfont();
if (!fm.font) {
cleanup();
return -1;
}
isinit_ttf = true;
if (gm.initgraphics() != 0) {
cleanup();
return -1;
}
isinit_img = true;
if (mm.initmusic() != 0) {
cleanup();
return -1;
}
isinit_mix = true;
logotexture = gm.maketexture(&rm, logoimg);
if (!logotexture) {
cleanup();
return -1;
}
texture = gm.maketexture(&rm, bgimg);
if (!texture) {
SDL_DestroyTexture(logotexture);
cleanup();
return -1;
}
Mainmenu m;
Gallary g;
Settings s;
SettingsAudio sa;
mm.music = Mix_LoadMUS(mm.musicfile);
mm.playmusic(mm.music);
int txwidth, txheight;
SDL_QueryTexture(logotexture, NULL, NULL, &txwidth, &txheight);
while (running) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
controls(&e);
}
SDL_SetRenderDrawColor(rm.renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(rm.renderer);
int textx = sv.width / 2 - txwidth / 2;
int texty = 40;
SDL_Rect logorect = {textx, texty, txwidth, txheight};
SDL_RenderCopy(rm.renderer, texture, NULL, NULL);
SDL_RenderCopy(rm.renderer, logotexture, NULL, &logorect);
if (curmenu == MAINMENU) {
m.render(&fm, &mm, &rm, menuindex, sv.width);
if (menuindex > 3) menuindex = 0;
else if (menuindex < 0) menuindex = 3;
} else if (curmenu == GALLARY) {
g.render(&fm, &mm, &rm, menuindex, sv.width);
if (menuindex > 4) menuindex = 0;
else if (menuindex < 0) menuindex = 4;
} else if (curmenu == SETTINGS) {
s.render(&fm, &mm, &rm, menuindex, sv.width);
if (menuindex > 3) menuindex = 0;
else if (menuindex < 0) menuindex = 3;
} else if (curmenu == SETTINGS_VIDEO) {
sv.render(&fm, &mm, &rm, menuindex, sv.width);
if (menuindex > 2) menuindex = 0;
else if (menuindex < 0) menuindex = 2;
} else if (curmenu == SETTINGS_AUDIO) {
sa.render(&fm, &mm, &rm, menuindex, sv.width);
if (menuindex > 2) menuindex = 0;
else if (menuindex < 0) menuindex = 2;
}
SDL_RenderPresent(rm.renderer);
}
// 掃除
cleanup();
return 0;
}

18
0.training/3.rendermanager/src/fontmanager.cc ノーマルファイル
ファイルの表示

@ -0,0 +1,18 @@
#include "fontmanager.hh"
#include <SDL2/SDL_image.h>
TTF_Font *Fontmanager::initfont() {
if (TTF_Init() < 0) {
std::cout << "TTF_Init()に失敗" << '\n';
return NULL;
}
TTF_Font *res = TTF_OpenFont(fontfile, fontsize);
if (!res) {
std::cout << "TTF_OpenFont()に失敗" << '\n';
return NULL;
}
return res;
}

20
0.training/3.rendermanager/src/fontmanager.hh ノーマルファイル
ファイルの表示

@ -0,0 +1,20 @@
#ifndef FONTMANAGER_HH
#define FONTMANAGER_HH
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
class Fontmanager {
public:
TTF_Font *initfont();
TTF_Font *font = NULL;
int fontsize = 24;
SDL_Color fgcol = {255, 255, 255, 0};
SDL_Color hlcol = {255, 0, 255, 0};
const char* fontfile = "ass/fnt/font.ttf";
};
#endif

ファイルの表示

@ -0,0 +1,29 @@
#include "graphicsmanager.hh"
#include <SDL2/SDL_image.h>
int Graphicsmanager::initgraphics() {
if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) {
std::cout << "IMG_Init()に失敗" << '\n';
return -1;
}
return 0;
}
SDL_Texture *Graphicsmanager::maketexture(Rendermanager *rm, const char *filename) {
SDL_Surface *surface = IMG_Load(filename);
if (!surface) {
std::cout << "サーフィスを読込に失敗" << '\n';
return NULL;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(rm->renderer, surface);
SDL_FreeSurface(surface);
if (!texture) {
std::cout << "テキチャーを作成に失敗" << '\n';
return NULL;
}
return texture;
}

ファイルの表示

@ -0,0 +1,18 @@
#ifndef GRAPHICSMANAGER_HH
#define GRAPHICSMANAGER_HH
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_image.h>
#include "rendermanager.hh"
class Graphicsmanager {
public:
int initgraphics();
SDL_Texture *maketexture(Rendermanager *rm, const char* filename);
};
#endif

ファイルの表示

@ -0,0 +1,32 @@
#include "musicmanager.hh"
#include <SDL2/SDL_image.h>
int Musicmanager::initmusic() {
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
std::cout << "Mix_OpenAudio()に失敗" << '\n';
return -1;
}
Mix_Volume(-1, MIX_MAX_VOLUME);
return 0;
}
void Musicmanager::playmusic(Mix_Music* music) {
if (Mix_PlayMusic(music, -1) < 0) {
std::cout << "OGGファイルのエラー" << Mix_GetError() << '\n';
}
}
int Musicmanager::changevolume(int i) {
int vol = Mix_VolumeMusic(-1);
vol += i;
if (i < 0) i = 0;
else if (i > MIX_MAX_VOLUME) i = MIX_MAX_VOLUME;
Mix_VolumeMusic(vol);
return vol;
}
void Musicmanager::stopmusic() {
Mix_HaltMusic();
}

ファイルの表示

@ -0,0 +1,26 @@
#ifndef MUSICMANAGER_HH
#define MUSICMANAGER_HH
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
class Musicmanager {
public:
int initmusic();
void playmusic(Mix_Music* music);
int changevolume(int i);
void stopmusic();
Mix_Music *music = NULL;
Mix_Chunk *sfx = NULL;
int volume = MIX_MAX_VOLUME;
const char* musicfile = "ass/bgm/titlescreen.ogg";
const char* sfx_menuscroll = "ass/sfx/scroll.ogg";
const char* sfx_menuselect1 = "ass/sfx/select1.ogg";
const char* sfx_menuselectb = "ass/sfx/selectback.ogg";
const char* sfx_menuselectg = "ass/sfx/selectgamestart.ogg";
};
#endif

ファイルの表示

@ -0,0 +1 @@
#include "rendermanager.hh"

ファイルの表示

@ -0,0 +1,13 @@
#ifndef RENDERMANAGER_HH
#define RENDERMANAGER_HH
#include <iostream>
#include <SDL2/SDL.h>
class Rendermanager {
public:
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
};
#endif

ファイルの表示

@ -0,0 +1,40 @@
#include "scenemanager.hh"
void Scenemanager::renderitems(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
const std::vector<std::string>& menuitems,
int width
) {
for (int i = 0; i < menuitems.size(); ++i) {
SDL_Texture *itemtexture = rendertext(
rm,
menuitems[i],
(i == menuindex) ? fm->hlcol : fm->fgcol,
fm->font
);
int txwidth, txheight;
SDL_QueryTexture(itemtexture, NULL, NULL, &txwidth, &txheight);
int textx = width / 2 - txwidth / 2;
int texty = 200 + i * 50;
SDL_Rect textRect = {textx, texty, txwidth, txheight};
SDL_RenderCopy(rm->renderer, itemtexture, NULL, &textRect);
SDL_DestroyTexture(itemtexture);
}
}
SDL_Texture* Scenemanager::rendertext(
Rendermanager *rm,
const std::string& text,
SDL_Color color,
TTF_Font *font
) {
SDL_Surface* surface = TTF_RenderUTF8_Solid(font, text.c_str(), color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(rm->renderer, surface);
SDL_FreeSurface(surface);
return texture;
}

ファイルの表示

@ -0,0 +1,42 @@
#ifndef SCENEMANAGER_HH
#define SCENEMANAGER_HH
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include "fontmanager.hh"
#include "musicmanager.hh"
#include "rendermanager.hh"
class Scenemanager {
public:
virtual void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) = 0;
protected:
void renderitems(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
const std::vector<std::string>& menuitems,
int width
);
private:
SDL_Texture* rendertext(
Rendermanager *fm,
const std::string& text,
SDL_Color color,
TTF_Font *font
);
};
#endif

ファイルの表示

@ -0,0 +1,34 @@
#include <iostream>
#include "gallary.hh"
#include "settings.hh"
void Gallary::render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) {
std::vector<std::string> menuitems;
if (Settings::lang == Settings::JAPANESE) {
menuitems = {
u8"インターネットサバイバー",
u8"ネイティブフェイス(初音ミク)",
u8"死体旅行へようこそ!",
u8"ラブコール着信中",
u8"戻る"
};
} else {
menuitems = {
"INTERNET SURVIVER",
"NATIVE FAITH (HATSUNE MIKU)",
"WELCOME TO THE DEAD BODY TRAVEL",
"LOVE CALL RINGTONE",
"BACK"
};
}
renderitems(fm, mm, rm, menuindex, menuitems, width);
}

ファイルの表示

@ -0,0 +1,20 @@
#ifndef GALLARY_HH
#define GALLARY_HH
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "../scenemanager.hh"
class Gallary : public Scenemanager {
public:
void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) override;
};
#endif

ファイルの表示

@ -0,0 +1,32 @@
#include <iostream>
#include "mainmenu.hh"
#include "settings.hh"
void Mainmenu::render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) {
std::vector<std::string> menuitems;
if (Settings::lang == Settings::JAPANESE) {
menuitems = {
u8"ゲーム開始",
u8"ギャラリー",
u8"設定",
u8"終了"
};
} else {
menuitems = {
"PLAY GAME",
"GALLARY",
"SETTINGS",
"QUIT"
};
}
renderitems(fm, mm, rm, menuindex, menuitems, width);
}

ファイルの表示

@ -0,0 +1,20 @@
#ifndef MAINMENU_HH
#define MAINMENU_HH
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "../scenemanager.hh"
class Mainmenu : public Scenemanager {
public:
void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) override;
};
#endif

ファイルの表示

@ -0,0 +1,38 @@
#include <iostream>
#include "settings.hh"
int Settings::lang = JAPANESE;
void Settings::setlang() {
if (lang == JAPANESE) lang = ENGLISH;
else lang = JAPANESE;
}
void Settings::render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) {
std::vector<std::string> menuitems;
if (lang == JAPANESE) {
menuitems = {
u8"ビデオ",
u8"オーディオ",
u8"言語",
u8"戻る"
};
} else {
menuitems = {
"VIDEO",
"AUDIO",
"LANGUAGE",
"BACK"
};
}
renderitems(fm, mm, rm, menuindex, menuitems, width);
}

ファイルの表示

@ -0,0 +1,28 @@
#ifndef SETTINGS_HH
#define SETTINGS_HH
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "../scenemanager.hh"
class Settings : public Scenemanager {
public:
void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) override;
static void setlang();
enum Language {
JAPANESE,
ENGLISH,
};
static int lang;
};
#endif

ファイルの表示

@ -0,0 +1,47 @@
#include <iostream>
#include <string>
#include "settings_audio.hh"
#include "settings.hh"
void SettingsAudio::render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) {
std::vector<std::string> menuitems;
std::string label = "";
if (Settings::lang == Settings::JAPANESE) {
menuitems = {
u8"増大",
u8"減小",
u8"戻る"
};
label = "容量: " + std::to_string(mm->changevolume(0));
} else {
menuitems = {
"UP",
"DOWN",
"BACK"
};
label = "VOLUME " + std::to_string(mm->changevolume(0));
}
renderitems(fm, mm, rm, menuindex, menuitems, width);
SDL_Surface* surface = TTF_RenderUTF8_Solid(fm->font, label.c_str(), fm->fgcol);
SDL_Texture* texture = SDL_CreateTextureFromSurface(rm->renderer, surface);
SDL_FreeSurface(surface);
int txwidth, txheight;
SDL_QueryTexture(texture, NULL, NULL, &txwidth, &txheight);
int textx = width / 2 - txwidth / 2;
int texty = 100 + 7 * 50;
SDL_Rect textRect = {textx, texty, txwidth, txheight};
SDL_RenderCopy(rm->renderer, texture, NULL, &textRect);
SDL_DestroyTexture(texture);
}

ファイルの表示

@ -0,0 +1,20 @@
#ifndef SETTINGS_AUDIO_HH
#define SETTINGS_AUDIO_HH
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "../scenemanager.hh"
class SettingsAudio : public Scenemanager {
public:
void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) override;
};
#endif

ファイルの表示

@ -0,0 +1,62 @@
#include <iostream>
#include <string>
#include "settings_video.hh"
#include "settings.hh"
void SettingsVideo::togglefs(Rendermanager *rm) {
Uint32 fsflag = SDL_WINDOW_FULLSCREEN_DESKTOP;
Uint32 flags = SDL_GetWindowFlags(rm->window);
if (!(flags & fsflag)) {
savewidth = width;
saveheight = height;
width = sw;
height = sh;
} else {
width = savewidth;
height = saveheight;
}
SDL_SetWindowFullscreen(rm->window, flags & fsflag ? 0 : fsflag);
}
void SettingsVideo::changeres(Rendermanager *rm) {
if (width == 800 && height == 600) {
width = 1280;
height = 960;
} else if (width == 1280 && height == 960) {
width = 1440;
height = 1080;
} else {
width = 800;
height = 600;
}
SDL_SetWindowSize(rm->window, width, height);
}
void SettingsVideo::render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) {
std::vector<std::string> menuitems;
std::string label = "";
if (Settings::lang == Settings::JAPANESE) {
menuitems = {
u8"解像度:" + std::to_string(width) + "x" + std::to_string(height),
u8"フルスクリーン切り替え",
u8"戻る"
};
} else {
menuitems = {
"RESOLUTION: " + std::to_string(width) + "x" + std::to_string(height),
"TOGGLE FULLSCREEN",
"BACK"
};
}
renderitems(fm, mm, rm, menuindex, menuitems, width);
}

ファイルの表示

@ -0,0 +1,28 @@
#ifndef SETTINGS_VIDEO_HH
#define SETTINGS_VIDEO_HH
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "../scenemanager.hh"
#include "../rendermanager.hh"
class SettingsVideo : public Scenemanager {
public:
void render(
Fontmanager *fm,
Musicmanager *mm,
Rendermanager *rm,
int menuindex,
int width
) override;
void changeres(Rendermanager *rm);
void togglefs(Rendermanager *rm);
int width = 800;
int height = 600;
int savewidth, saveheight; // フルスクリーン用
int sw, sh; // 画面のサイズ
};
#endif