まずはソースコードには何も手を加えずにファイルを分割してみました。
学校ではきちんとビルド可能だったのに、自宅でビルドすると以下のようなエラーがたくさん出てきました。
学校と環境が違うせいでしょうか。
自宅ではvisual studio 2017 community を使っています。
ちなみにファイルを分割する前も同じようなエラーがでてビルドできませんでした。
改良どころじゃないんですが、どの様に修正するべきでしょうか。
1>main.cpp
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(56): warning C4838: 'unsigned int' から 'int' への変換には縮小変換が必要です
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(104): error C2440: '初期化中': 'const char [10]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\.総合課題.c\main.cpp(104): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\.総合課題.c\main.cpp(104): error C2440: '初期化中': 'const char [7]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\.総合課題.c\main.cpp(104): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(104): error C2440: '初期化中': 'const char [5]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(104): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): error C2440: '初期化中': 'const char [12]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): error C2440: '初期化中': 'const char [9]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): error C2440: '初期化中': 'const char [5]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(125): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): error C2440: '初期化中': 'const char [11]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): error C2440: '初期化中': 'const char [12]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): error C2440: '初期化中': 'const char [6]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): error C2440: '初期化中': 'const char [7]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): error C2440: '初期化中': 'const char [5]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(219): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(228): error C2440: '=': 'const char [10]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(228): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(229): error C2440: '=': 'const char [11]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(229): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(230): error C2440: '=': 'const char [8]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(230): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(231): error C2440: '=': 'const char [9]' から 'char *' に変換できません。
1>c:\users\keisuke\source\repos\総合課題.c\main.cpp(231): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
#include "main.h"
// ウィンメイン関数 ---------------------------------------------------------------------------- //
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 初期化処理
SetGraphMode(640, 480, 16); // 画面モードのセット
SetOutApplicationLogValidFlag(false); // Log.txtの出力を抑制
SetWindowIconID(101); // タイトルアイコンの変更
SetMainWindowText("Falling Pieces 1.22"); // タイトルバーの変更
ChangeWindowMode(winMode); // ウィンドウモードで起動
if (DxLib_Init() == -1) { return -1; } // DXライブラリ初期化処理
InitGrp(); // 画像データのロード
InitSE(); // 効果音データのロード
PlayMusicGame();
// メインループ
while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0 && exitFlag == 0) {
frame++; // フレーム加算
Input(); // 入力の感知
ClearDrawScreen(); // 画面をクリアする
if (Key[KEY_INPUT_TAB] == 1) { FullScreen(); }
// 画面モード分岐
switch (scene) {
case _TITLE: Title(); break;
case _OPTION: Option(); break;
case _CONTROLL: Controll(); break;
case _SELECT: Select(); break;
case _MAIN_GAME: MainGame(); break;
case _PAUSE: Pause(); break;
case _GAME_OVER: GameOver(); break;
case _ENDING: Ending(); break;
}
ScreenFlip(); // 裏画面の内容を表画面に反映させる(PCのフレームレートに合わせて描画される)
}
DxLib_End(); // DXライブラリ使用の終了処理
return 0; // ソフトの終了
}
// タイトル画面 -------------------------------------------------------------------------------- //
void Title(void)
{
enum eTitle { _START, _MENU, _OPTION };
static eTitle titleScene = _START;
// タイトル共通描画
DrawGraph(0, 0, grp.BG[2], false);
static int color3D[3] = { 0 };
if (frame % 2 == 0 && titleScene == _TITLE) { for (int i = 0; i<3; i++) { color3D[i] = GetRand(96) + 64; } }
int color[7] = {
GetColor(color3D[0], color3D[1], color3D[2]),
GetColor(100, 150, 150),
GetColor(150, 100, 150),
GetColor(150, 150, 100),
GetColor(150, 100, 100),
GetColor(100, 150, 100),
GetColor(100, 100, 150)
};
int x = 160, y = 50;
DrawStringToHandle(x + 3, y + 3, "Falling", color[0], grp.font64);
DrawStringToHandle(x, y, "F", color[1], grp.font64);
DrawStringToHandle(x, y, " a", color[2], grp.font64);
DrawStringToHandle(x, y, " l", color[3], grp.font64);
DrawStringToHandle(x, y, " l", color[4], grp.font64);
DrawStringToHandle(x, y, " i", color[5], grp.font64);
DrawStringToHandle(x, y, " n", color[6], grp.font64);
DrawStringToHandle(x, y, " g", color[1], grp.font64);
x += 50, y += 60;
DrawStringToHandle(x + 3, y + 3, "Pieces", color[0], grp.font64);
DrawStringToHandle(x, y, "P", color[1], grp.font64);
DrawStringToHandle(x, y, " i", color[2], grp.font64);
DrawStringToHandle(x, y, " e", color[3], grp.font64);
DrawStringToHandle(x, y, " c", color[4], grp.font64);
DrawStringToHandle(x, y, " e", color[5], grp.font64);
DrawStringToHandle(x, y, " s", color[6], grp.font64);
DrawGraph(420, 40, grp.PieceT, true);
DrawStringToHandle(160, 440, "copy right (c) 2011 Y.I", GetColor(200, 200, 200), grp.font20);
static int menu = 0;
// タイトル:スタート
if (titleScene == _START) {
// Zキー:決定
if (Key[KEY_INPUT_Z] == 1) {
PlaySoundMem(se.sePEPO, DX_PLAYTYPE_NORMAL);
titleScene = _MENU;
}
// 描画
if (frame % 24 < 16) {
DrawStringToHandle(208, 278, "PUSH Z BUTTON !", GetColor(200, 200, 200), grp.font24);
DrawStringToHandle(210, 280, "PUSH Z BUTTON !", GetColor(100, 100, 100), grp.font24);
}
}
// タイトル:メニュー
else if (titleScene == _MENU) {
// Zキー:決定
if (Key[KEY_INPUT_Z] == 1) {
PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 0) { scene = _SELECT; PlayMusicGame(); }
if (menu == 1) { titleScene = _OPTION; menu = 0; }
if (menu == 2) { exitFlag = 1; }
}
// ↑↓キー:メニュー移動
if (Key[KEY_INPUT_DOWN] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu++; if (menu>2) menu = 0; }
if (Key[KEY_INPUT_UP] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu--; if (menu<0) menu = 2; }
// 描画
static char* strMenu[6] = { "MAIN GAME", "OPTION", "EXIT" };
DrawMenu(250, 220, 40, menu, strMenu);
}
// タイトル:オプション
else if (titleScene == _OPTION) {
// Zキー:決定
if (Key[KEY_INPUT_Z] == 1) {
PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 0) { FullScreen(); }
if (menu == 1) { scene = _CONTROLL; menu = 0; }
if (menu == 2) { titleScene = _MENU; menu = 0; }
}
// Xキー:キャンセル
if (Key[KEY_INPUT_X] == 1) {
PlaySoundMem(se.seCancel, DX_PLAYTYPE_BACK);
titleScene = _MENU; menu = 0;
}
// ↑↓キー:メニュー移動
if (Key[KEY_INPUT_DOWN] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu++; if (menu>2) menu = 0; }
if (Key[KEY_INPUT_UP] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu--; if (menu<0) menu = 2; }
// 描画
static char* strOption[6] = { "WINDOW MODE","CONTROLL", "BACK" };
DrawMenu(250, 220, 40, menu, strOption);
}
}
// ポーズ画面 ---------------------------------------------------------------------------------- //
void Pause(void)
{
if (Key[KEY_INPUT_RETURN] == 1) {
PlaySoundMem(se.seHold, DX_PLAYTYPE_NORMAL);
scene = _MAIN_GAME;
}
DrawGraph(0, 0, grp.BG[1], false);
DrawScore();
if (cameraMode == 1) { DrawGraph(0, 0, grp.CameraIcon, false); }
DrawStringToHandle(230, 160, "PAUSE", GetColor(200, 200, 200), grp.font64);
}
// エンディング画面 ---------------------------------------------------------------------------- //
void Ending(void)
{
static int time = 0;
DrawGraph(0, 0, grp.BG[0], false);
int x = 100, y = 100, h = 60, t = 300;
int color = GetColor(200, 200, 200);
// 描画
DrawStringToHandle(460, 445, "♪コロブチカ", color, grp.font20);
if (time == 0) { time = frame; }
if (time + t * 2 > frame) {
DrawStringToHandle(x, y, "企画/製作", color, grp.font24);
DrawStringToHandle(x, y + 60, " Yuichiro Itohara", color, grp.font24);
}
else if (time + t * 3 > frame) { DrawStringToHandle(x, y, "背景デザイン 空彩", color, grp.font24); }
else if (time + t * 4 > frame) {
DrawStringToHandle(x, y, "音楽 AQUANOTE", color, grp.font24);
DrawStringToHandle(x, y + 60, "効果音 ULTIMATEゲーム事業部", color, grp.font24);
}
else if (time + t * 5 > frame) {
DrawStringToHandle(x, y, "スペシャルサンクス", color, grp.font24);
DrawStringToHandle(x, y + 60, " DXライブラリ Takumi Yamada", color, grp.font24);
}
else if (time + t * 6 + 100 > frame) { DrawStringToHandle(x, y + 100, "THANK YOU FOR YOUR PLAYING !!", color, grp.font24); }
else { scene = _TITLE; time = 0; PlayMusicGame(); }
// Enterキー:スキップ
if (Key[KEY_INPUT_RETURN] == 1) { scene = _TITLE; time = 0; PlayMusicGame(); }
}
// ゲームオーバー画面 -------------------------------------------------------------------------- //
void GameOver(void)
{
static int time = 0;
if (time == 0) { time = frame; }
// Zキー
if (Key[KEY_INPUT_Z] == 2) { time = 0; scene = _TITLE; PlayMusicGame(); }
DrawGraph(0, 0, grp.BG[1], false);
DrawStringToHandle(160, 200, "GAME OVER", GetColor(100, 100, 100), grp.font64);
}
// セレクト画面 -------------------------------------------------------------------------------- //
void Select(void)
{
static int menu = 0;
// Zキー:決定
if (Key[KEY_INPUT_Z] == 1) {
PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 0) { scene = _MAIN_GAME; for (int i = 0; i<4; ++i) { AppearPiece(); } PlaySoundMem(se.seStart, DX_PLAYTYPE_BACK); }
if (menu == 1) { level++; if (level > 9) level = 1; }
if (menu == 2) { music++; if (music > 3) { music = 0; } PlayMusicGame(); }
if (menu == 3) { changeCameraMode(); }
if (menu == 4) { changeGridMode(); }
if (menu == 5) { scene = _TITLE; PlayMusicGame(); }
}
// Xキー:キャンセル
if (Key[KEY_INPUT_X] == 1) {
PlaySoundMem(se.seCancel, DX_PLAYTYPE_BACK);
scene = _TITLE; PlayMusicGame();
}
// ↑↓キー:メニュー移動
if (Key[KEY_INPUT_DOWN] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu++; if (menu>5) menu = 0; }
else if (Key[KEY_INPUT_UP] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu--; if (menu<0) menu = 5; }
// ←→キー:項目変更
if (Key[KEY_INPUT_LEFT] == 1) {
if (menu >= 1 && menu <= 4) PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 1) { level--; if (level < 1) level = 9; }
if (menu == 2) { music--; if (music < 0) music = 3; PlayMusicGame(); }
if (menu == 3) { changeCameraMode(); }
if (menu == 4) { changeGridMode(); }
}
else if (Key[KEY_INPUT_RIGHT] == 1) {
if (menu >= 1 && menu <= 4) PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 1) { level++; if (level > 9) level = 1; }
if (menu == 2) { music++; if (music > 3) music = 0; PlayMusicGame(); }
if (menu == 3) { changeCameraMode(); }
if (menu == 4) { changeGridMode(); }
}
// 文字列の作成
static char* strMenu[6] = { "GAME START", "START LEVEL", "MUSIC", "CAMERA", "GRID", "BACK" };
static char strMusic[64];
switch (music) {
case 0: sprintf_s(strMusic, "MUSIC OFF"); break;
case 1: sprintf_s(strMusic, "MUSIC A"); break;
case 2: sprintf_s(strMusic, "MUSIC B"); break;
case 3: sprintf_s(strMusic, "MUSIC C"); break;
}
strMenu[2] = strMusic;
if (cameraMode == 1) { strMenu[3] = "CAMERA ON"; }
else { strMenu[3] = "CAMERA OFF"; }
if (gridMode == 1) { strMenu[4] = "GRID ON"; }
else { strMenu[4] = "GRID OFF"; }
// 描画
DrawGraph(0, 0, grp.BG[1], false);
DrawScore();
DrawHold(60.0f, 420.0f, 80.0f);
DrawNext(460.0f, 430.0f, 80.0f);
DrawField(200.0f, 430.0f, 80.0f);
if (cameraMode == 1) { DrawGraph(0, 0, grp.CameraIcon, false); }
DrawMenu(250, 120, 40, menu, strMenu);
}
// フルスクリーンの切り替え -------------------------------------------------------------------- //
void FullScreen(void)
{
if (winMode == 1) winMode = 0;
else winMode = 1;
ChangeWindowMode(winMode);
InitGrp();
}
// オプション ---------------------------------------------------------------------------------- //
void Option(void) {}
1>gamemain.cpp
gamemain.cpp(93): error C2440: '初期化中': 'const char [10]' から 'char *' に変換できません。
gamemain.cpp(93): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
gamemain.cpp(93): error C2440: '初期化中': 'const char [8]' から 'char *' に変換できません。
gamemain.cpp(93): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
gamemain.cpp(93): error C2440: '初期化中': 'const char [5]' から 'char *' に変換できません。
gamemain.cpp(93): note: 文字列リテラルからの変換では const 修飾子が失われます (/Zc:strictStrings を参照)
gamemain.cpp(525): warning C4838: 'unsigned int' から 'int' への変換には縮小変換が必要です
gamemain.cpp(542): warning C4838: 'unsigned int' から 'int' への変換には縮小変換が必要です
#include "gamemain.h"
// ゲーム中の音楽再生 -------------------------------------------------------------------------- //
void PlayMusicGame(void)
{
switch (scene) {
case _TITLE: PlayMusic("Data/Sound/fantasy01.mid", DX_PLAYTYPE_LOOP);break;
case _SELECT:
case _MAIN_GAME:
if (music == 0) { StopMusic(); }
if (music == 1) { PlayMusic("Data/Sound/fantasy04.mid", DX_PLAYTYPE_LOOP); }
if (music == 2) { PlayMusic("Data/Sound/up01.mid", DX_PLAYTYPE_LOOP); }
if (music == 3) { PlayMusic("Data/Sound/A.mid", DX_PLAYTYPE_LOOP); }
break;
case _GAME_OVER: PlayMusic("Data/Sound/orc02.mid", DX_PLAYTYPE_LOOP); break;
case _ENDING: PlayMusic("Data/Sound/A'.mid", DX_PLAYTYPE_LOOP); break;
}
}
// ゲームパッド、キーボードの入力状態の更新 ---------------------------------------------------- //
void Input(void)
{
int padInput = GetJoypadInputState(DX_INPUT_PAD1);
char keyBuff[256];
GetHitKeyStateAll(keyBuff);
// ←キー、←ボタン
if ((padInput & PAD_INPUT_LEFT) || keyBuff[KEY_INPUT_LEFT]) { Key[KEY_INPUT_LEFT] ++; }
else { Key[KEY_INPUT_LEFT] = 0; }
// ↑キー、↑ボタン
if ((padInput & PAD_INPUT_UP) || keyBuff[KEY_INPUT_UP]) { Key[KEY_INPUT_UP] ++; }
else { Key[KEY_INPUT_UP] = 0; }
// →キー、→ボタン
if ((padInput & PAD_INPUT_RIGHT) || keyBuff[KEY_INPUT_RIGHT]) { Key[KEY_INPUT_RIGHT] ++; }
else { Key[KEY_INPUT_RIGHT] = 0; }
// ↓キー、↓ボタン
if ((padInput & PAD_INPUT_DOWN) || keyBuff[KEY_INPUT_DOWN]) { Key[KEY_INPUT_DOWN] ++; }
else { Key[KEY_INPUT_DOWN] = 0; }
// Zキー、○ボタン
if ((padInput & PAD_INPUT_C) || keyBuff[KEY_INPUT_Z]) { Key[KEY_INPUT_Z] ++; }
else { Key[KEY_INPUT_Z] = 0; }
// Xキー、BkSpキー、×ボタン
if ((padInput & PAD_INPUT_B) || keyBuff[KEY_INPUT_X] || keyBuff[KEY_INPUT_BACK]) { Key[KEY_INPUT_X] ++; }
else { Key[KEY_INPUT_X] = 0; }
// Cキー, □ボタン(未使用)
if ((padInput & PAD_INPUT_X) || keyBuff[KEY_INPUT_C]) { Key[KEY_INPUT_C] ++; }
else { Key[KEY_INPUT_C] = 0; }
// spaceキー、Lボタン
if ((padInput & PAD_INPUT_L) || keyBuff[KEY_INPUT_SPACE]) { Key[KEY_INPUT_SPACE] ++; }
else { Key[KEY_INPUT_SPACE] = 0; }
// LShiftキー、Rボタン
if ((padInput & PAD_INPUT_R) || keyBuff[KEY_INPUT_LSHIFT]) { Key[KEY_INPUT_LSHIFT] ++; }
else { Key[KEY_INPUT_LSHIFT] = 0; }
// Enterキー、STARTボタン
if ((padInput & PAD_INPUT_START) || keyBuff[KEY_INPUT_RETURN]) { Key[KEY_INPUT_RETURN] ++; }
else { Key[KEY_INPUT_RETURN] = 0; }
// Tabキー : フルスクリーン
if (keyBuff[KEY_INPUT_TAB]) { Key[KEY_INPUT_TAB] ++; }
else { Key[KEY_INPUT_TAB] = 0; }
// Gキー : グリッドモード
if (keyBuff[KEY_INPUT_G]) { Key[KEY_INPUT_G] ++; }
else { Key[KEY_INPUT_G] = 0; }
}
// 画面モード:コントロール -------------------------------------------------------------------- //
void Controll(void)
{
static int menu = 0;
static bool isJoyPad = false;
// Zキー:決定
if (Key[KEY_INPUT_Z] == 1) {
PlaySoundMem(se.seDecide, DX_PLAYTYPE_BACK);
if (menu == 0) { isJoyPad = false; }
if (menu == 1) { isJoyPad = true; }
if (menu == 2) { scene = _TITLE; menu = 0; }
}
// Xキー:キャンセル
if (Key[KEY_INPUT_X] == 1) {
PlaySoundMem(se.seCancel, DX_PLAYTYPE_BACK);
scene = _TITLE; menu = 0;
}
// ↑↓キー:メニュー移動
if (Key[KEY_INPUT_DOWN] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu++; if (menu > 2) menu = 0; }
if (Key[KEY_INPUT_UP] == 1) { PlaySoundMem(se.seCursor, DX_PLAYTYPE_BACK); menu--; if (menu < 0) menu = 2; }
// 描画
DrawGraph(0, 0, grp.BG[4], false);
if (isJoyPad) DrawGraph(0, 0, grp.Controller, true);
else DrawGraph(0, 0, grp.KeyBoard, true);
static char* strOption[6] = { "KEY BOARD", "JOY PAD", "BACK" };
DrawMenu(100, 30, 40, menu, strOption);
}
// 描画:メニュー ------------------------------------------------------------------------------ //
void DrawMenu(int x, int y, int h, int menu, char* str[6])
{
int rgb = 0;
int colorS = GetColor(200, 200, 200);
int colorD = GetColor(100, 100, 100);
int color[6] = { colorD, colorD, colorD, colorD, colorD, colorD };
static int colorM = 0;
if (frame % 2 == 0) { rgb = GetRand(64) + 64; colorM = GetColor(rgb, rgb, rgb); }
color[menu] = colorM;
for (int i = 0; i < 6; i++) {
DrawStringToHandle(x - 2, y + h * i - 2, str[i], colorS, grp.font24);
DrawStringToHandle(x, y + h * i, str[i], color[i], grp.font24);
}
// カーソル
int move = -40;
if (frame % 40 < 20) { move += frame % 40 / 4; }
else { move -= frame % 40 / 4 - 10; }
DrawGraph(x + move, y + h * menu, grp.cursor, true);
}
// カメラモードの切り替え ---------------------------------------------------------------------- //
void changeCameraMode(void)
{
if (cameraMode == 1) cameraMode = 0;
else cameraMode = 1;
}
// グリッドモードの切り替え -------------------------------------------------------------------- //
void changeGridMode(void)
{
if (gridMode == 1) gridMode = 0;
else gridMode = 1;
}
// メインゲーム画面 ---------------------------------------------------------------------------- //
void MainGame(void)
{
// カメラの座標を初期化
static VECTOR CameraPos = { 320.0f, 300.0f, -420.0f };
if (!cameraMode) { CameraPos.x = 320.0f, CameraPos.y = 300.0f, CameraPos.z = -420.0f; }
// ピース接地時の遊びをつくる(固定時間)
if (fixTime > 0) fixTime--;
if (fixTime == 1) {
if (!MoveDown()) {
FixPiece();
if (cameraMode) { CameraPos.x = 320.0f; CameraPos.y = 300.0f; }
}
else { fixTime = fixingTime; }
}
// 自然落下
int f = 150 / level; // 落下スピード
if (cameraMode) { CameraPos.y -= 2.0f / f; }
if (frame % f == 0) {
if (!MoveDown()) { if (fixTime == 0) fixTime = fixingTime; }
}
// ↑キー:ハードドロップ
if (Key[KEY_INPUT_UP] == 1) {
HardDrop();
if (cameraMode) { CameraPos.x = 320.0f; CameraPos.y = 300.0f; }
}
// ↓キー:落下
if (Key[KEY_INPUT_DOWN] != 0 && Key[KEY_INPUT_DOWN] < 1000) {
if (MoveDown()) { CameraPos.y -= 0.1f; }
else {
if (fixTime == 0) fixTime = fixingTime;
if (fixTime >= 2 && fixTime <= fixingTime - 1) { // 固定時間中の↓キー強制固定
FixPiece();
fixTime = 0;
if (cameraMode) { CameraPos.x = 320.0f; CameraPos.y = 310.0f; }
}
Key[KEY_INPUT_DOWN] = 1000; // 次のテトリミノへの↓キーの影響を制御
}
}
// ←→キー:左右移動
if (Key[KEY_INPUT_LEFT] == 1 || Key[KEY_INPUT_LEFT] >= 30) {
if (MoveLeft()) {
if (fixTime != 0) { fixTime = fixingTime; }
if (cameraMode) { CameraPos.x -= 15.0f; }
}
}
else if (Key[KEY_INPUT_RIGHT] == 1 || Key[KEY_INPUT_RIGHT] >= 30) {
if (MoveRight()) {
if (fixTime != 0) { fixTime = fixingTime; }
if (cameraMode) CameraPos.x += 15.0f;
}
}
// Xキー:右回転
if (Key[KEY_INPUT_X] == 1) {
if (TurnPiece(1)) {
PlaySoundMem(se.seTurn, DX_PLAYTYPE_BACK);
if (fixTime != 0) { fixTime = fixingTime; }
}
else if (TurnPiece(0)) {
PlaySoundMem(se.seTurn, DX_PLAYTYPE_BACK);
if (fixTime != 0) { fixTime = fixingTime; }
}
}
// Zキー:左回転
if (Key[KEY_INPUT_Z] == 1) {
if (TurnPiece(0)) {
PlaySoundMem(se.seTurn, DX_PLAYTYPE_BACK);
if (fixTime != 0) { fixTime = fixingTime; }
}
else if (TurnPiece(1)) {
PlaySoundMem(se.seTurn, DX_PLAYTYPE_BACK);
if (fixTime != 0) { fixTime = fixingTime; }
}
}
// スペースキー:ホールド
if (Key[KEY_INPUT_SPACE] == 1) {
if (HoldPiece()) {
PlaySoundMem(se.seHold, DX_PLAYTYPE_NORMAL);
score += level * getScore[5];
if (score < 0) { score = 0; }
fixTime = 0;
if (cameraMode) { CameraPos.x = 320.0f; CameraPos.y = 300.0f; }
}
}
// Enterキー:ポーズ
if (Key[KEY_INPUT_RETURN] == 1) {
scene = _PAUSE;
PlaySoundMem(se.seHold, DX_PLAYTYPE_NORMAL);
}
// LShiftキー : カメラ
if (Key[KEY_INPUT_LSHIFT] == 1) {
changeCameraMode();
PlaySoundMem(se.seHold, DX_PLAYTYPE_NORMAL);
}
// Gキー : グリッドモード
if (Key[KEY_INPUT_G] == 1) {
changeGridMode();
PlaySoundMem(se.seHold, DX_PLAYTYPE_NORMAL);
}
GhostBlock(); // ゴーストブロックの位置を計算
SetCameraPositionAndTarget_UpVecY(CameraPos, VGet(320.0f, 240.0f, 1.0f)); // カメラの位置と注視点をセット、注視点は原点
// 描画
DrawGraph(0, 0, grp.BG[1], false);
DrawScore();
DrawHold(60.0f, 420.0f, 80.0f);
DrawNext(460.0f, 430.0f, 80.0f);
DrawField(200.0f, 430.0f, 80.0f);
if (cameraMode == 1) { DrawGraph(0, 0, grp.CameraIcon, false); }
}
// ピース端を調べる ---------------------------------------------------------------------------- //
int GetTopSide(void)
{
int length = 3;
for (int y = 1; y >= 0; y--) { for (int x = 0; x < 5; x++) { if (Piece[x][y]) { length--; break; } } }
return length;
}
int GetDownSide(void)
{
int length = 3;
for (int y = 3; y < 5; y++) { for (int x = 0; x < 5; x++) { if (Piece[x][y]) { length++; break; } } }
return length;
}
int GetLeftSide(void)
{
int length = 3;
for (int x = 1; x >= 0; x--) { for (int y = 0; y < 5; y++) { if (Piece[x][y]) { length--; break; } } }
return length;
}
int GetRightSide(void)
{
int length = 3;
for (int x = 3; x < 5; x++) { for (int y = 0; y < 5; y++) { if (Piece[x][y]) { length++; break; } } }
return length;
}
// ピースの↓移動 ------------------------------------------------------------------------------ //
bool MoveDown(void)
{
int bottom = GetDownSide();
if (PieceY < (FIELD_HEIGHT - bottom)) {
int count = 0;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (Piece[x][y] && field[PieceX + x][PieceY + y + 1]) { count++; }
}
}
if (!count) { PieceY++; }
else { return false; }
}
else { return false; }
return true;
}
// ピースの←移動 ------------------------------------------------------------------------------ //
bool MoveLeft(void)
{
if (PieceX > -(GetLeftSide() - 1)) {
int count = 0;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (Piece[x][y] && field[PieceX + x - 1][PieceY + y]) { count++; }
}
}
if (!count) { PieceX--; }
else { return false; }
}
else { return false; }
return true;
}
// ピースの→移動 ------------------------------------------------------------------------------ //
bool MoveRight(void)
{
if (PieceX < (FIELD_WIDTH - GetRightSide())) {
int count = 0;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (Piece[x][y] && field[PieceX + x + 1][PieceY + y]) { count++; }
}
}
if (!count) { PieceX++; }
else { return false; }
}
else { return false; }
return true;
}
// ピースの回転 -------------------------------------------------------------------------------- //
// 引数:0 左回転, 0以外 右回転
bool TurnPiece(int turn)
{
// 回転ピースを生成する
int turnPiece[5][5] = { 0 };
int turnPieceX = PieceX, turnPieceY = PieceY;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (turn == 0) { turnPiece[y][4 - x] = Piece[x][y]; } // 左回転
else { turnPiece[4 - y][x] = Piece[x][y]; } // 右回転
}
}
// 回転ピースの衝突判定
bool canTurn = true; //
bool leftWall = false; // 回転ピースが壁にめり込んでいるかを調べるフラグ
bool rightWall = false; //
bool bottomWall = false; //
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (turnPiece[x][y] != 0) {
int offsetX = turnPieceX + x, offsetY = turnPieceY + y;
if (offsetX < 0) { leftWall = true; } // 左壁との衝突
if (offsetX >= FIELD_WIDTH) { rightWall = true; } // 右壁との衝突
if (offsetY >= FIELD_HEIGHT) { bottomWall = true; } // 下壁との衝突
if (field[offsetX][offsetY] != 0) { bottomWall = true; } // フィールド上のブロックとの衝突
}
}
}
// 壁と衝突した場合、位置をずらす(スーパーローテーション)
if (leftWall) turnPieceX += 1;
if (rightWall) turnPieceX -= 1;
if (bottomWall) turnPieceY -= 1;
// ずらした位置での衝突判定
if (leftWall || rightWall || bottomWall) {
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (turnPiece[x][y] != 0) {
int offsetX = turnPieceX + x, offsetY = turnPieceY + y;
if (offsetX < 0 || offsetX >= FIELD_WIDTH || offsetY >= FIELD_HEIGHT || field[offsetX][offsetY] != 0) { canTurn = false; }
}
}
}
}
// 現在ピース←回転ピース
if (canTurn) {
memcpy(Piece, turnPiece, sizeof(int) * 25);
PieceX = turnPieceX;
PieceY = turnPieceY;
}
return canTurn;
}
// ピースのホールド ---------------------------------------------------------------------------- //
int HoldPiece(void)
{
if (holdFrag) { return 0; }
int copy[5][5] = { 0 };
memcpy(copy, Piece, sizeof(int) * 25);
memcpy(Piece, holdPiece, sizeof(int) * 25);
memcpy(holdPiece, copy, sizeof(int) * 25);
PieceX = 3;
PieceY = -1;
if (Piece[2][2] == 0) { AppearPiece(); }
holdFrag = true;
return 1;
}
// ゴーストブロック ---------------------------------------------------------------------------- //
void GhostBlock(void)
{
memcpy(ghostPiece, Piece, sizeof(int) * 25);
ghostPieceX = PieceX;
ghostPieceY = PieceY;
int bottom = GetDownSide();
for (int i = 0; i < FIELD_HEIGHT; i++) {
if (ghostPieceY < (FIELD_HEIGHT - bottom)) {
int count = 0;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (ghostPiece[x][y] && field[ghostPieceX + x][ghostPieceY + y + 1]) { count++; }
}
}
if (!count) { ghostPieceY++; }
else { break; }
}
else { break; }
}
}
// ハードドロップ ------------------------------------------------------------------------------ //
void HardDrop(void)
{
int bottom = GetDownSide();
for (int i = 0; i < FIELD_HEIGHT; i++) {
if (PieceY < (FIELD_HEIGHT - bottom)) {
int count = 0;
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (Piece[x][y] && field[PieceX + x][PieceY + y + 1]) { count++; }
}
}
if (!count) { PieceY++; }
else { break; }
}
else { break; }
}
FixPiece();
}
// ピースの固定 -------------------------------------------------------------------------------- //
void FixPiece(void)
{
PlaySoundMem(se.seSolid, DX_PLAYTYPE_NORMAL);
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (Piece[x][y] != 0) { field[PieceX + x][PieceY + y] = Piece[x][y]; }
}
}
// ライン消滅
int eraseLine = AdjustLine();
if (eraseLine != 0)
{
PlaySoundMem(se.seErase, DX_PLAYTYPE_NORMAL);
score += (int)(level * (getScore[eraseLine] + (getScore[6] * chain)));
if (score > bestScore) bestScore = score;
line += eraseLine;
if (level < line / 10 + 1) level = line / 10 + 1;
if (eraseLine == 4) chain++;
else chain = 0;
}
AppearPiece();
// ゲーム終了
if (field[5][1] || (PieceY + eraseLine + GetTopSide() - 1) < 0)
{
PlaySoundMem(se.seStart, DX_PLAYTYPE_BACK);
if (score < 100000) { scene = _GAME_OVER; PlayMusicGame(); }
else { scene = _ENDING; PlayMusicGame(); }
for (int x = 0; x < FIELD_WIDTH; x++) { for (int y = 0; y < FIELD_HEIGHT; y++) { field[x][y] = 0; } } // フィールドのクリア
for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { Piece[x][y] = 0; holdPiece[x][y] = 0; } } // ピース、ホールドのクリア
for (int i = 0; i < 3; i++) { for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { nextPiece[i][x][y] = 0; } } } // ネクストのクリア
level = 1;
line = 0;
score = 0;
chain = 0;
}
}
// ライン調整 ---------------------------------------------------------------------------------- //
int AdjustLine(void)
{
int delCount = 0;
for (int y = FIELD_HEIGHT - 1; y >= 0; ) {
int lineCount = 0;
for (int x = 0; x < FIELD_WIDTH; x++) { if (field[x][y]) lineCount++; }
if (lineCount == 0) break; /*これより上にブロックはない*/
if (lineCount != FIELD_WIDTH) { y--; continue; }
/*一行削除する*/
delCount++;
for (int iy = y; iy >= 0; iy--) {
for (int x = 0; x < FIELD_WIDTH; x++) {
if (iy > 0) { field[x][iy] = field[x][iy - 1]; }
else { field[x][0] = SH_NONE; } /*0 行より上はないので 0 で埋める*/
}
}
}
return delCount;
}
// ピースの出現 -------------------------------------------------------------------------------- //
void AppearPiece(void)
{
memcpy(Piece, nextPiece[0], sizeof(int) * 25);
memcpy(nextPiece[0], nextPiece[1], sizeof(int) * 25);
memcpy(nextPiece[1], nextPiece[2], sizeof(int) * 25);
// 新たにピースを生成
int piece[5][5] = { 0 };
int num = GetRand(6) + 1;
switch (num) {
case SH_I: for (int i = 1; i < 5; ++i) { piece[i][2] = num; } break;
case SH_O: piece[2][1] = num; piece[2][2] = num; piece[3][1] = num; piece[3][2] = num; break;
case SH_S: piece[1][2] = num; piece[2][1] = num; piece[2][2] = num; piece[3][1] = num; break;
case SH_Z: piece[1][1] = num; piece[2][1] = num; piece[2][2] = num; piece[3][2] = num; break;
case SH_J: piece[1][1] = num; for (int i = 1; i < 4; ++i) { piece[i][2] = num; } break;
case SH_L: piece[3][1] = num; for (int i = 1; i < 4; ++i) { piece[i][2] = num; } break;
case SH_T: piece[2][1] = num; for (int i = 1; i < 4; ++i) { piece[i][2] = num; } break;
}
memcpy(nextPiece[2], piece, sizeof(int) * 25);
PieceX = 2;
PieceY = -1;
holdFrag = false;
}
// 描画:スコア -------------------------------------------------------------------------------- //
void DrawScore(void)
{
int color[4][2] = {
{ GetColor(250, 150, 200), GetColor(150, 50, 100) },
{ GetColor(250, 200, 200), GetColor(150, 100, 100) },
{ GetColor(200, 150, 250), GetColor(100, 50, 150) },
{ GetColor(200, 200, 250), GetColor(100, 100, 150) }
};
int x = 40, y = 180, s = -2, h = 40;
DrawFormatStringToHandle(x + s, y + s, color[2][0], grp.font24, "SCORE");
DrawFormatStringToHandle(x, y, color[2][1], grp.font24, "SCORE");
DrawFormatStringToHandle(x + s, y + s + 30, color[2][0], grp.font24, " %d", score);
DrawFormatStringToHandle(x, y + 30, color[2][1], grp.font24, " %d", score);
DrawFormatStringToHandle(x + s, y + s + h * 2, color[3][0], grp.font24, "BEST");
DrawFormatStringToHandle(x, y + h * 2, color[3][1], grp.font24, "BEST");
DrawFormatStringToHandle(x + s, y + s + h * 2 + 30, color[3][0], grp.font24, " %d", bestScore);
DrawFormatStringToHandle(x, y + h * 2 + 30, color[3][1], grp.font24, " %d", bestScore);
x = 40, y = 350, s = -2, h = 50;
DrawFormatStringToHandle(x + s, y + s, color[1][0], grp.font24, "LINE %d", line);
DrawFormatStringToHandle(x, y, color[1][1], grp.font24, "LINE %d", line);
DrawFormatStringToHandle(x + s, y + s + h, color[0][0], grp.font24, "LEVEL %d", level);
DrawFormatStringToHandle(x, y + h, color[0][1], grp.font24, "LEVEL %d", level);
if (chain != 0) {
x = 460, y = 420, s = -2, h = 50;
static int colorChain[2] = { GetColor(200, 200, 200), 0 };
if (frame % 2 == 0) { colorChain[1] = GetColor(GetRand(64) + 64, GetRand(64) + 64, GetRand(64) + 64); }
DrawFormatStringToHandle(x + s, y + s, colorChain[0], grp.font24, "CHAIN %d", chain);
DrawFormatStringToHandle(x, y, colorChain[1], grp.font24, "CHAIN %d", chain);
}
}
// 描画:ホールド ------------------------------------------------------------------------------ //
void DrawHold(float X, float Y, float Z)
{
DrawStringToHandle(100 - 2, 20 - 2, "HOLD", GetColor(100, 100, 100), grp.font24);
DrawStringToHandle(100, 20, "HOLD", GetColor(180, 180, 180), grp.font24);
for (int i = 0; i < 4; ++i) {
for (int y = 4; y >= 0; y--) {
float X1 = X, Y1 = Y - (y * PIECE_SIZE), Z1 = Z;
for (int x = 0; x < 5; x++) {
bool isPiece = holdPiece[x][y] != 0;
//if ( i == 0 && gridMode == 1 ) { DrawPieceNone( SH_NONE, X1, Y1, Z1 ); }
if (i == 1 && isPiece) { DrawPieceSide(holdPiece[x][y], X1, Y1, Z1); }
if (i == 2 && isPiece) { DrawPieceTop(holdPiece[x][y], X1, Y1, Z1); }
if (i == 3 && isPiece) { DrawPieceFront(holdPiece[x][y], X1, Y1, Z1); }
X1 += PIECE_SIZE;
}
}
}
}
// 描画:ネクスト ------------------------------------------------------------------------------ //
void DrawNext(float X, float Y, float Z)
{
DrawStringToHandle(475 - 2, 20 - 2, "NEXT", GetColor(100, 100, 100), grp.font24);
DrawStringToHandle(475, 20, "NEXT", GetColor(180, 180, 180), grp.font24);
for (int j = 0; j < 3; ++j) {
for (int i = 0; i < 4; ++i) {
for (int y = 4; y >= 0; y--) {
float X1 = X, Y1 = Y - (y * PIECE_SIZE) - (j * PIECE_SIZE * 5), Z1 = Z;
for (int x = 0; x < 5; x++) {
bool isPiece = nextPiece[j][x][y] != 0;
//if ( i == 0 && gridMode == 1 ) { DrawPieceNone( SH_NONE, X1, Y1, Z1); }
if (i == 1 && isPiece) { DrawPieceSide(nextPiece[j][x][y], X1, Y1, Z1); }
if (i == 2 && isPiece) { DrawPieceTop(nextPiece[j][x][y], X1, Y1, Z1); }
if (i == 3 && isPiece) { DrawPieceFront(nextPiece[j][x][y], X1, Y1, Z1); }
X1 += PIECE_SIZE;
}
}
}
}
}
// 描画:フィールド ---------------------------------------------------------------------------- //
void DrawField(float X, float Y, float Z)
{
// フィールド背景の描画
if (gridMode == 0) {
int color = GetColor(32, 32, 32);
int color2 = GetColor(GetRand(32) + 64, GetRand(32) + 64, GetRand(32) + 64);
float Xf = X, Yf = Y + PIECE_SIZE, Zf = Z + PIECE_SIZE;
float Xf2 = X + PIECE_SIZE * FIELD_WIDTH, Yf2 = Yf - PIECE_SIZE * FIELD_HEIGHT;
DrawTriangle3D(VGet(Xf, Yf, Zf), VGet(Xf2, Yf, Zf), VGet(Xf, Yf2, Zf), color, true); // ベタ塗り
DrawTriangle3D(VGet(Xf2, Yf2, Zf), VGet(Xf2, Yf, Zf), VGet(Xf, Yf2, Zf), color, true); //
DrawLine3D(VGet(Xf, Yf, Zf), VGet(Xf2, Yf, Zf), color2); // 外枠
DrawLine3D(VGet(Xf, Yf, Zf), VGet(Xf, Yf2, Zf), color2); //
DrawLine3D(VGet(Xf2, Yf, Zf), VGet(Xf2, Yf2, Zf), color2); //
DrawLine3D(VGet(Xf, Yf2, Zf), VGet(Xf2, Yf2, Zf), color2); //
}
// ピースの描画
for (int i = 0; i < 4; ++i) {
for (int y = 0; y <= FIELD_HEIGHT - 1; y++) {
float X1 = X, Y1 = Y - y * PIECE_SIZE, Z1 = Z;
for (int x = 0; x < FIELD_WIDTH; x++) {
int px = x - PieceX, py = y - PieceY;
bool isPiece = px >= 0 && px < 5 && py >= 0 && py < 5 && Piece[px][py] != 0;
int gx = x - ghostPieceX, gy = y - ghostPieceY;
bool isGhost = gx >= 0 && gx < 5 && gy >= 0 && gy < 5 && ghostPiece[gx][gy] != 0;
if (i == 0 && gridMode == 1) { DrawPieceNone(SH_NONE, X1, Y1, Z1); }
if (i == 0 && field[x][y] == 0 && isGhost) { DrawPieceGhost(SH_NONE, X1, Y1, Z1); }
if (i == 1 && field[x][y] != 0) { DrawPieceSide(field[x][y], X1, Y1, Z1); }
if (i == 1 && field[x][y] == 0 && isPiece) { DrawPieceSide(Piece[px][py], X1, Y1, Z1); }
if (i == 2 && field[x][y] != 0) { DrawPieceTop(field[x][y], X1, Y1, Z1); }
if (i == 2 && field[x][y] == 0 && isPiece) { DrawPieceTop(Piece[px][py], X1, Y1, Z1); }
if (i == 3 && field[x][y] != 0) { DrawPieceFront(field[x][y], X1, Y1, Z1); }
if (i == 3 && field[x][y] == 0 && isPiece) { DrawPieceFront(Piece[px][py], X1, Y1, Z1); }
X1 += PIECE_SIZE;
}
}
}
}
// 描画:ピース:なし(グリッド線) ------------------------------------------------------------ //
void DrawPieceNone(int piece, float X1, float Y1, float Z1)
{
float X2 = X1 + PIECE_SIZE, Y2 = Y1 + PIECE_SIZE, Z2 = Z1 + PIECE_SIZE;
int Color = 0;
SetPieceColor(piece, Color, Color);
DrawLine3D(VGet(X1, Y1, Z2), VGet(X2, Y1, Z2), Color);
DrawLine3D(VGet(X2, Y1, Z2), VGet(X2, Y2, Z2), Color);
DrawLine3D(VGet(X2, Y2, Z2), VGet(X1, Y2, Z2), Color);
DrawLine3D(VGet(X1, Y2, Z2), VGet(X1, Y1, Z2), Color);
}
// 描画:ピース:ゴースト(影) ---------------------------------------------------------------- //
void DrawPieceGhost(int piece, float X1, float Y1, float Z1)
{
float X2 = X1 + PIECE_SIZE, Y2 = Y1 + PIECE_SIZE, Z2 = Z1 + PIECE_SIZE;
int Color = GetColor(128, 128, 128);
DrawTriangle3D(VGet(X1, Y1, Z2), VGet(X1, Y2, Z2), VGet(X2, Y1, Z2), Color, true);
DrawTriangle3D(VGet(X2, Y1, Z2), VGet(X1, Y2, Z2), VGet(X2, Y2, Z2), Color, true);
DrawPieceNone(piece, X1, Y1, Z1);
}
// 描画:ピース:側面 -------------------------------------------------------------------------- //
void DrawPieceSide(int piece, float X1, float Y1, float Z1)
{
float X2 = X1 + PIECE_SIZE, Y2 = Y1 + PIECE_SIZE, Z2 = Z1 + PIECE_SIZE;
int Color = 0, Color2 = 0;
SetPieceColor(piece, Color, Color2);
// 左面
DrawTriangle3D(VGet(X1, Y1, Z1), VGet(X1, Y2, Z1), VGet(X1, Y1, Z2), Color, true);
DrawTriangle3D(VGet(X1, Y2, Z2), VGet(X1, Y2, Z1), VGet(X1, Y1, Z2), Color, true);
// 右面
DrawTriangle3D(VGet(X2, Y1, Z1), VGet(X2, Y2, Z1), VGet(X2, Y1, Z2), Color, true);
DrawTriangle3D(VGet(X2, Y2, Z2), VGet(X2, Y2, Z1), VGet(X2, Y1, Z2), Color, true);
}
// 描画:ピース:上面 -------------------------------------------------------------------------- //
void DrawPieceTop(int piece, float X1, float Y1, float Z1)
{
float X2 = X1 + PIECE_SIZE, Y2 = Y1 + PIECE_SIZE, Z2 = Z1 + PIECE_SIZE;
int Color = 0, Color2 = 0;
SetPieceColor(piece, Color, Color2);
// 下面
DrawTriangle3D(VGet(X1, Y1, Z1), VGet(X2, Y1, Z1), VGet(X1, Y1, Z2), Color, true);
DrawTriangle3D(VGet(X2, Y1, Z2), VGet(X2, Y1, Z1), VGet(X1, Y1, Z2), Color, true);
// 上面
DrawTriangle3D(VGet(X1, Y2, Z1), VGet(X2, Y2, Z1), VGet(X1, Y2, Z2), Color, true);
DrawTriangle3D(VGet(X2, Y2, Z2), VGet(X2, Y2, Z1), VGet(X1, Y2, Z2), Color, true);
// 側面の線
DrawLine3D(VGet(X1, Y1, Z1), VGet(X1, Y1, Z2), Color2);
DrawLine3D(VGet(X2, Y1, Z1), VGet(X2, Y1, Z2), Color2);
DrawLine3D(VGet(X2, Y2, Z1), VGet(X2, Y2, Z2), Color2);
DrawLine3D(VGet(X1, Y2, Z1), VGet(X1, Y2, Z2), Color2);
}
// 描画:ピース:前面 -------------------------------------------------------------------------- //
void DrawPieceFront(int piece, float X1, float Y1, float Z1)
{
float X2 = X1 + PIECE_SIZE, Y2 = Y1 + PIECE_SIZE, Z2 = Z1 + PIECE_SIZE;
int Color = 0, Color2 = 0;
SetPieceColor(piece, Color, Color2);
// 前面
DrawTriangle3D(VGet(X1, Y1, Z1), VGet(X2, Y1, Z1), VGet(X1, Y2, Z1), Color, true);
DrawTriangle3D(VGet(X2, Y2, Z1), VGet(X2, Y1, Z1), VGet(X1, Y2, Z1), Color, true);
// 前面の線
DrawLine3D(VGet(X1, Y1, Z1), VGet(X2, Y1, Z1), Color2);
DrawLine3D(VGet(X2, Y1, Z1), VGet(X2, Y2, Z1), Color2);
DrawLine3D(VGet(X2, Y2, Z1), VGet(X1, Y2, Z1), Color2);
DrawLine3D(VGet(X1, Y2, Z1), VGet(X1, Y1, Z1), Color2);
}
// ピース色の設定 ------------------------------------------------------------------------------ //
void SetPieceColor(int piece, int& Color1, int& Color2)
{
int a = 240;
if (frame % 16 == 0) { a = GetRand(32) + 220; } // 微妙に光らせる色を設定
switch (piece) {
case SH_NONE: Color1 = GetColor(100, 100, 100); Color2 = GetColor(100, 100, 100); break;
case SH_I: Color1 = GetColor(100, a, a); Color2 = GetColor(50, 150, 150); break;
case SH_O: Color1 = GetColor(a, a, 100); Color2 = GetColor(150, 150, 50); break;
case SH_S: Color1 = GetColor(100, a, 100); Color2 = GetColor(50, 150, 50); break;
case SH_Z: Color1 = GetColor(a, 100, 100); Color2 = GetColor(150, 50, 50); break;
case SH_J: Color1 = GetColor(100, 100, a); Color2 = GetColor(50, 50, 150); break;
case SH_L: Color1 = GetColor(a, 150, 50); Color2 = GetColor(150, 50, 50); break;
case SH_T: Color1 = GetColor(a, 100, a); Color2 = GetColor(150, 50, 150); break;
}
}
// END OF FILE --------------------------------------------------------------------------------- //