ビルドは成立するのですが・・・。
Posted: 2015年3月25日(水) 06:16
現在ゲームプログラミングを参照して自分なりにまとめて作成してみたのですが、ビルドは成立するのですがデバックがうまくいきません・・・。
自分なりに改善しているのですが、初心者のため改善すべきポイントも正直あまりわからず、どうしてもうまくいきません・・・。
訂正ポイントなどを教えていただけると嬉しいです。
よろしくお願いいたします。
main.cpp
control.cpp
control.h
自分なりに改善しているのですが、初心者のため改善すべきポイントも正直あまりわからず、どうしてもうまくいきません・・・。
訂正ポイントなどを教えていただけると嬉しいです。
よろしくお願いいたします。
main.cpp
#include<Dxlib.h>
#include"control.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
/*ウインドウモード設定、Dxライブラリ初期化設定、描画先を裏画面に設定*/
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
int t1;
SetOutApplicationLogValidFlag(FALSE);
Option();
/*裏画面を表画面に反映、メッセージ処理、画面をクリア*/
while (ProcessMessage() == 0 && GetHitKeyStateAll == 0){
t1 = GetNowCount();
ClearDrawScreen();
Step1();
Step2();
while (GetNowCount() - t1 < 17);
}
DxLib_Init();
return(0);
}
control.cpp
#include<DxLib.h>
#include"control.h"
#define MAX 50
int Count = 0; /*カウントを格納する変数*/
int Time = 0; /*時間を格納する変数*/
int WHITE; /*WHITEを指定する*/
int Check_Color[MAX] = { 0, 1, 2, 1, 0, 2, 1, 1, 2, 0, 2, 1, 0, 2, 0, 1, 2, 0, 2, 0, }; /*だるまの順番*/
int Color[3]; /*だるまの色指定*/
int Key[4] = { KEY_INPUT_LEFT, KEY_INPUT_DOWN, KEY_INPUT_RIGHT, KEY_INPUT_RETURN }; /*押されたキーを格納する変数*/
int Check_Push[4]; /*押されたキーを格納*/
int Old_Push[4] = { 0, 0, 0, 0 }; /*過去に押されたキーを格納*/
int Font_30; /*文字のフォントを設定*/
int Font_100;
int Font_300;
int Font_600;
char key[256]; /*キーを格納する変数*/
char Allow[3][3] = { "←", "↓", "→" }; /*矢印を格納する変数*/
/*初期設定*/
void Option(){
WHITE = GetColor(255, 255, 255); /*WHITEの色を設定*/
Color[0] = GetColor(255, 0, 0); /*Color[0]に赤を設定*/
Color[1] = GetColor(0, 255, 0); /*Color[1]に緑を設定*/
Color[2] = GetColor(0, 0, 255); /*Color[2]に青を設定*/
Font_30 = CreateFontToHandle(NULL, 30, 3); /*文字のフォントの大きさや太さを設定*/
Font_100 = CreateFontToHandle(NULL, 100, 5);
Font_300 = CreateFontToHandle(NULL, 300, 5);
Font_600 = CreateFontToHandle(NULL, 600, 5);
}
/*スキップを表示*/
void Skip(){
DrawStringToHandle(500, 450, "Skip:ENTER", WHITE, Font_30);
}
/*リトライを表示*/
void Retry(){
DrawStringToHandle(500, 450, "Retry:ENTER", WHITE, Font_30);
}
/*オープニング設定*/
void Opening(){
if (Count < 270){
if (Count >= 0){
if (Count < 10)
DrawStringToHandle(720 - 60 * Count, 50, "あなたの", WHITE, Font_100);
else
DrawStringToHandle(120, 50, "あなたの", WHITE, Font_100);
}
if (Count >= 90){
if (Count < 100)
DrawStringToHandle(180 - 600 + 60 * (Count - 90), 150, "瞬発力は", WHITE, Font_100);
else
DrawStringToHandle(180, 150, "瞬発力は", WHITE, Font_100);
}
if (Count >= 180){
if (Count < 190){
DrawStringToHandle(680 - 60 * (Count - 180), 300, "一体", WHITE, Font_100);
DrawStringToHandle(180 - 600 + 60 * (Count - 180), 300, "どれほどか?", WHITE, Font_100);
}
else{
DrawStringToHandle(80, 300, "一体", WHITE, Font_100);
DrawStringToHandle(180, 300, "どれほどか?", WHITE, Font_100);
}
}
}
if (Count >= 270 && Count < 330){
DrawStringToHandle(90, 190, "ルール説明", WHITE, Font_100);
}
if (Check_Push[3] == 1){
Count = 330;
}
Skip();
}
/*キーの入力状態を判断*/
void KeyCheck(){
for (int i = 0; i < 4;i++){
if (key[Key[i]] == 1 && Old_Push[i] == 0)
Check_Push[i] = 1;
else
Check_Push[i] = 0;
}
for (int i = 0; i < 4; i++){
Old_Push[i] = Key[Key[i]];
}
}
/*説明画面*/
void Demo(){
static int X0[6] = { 0, 1, 2, 1, 0, 2 }, X1[] = { 0, 2 };
for (int i = 0; i < 6; i++){
if (Count>500 + i * 60 && Count <= 560 + i * 60)
key[Key[X0[i]]] = 1;
}
for (int i = 0; i < 2; i++){
if (Count>900 + i * 60 && Count <= 960 + i * 60)
key[Key[X1[i]]] = 1;
}
}
/*説明画面2*/
void Demo2(){
if (Count <= 1020){
DrawStringToHandle(20, 20, "ゲーム説明", WHITE, Font_100);
if (Check_Push[3] == 1)
Count = 1020;
Skip();
}
if (Count == 1140){
for (int i = 0; i < MAX; i++){
Check_Color[i] = GetRand(2);
if (i > 1){
if (Check_Color[i] == Check_Color[i - 1] && Check_Color[i - 1] == Check_Color[i - 2])
i--;
}
}
}
}
/*カウントダウン*/
void Countdown(){
DrawStringToHandle(380 - (Count - 380), 180, "同じ色の十字キーを素早く押せ!", WHITE, Font_30);
if (Count > 1020 && Count <= 1140)
DrawStringToHandle(100, 190, "Are You Ready?", WHITE,Font_100);
if (Count > 1140 && Count <= 1230)
DrawStringToHandle(320-150, 90, "3", WHITE, Font_300);
if (Count > 1230 && Count <= 1320)
DrawStringToHandle(320-150, 90, "2", WHITE, Font_300);
if (Count > 1320 && Count <= 1410)
DrawStringToHandle(320-150, 90, "1", WHITE, Font_300);
}
/*だるまの表示*/
void Daruma_Display(int Now){
int n;
n = Now;
for (int i = 0; i < 15; i++){
DrawBox(320 - 30, 300 - (i + 1) * 20, 320 + 30, 300 - i * 20, Color[Check_Color[i]],TRUE);
DrawBox(320 - 30, 300 - (i + 1) * 20, 320 + 30, 300 - i * 20, WHITE, FALSE);
n++;
if (n >= MAX)
break;
}
}
/*矢印と円の表示*/
void Circle_Display(){
for (int i = 0; i < 3; i++){
if (key[Key[i]] == 1)
DrawCircle(170 + i * 150, 400, 70, Color[i]);
else
DrawCircle(170 + i * 150, 400, 50, Color[i]);
DrawFormatStringToHandle(120 + i * 150, 350, WHITE, Font_100, Allow[3]);
}
}
/**/
void Game(){
static int Pass = 0, Correct = 0, Fault = 0, Fault_Count = 0;
Daruma_Display(Correct);
if (Fault == 0 && Time == 0){
if (Check_Push[Check_Color[Correct]] == 1)
Correct++;
else{
for (int i = 0; i < 3; i++){
if (Check_Push[i] == 1){
Fault = 60;
Fault_Count++;
}
}
}
if (Correct == MAX)
Time = Count;
}
Circle_Display();
if (Fault>0 && Time == 0){
DrawStringToHandle(320 - 300, 240 - 300, "×", Color[0], Font_600);
Fault--;
}
if (Time > 0){
DrawStringToHandle(70, 50, "Clear!", WHITE, Font_100);
DrawFormatStringToHandle(200, 200, WHITE, Font_30, "TIME %.3f", (double)(Time - 1410)*17.0f / 1000.0f);
DrawFormatStringToHandle(250, 250, WHITE, Font_30, "ミス回数 %d回", Fault_Count);
Retry();
if (Check_Push[3] == 1){
Fault_Count = 0;
Time = 0;
Count = 1020;
Correct = 0;
}
}
if (Count > 1410 && Count <= 1500)
DrawStringToHandle(170, 190, "START!", WHITE, Font_100);
}
void Step1(){
if (Count >= 330 && Count <= 1410)
Demo();
KeyCheck();
}
void Step2(){
if (Count >= 0 && Count < 330)
Opening();
else if (Count >= 330 && Count <= 1410){
if (Count <= 1020 || Count > 1140)
Game();
Demo2();
Countdown();
}
else
Game();
ScreenFlip();
Count++;
}
control.h