Пример #1
0
// 
// メインプログラム
// 
int main() {
	// アプリウインドウの準備
	AppEnv app_env(Window::WIDTH, Window::HEIGHT);

	// ハイスコア
	int hi_score = 0;
	{
		std::ifstream fstr("score.txt");
		if (fstr){
			fstr >> hi_score;
		}
	}
	// 結果画面からタイトル画面に戻るループ
	while (1){
		// 背景を動かす変数
		float scroll_back = 0;
		// 飛距離
		int jump_distance = 0;

		// タイトル画面
		{
			// タイトル画像
			Texture title_image("res/title_back.png");
			Texture title_rogo("res/title.png");
			Texture GAMESTART("res/GAME START.png");

			// 「Run and Jump」演出用変数を用意
			float title_angle = 0.0;
			int blink = 0;
			// メインループ
			while (1) {
				// ウィンドウが閉じられたらアプリを終了
				if (!app_env.isOpen()) return 0;

				// 描画準備
				app_env.setupDraw();

				// 入力による操作(break本編へ,returnアプリ終了)
				if (app_env.isPushButton(Mouse::RIGHT)) break;
				if (app_env.isPushButton(Mouse::LEFT))  break;
				if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

				// タイトル画像
				drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
					0, 0, 2048, 1024,
					title_image,
					Color(1, 1, 1));

				// タイトルロゴの色にサイン,コサインを利用
				title_angle += 0.05;
				float title_sin = std::abs(std::sin(title_angle));
				float title_cos = std::abs(std::cos(title_angle));

				// タイトルロゴを表示
				drawTextureBox(0 - 1024 / 2, 512 / 2, 565, 80,
					0, 512, 565, 80,
					title_rogo,
					Color(0, title_sin, title_cos),
					0,
					Vec2f(2, 2),
					Vec2f(0, 0));

				// 「GAME START」を表示
				blink += 1;
				int value = (blink / 30) % 2;

				if (value){
					drawTextureBox(0 - 360, 0 - 480, 512, 256,
						0, 0, 512, 256,
						GAMESTART,
						Color(1, 0, 0),
						0,
						Vec2f(1.8, 1.8),
						Vec2f(0, 0));
				}
				// 画面を更新
				app_env.update();
			}
			// 入力のフラッシュ
			app_env.flushInput();
		}
		// 操作説明画面
		{
		// 操作説明画像
		Texture tutorial("res/tuto.png");
		Texture back("res/field.png");

		// メインループ
		while (1) {
			// ウィンドウが閉じられたらアプリを終了
			if (!app_env.isOpen()) return 0;

			// 描画準備
			app_env.setupDraw();

			// 入力による操作(break本編へ,returnアプリ終了)
			if (app_env.isPushButton(Mouse::RIGHT)) break;
			if (app_env.isPushButton(Mouse::LEFT))  break;
			if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
			if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

			// 操作説明画面
			drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
				0, 0, 2048, 1024,
				back,
				Color(1, 1, 1));

			drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
				0, 0, 2048, 1024,
				tutorial,
				Color(1, 1, 1));

			// 画面を更新
			app_env.update();

			// 入力のフラッシュ
			app_env.flushInput();
		}

		// 本編
		{
			// 本編の画像
			Texture back("res/field.png");
			Texture run("res/run.png");
			Texture jump("res/jump.png");
			Texture back2("res/field2.png");
			Texture back3("res/field3.png");
			Texture dispnumber("res/number.png");

			int blink = 0;
			// キャラの表示位置
			float x = 0 - 1024 / 1.5;
			float y = 0 - 380;
			// キャラの加速度
			float a = 0;
			// 重力加速度
			float g = -0.2;
			// キャラの速度
			float v = 0;
			// キャラのジャンプ回数
			int jump_count = 3;
			// キャラのジャンプスイッチ
			int jump_switch = 0;

			// メインループ
			while (1){
				// ウインドウが閉じられたら終了
				if (!app_env.isOpen()) return 0;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

				// 描画準備
				app_env.setupDraw();

				// キャラクターのモーション情報
				struct Texture {
					// 画像からの切り抜き情報
					float texture_x, texture_y;
					float texture_width, texture_height;
				};

				// キャラクターの情報を配列で用意
				Texture move_info[] = {
					{ 0 * 100, 0, 100, 150 },
					{ 1 * 100, 0, 100, 150 },
					{ 2 * 100, 0, 100, 150 },
					{ 3 * 100, 0, 100, 150 },
					{ 4 * 100, 0, 100, 150 },
					{ 5 * 100, 0, 100, 150 },
					{ 6 * 100, 0, 100, 150 },
				};

				// 数字の情報を配列で用意
				Texture number_info[] = {
					{ 0 * 50, 0, 29, 55 },
					{ 1 * 50, 0, 48, 54 },
					{ 2 * 50, 0, 44, 55 },
					{ 3 * 50, 0, 45, 54 },
					{ 4 * 50, 0, 47, 54 },
					{ 5 * 50, 0, 43, 55 },
					{ 6 * 50, 0, 43, 54 },
					{ 7 * 50, 0, 45, 55 },
					{ 8 * 50, 0, 43, 55 },
					{ 9 * 50, 0, 38, 57 },
				};

				// キャラクターの情報を配列から取り出す
				Texture move_chara1 = move_info[0];
				Texture move_chara2 = move_info[1];
				Texture move_chara3 = move_info[2];
				Texture move_chara4 = move_info[3];
				Texture move_chara5 = move_info[4];
				Texture move_chara6 = move_info[5];
				Texture move_chara7 = move_info[6];

				Texture disp_num1 = number_info[0];
				Texture disp_num2 = number_info[1];
				Texture disp_num3 = number_info[2];
				Texture disp_num4 = number_info[3];
				Texture disp_num5 = number_info[4];
				Texture disp_num6 = number_info[5];
				Texture disp_num7 = number_info[6];
				Texture disp_num8 = number_info[7];
				Texture disp_num9 = number_info[8];
				Texture disp_num0 = number_info[9];

				// ゲーム本編
				{
					
					// キャラクター処理
					{
						// 本編背景を連ねて表示に必要な変数
						int draw_back = 0;
						float num_x = -Window::WIDTH / 2 + 50;
						float num_y = -Window::HEIGHT / 2 + 25;

						// 本編画像を表示					
						draw_back += 2000;

						if (app_env.isPressKey(GLFW_KEY_RIGHT)){
							scroll_back += 20;
						}

						drawTextureBox(0 - 2048 / 2 - scroll_back, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 2000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 4000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back2,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 6000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 8000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 10000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						// キャラをジャンプさせる
						if (app_env.isPushKey(GLFW_KEY_SPACE) && jump_count > 0){
							a = 10 + g;
							jump_count--;
							jump_switch = 1;
						}
						else{
							a = g;
						}
						v = v + a;
						y = y + ((1 / 2) * a) + v;

						if (y < (0 - 380)) {
							v = 0;
							y = 0 - 380;
							// キャラが飛んでから地面に足をついたら結果画面へ
							if (jump_switch == 1 && y <= 0 - 380){
								break;
							}
						}

						// キャラが画面上端を超えたら止める
						if (y >= 512 - 200){
							y = 512 - 200;
							v = 0;
						}

						// キャラを表示
						if (app_env.isPressKey(GLFW_KEY_RIGHT)){
							blink += 1;
						}
						int value = (blink / 3) % 7;

						drawTextureBox(x, y, move_info[value].texture_width, move_info[value].texture_height,
							move_info[value].texture_x, move_info[value].texture_y,
							move_info[value].texture_width, move_info[value].texture_height,
							run,
							Color(0, 0, 0),
							0,
							Vec2f(1.5, 1.5),
							Vec2f(0, 0));
						

						// 飛距離を表示する
						if (scroll_back >= 3250 - x && jump_count >= 0){
							jump_distance = (scroll_back - 4100) / 20;
						}
						// 線を越えても飛んでなかったらファウル
						if (scroll_back >= 3300 - x && jump_count == 3){
							jump_distance = 0;
							break;
						}

						// 100の位
						if (jump_distance >= 100){
							int hundred_distance = jump_distance / 100;
							if (hundred_distance != 0){
								drawTextureBox(num_x, num_y, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
									number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
									number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (hundred_distance == 0){
								drawTextureBox(num_x, num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
						// 10の位
						if (jump_distance >= 10){
							int ten_distance = jump_distance % 100 / 10;
							if (ten_distance != 0){
								drawTextureBox(num_x + 120, num_y, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
									number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
									number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (ten_distance == 0){
								drawTextureBox(num_x + 120 , num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
						// 1の位
						if (jump_distance >= 1){
							int one_distance = jump_distance % 10;
							if (one_distance != 0){
								drawTextureBox(num_x + 240, num_y, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
									number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
									number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (one_distance == 0){
								drawTextureBox(num_x + 240, num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
					}
					// ハイスコア更新チェック
					if (jump_distance > hi_score){
						std::ofstream fstr("score.txt");
						if (fstr){
							fstr << jump_distance << std::endl;
							hi_score = jump_distance;
						}
					}

					// 画面を更新
					app_env.update();
				}
				// 入力のフラッシュ
				app_env.flushInput();
			}

			// 結果画面
			{
				Texture result("res/result.png");
				Texture back("res/field.png");
				Texture dispnumber("res/number.png");
				Texture Return("res/Return to Title");

				// メインループ
				while (1) {
					// ウィンドウが閉じられたらアプリを終了
					if (!app_env.isOpen()) return 0;

					float num_x = 0 - 25 / 2;
					float num_y_now = 0 - 30 / 2;
					float num_y_hi = 0 - 30 / 2 - 270;

					// 描画準備
					app_env.setupDraw();

					// 入力による操作(break本編へ,returnアプリ終了)
					if (app_env.isPushButton(Mouse::RIGHT)) break;
					if (app_env.isPushButton(Mouse::LEFT))  break;
					if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
					if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

					// 結果画面表示
					drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
						0, 0, 2048, 1024,
						back,
						Color(1, 1, 1));

					drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
						0, 0, 2048, 1024,
						result,
						Color(1, 1, 1));

					// 「Return to Title」を表示
					drawTextureBox(0 - 360, 0 - 480, 512, 256,
							0, 0, 512, 256,
							Return,
							Color(1, 0, 0),
							0,
							Vec2f(1.8, 1.8),
							Vec2f(0, 0));

					// 100の位
					if (jump_distance >= 100){
						int hundred_distance = jump_distance / 100;
						if (hundred_distance != 0){
							drawTextureBox(num_x, num_y_now, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
								number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (hundred_distance == 0){
							drawTextureBox(num_x, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 10の位
					if (jump_distance >= 10){
						int ten_distance = jump_distance % 100 / 10;
						if (ten_distance != 0){
							drawTextureBox(num_x + 120, num_y_now, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
								number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (ten_distance == 0){
							drawTextureBox(num_x + 120, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 1の位
					if (jump_distance >= 1){
						int one_distance = jump_distance % 10;
						if (one_distance != 0){
							drawTextureBox(num_x + 240, num_y_now, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
								number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (one_distance == 0){
							drawTextureBox(num_x + 240, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// ハイスコア
					// 100の位
					if (jump_distance >= 100){
						int hundred_distance = jump_distance / 100;
						if (hundred_distance != 0){
							drawTextureBox(num_x, num_y_hi, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
								number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (hundred_distance == 0){
							drawTextureBox(num_x, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 10の位
					if (jump_distance >= 10){
						int ten_distance = jump_distance % 100 / 10;
						if (ten_distance != 0){
							drawTextureBox(num_x + 120, num_y_hi, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
								number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (ten_distance == 0){
							drawTextureBox(num_x + 120, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 1の位
					if (jump_distance >= 1){
						int one_distance = jump_distance % 10;
						if (one_distance != 0){
							drawTextureBox(num_x + 240, num_y_hi, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
								number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (one_distance == 0){
							drawTextureBox(num_x + 240, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}

					// 画面を更新
					app_env.update();
				}
				// 入力のフラッシュ
				app_env.flushInput();
			}
		}
	}
		// アプリ終了
	}
}
Пример #2
0
// 
// メインプログラム//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
int main() {
	// アプリウインドウの準備
	AppEnv app_env(Window::WIDTH, Window::HEIGHT);

	int	LINE_y1 = 0;
	int pointer_mark1 = 0;
	int pointer_mark2 = 0;
	int pointer_mark3 = 0;

	while (1){
		srand((unsigned)time(NULL));

		//
		int hi_score = 0;
		{
			std::ifstream fstr("res/score.txt");
			if (fstr){
				fstr >> hi_score;
			}
		}

		//タイトル画面///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		{
			//タイトル画像
			Texture title_image("res/title1.png");

			
			
			
				//サウンドの読み込み
				Media sound("res/Clover1.wav");
				//再生
				sound.play();
				sound.looping(true);
				//音量(0.0~1.0)
				sound.gain(0.1);

			
			
			
			//停止
			//sound.stop();
			//一時停止
			//sound.pause();
			
			

			//「Click to Start」演出用変数を用意
			float title_angle = 0.0;

			int blink = 0;



			// メインループ
			while (1) {

				// ウィンドウが閉じられたらアプリを終了
				if (!app_env.isOpen()) return 0;

				// 描画準備
				app_env.setupDraw();



				//マウスのボタンがクリックされたらゲーム本編へ
				if (app_env.isPushButton(Mouse::LEFT)) break;
				//if (app_env.isPushButton(Mouse::RIGHT))break;
				if (app_env.isPushKey(GLFW_KEY_ENTER)) break;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

				//「Click to Start」演出用変数を変更
				title_angle += 0.05;
				//sinの値の絶対値を色に利用
				int value = (blink / 30) % 2;
				float title_color = std::abs(std::sin(title_angle));
				float		color = 0;
				if (title_color = 1){
					color = 1;
					if (color = 1){
						color = std::abs(std::sin(title_angle));
					}
				}


				blink += 1;

				std::cout << blink << std::endl;	//←??

				if (value >= 0) {
					title_color = 1;
					if (value < 1) {
						title_color = 0;
					}
				}



				if (value){
					//タイトルロゴ
					drawTextureBox(0 - 512 / 2,//半分の計算をPCにさせると簡単
						0 + 512 / 2, 512, 512 / 4,
						0, 0, 512, 512 / 4,
						title_image,
						Color(title_color, value, value));
				}
				//「あみだくじ」
				drawTextureBox(0 - 512 / 2,
					0 - 512 / 2,
					512, 512,
					0, 512 / 4,
					512, 512 - 512 / 4,
					title_image,
					Color(1, 1, 1));



				//ハイスコア
				//dispPlayPoint(hi_score);

				// 画面を更新
				app_env.update();
			}
			//入力のフラッシュ
			app_env.flushInput();
		}

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//ゲームで使うさまざまな変数
		//プレイ時間(15秒)
		int time_1 = 15;
		int play_time = 60 * time_1;	//60=1秒間に60ループ
		//得点
		int play_point = 0;

		//取り出したカードの場所
		//int card_index = 0;
		

		app_env.random().setSeed(rand());




		//ゲーム本編/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		{
			
			int top_y = HEIGHT / 3;			//縦線の始点
			int under_y = -HEIGHT / 3;		//縦線の終点
			int top_plus = top_y + 20;		//スタートの位置
			int under_minus = under_y - 20;	//ゴールの位置

			//縦線の配置
			float A_X = WIDTH / 3;
			float B_X = WIDTH / 6;
			float C_X = 0;
			float D_X = -(WIDTH / 6);
			float E_X = -(WIDTH / 3);

			//ドット位置の構造体
			struct Dot_point{
				int x, y;
				bool dot;
				int x2, y2;
				bool flag;
			};
			
			//ドット位置
			Dot_point pointer[20] = {
				//A_X
				{ A_X, top_plus, false, B_X, top_plus, false },
				{ A_X, top_plus, false, C_X, top_plus, false },
				{ A_X, top_plus, false, D_X, top_plus, false },
				{ A_X, top_plus, false, E_X, top_plus, false },
				//B_X
				{ B_X, top_plus, false, A_X, top_plus, false },
				{ B_X, top_plus, false, C_X, top_plus, false },
				{ B_X, top_plus, false, D_X, top_plus, false },
				{ B_X, top_plus, false, E_X, top_plus, false },
				//C_X
				{ C_X, top_plus, false, A_X, top_plus, false },
				{ C_X, top_plus, false, B_X, top_plus, false },
				{ C_X, top_plus, false, D_X, top_plus, false },
				{ C_X, top_plus, false, E_X, top_plus, false },
				//D_X
				{ D_X, top_plus, false, A_X, top_plus, false },
				{ D_X, top_plus, false, B_X, top_plus, false },
				{ D_X, top_plus, false, C_X, top_plus, false },
				{ D_X, top_plus, false, E_X, top_plus, false },
				//E_X
				{ E_X, top_plus, false, A_X, top_plus, false },
				{ E_X, top_plus, false, B_X, top_plus, false },
				{ E_X, top_plus, false, C_X, top_plus, false },
				{ E_X, top_plus, false, D_X, top_plus, false },
				//


			};

			


			//ライン位置の構造体
			struct LINE{
				int y1;				//横線のy座標(高さ)
				int x1;				//横線の場所(始点)
				int x2;				//横線の場所(終点)
				bool LINE_ON;		//横線の表示設定
				bool Cursor_ON;		//カーソルが乗っているかの判定
				int R,B,G;			//色
				int n18;			//わかりやすく数字振り分けただけ
				
			};
			//横線の数列
			LINE side[18] = {
				//一番右の横線0~3
				{ 290, A_X, B_X, true, true, 1, 0, 0,0 },
				{ 145, A_X, B_X, true, true, 1, 0, 0,1 },
				{ 0, A_X, B_X, true, true, 1, 0, 0 ,2},
				{ -145, A_X, B_X, true, true, 1, 0, 0,3 },
				
				//右から二番目の横線4~6
				{ 218, B_X, C_X, true, true, 1, 0, 0 ,5},
				{ 73, B_X, C_X, true, true, 1, 0, 0 ,6},
				{ -218, B_X, C_X, true, true, 1, 0, 0 ,8},

				//左から二番目の横線7~10
				{ 290, C_X, D_X, true, true, 1, 0, 0 ,9},
				{ 145, C_X, D_X, true, true, 1, 0, 0 ,10},
				{ 0, C_X, D_X, true, true, 1, 0, 0 ,11},
				{ -145, C_X, D_X, true, true, 1, 0, 0 ,12},
				
				//一番左の横線11~13
				{ 218, D_X, E_X, true, true, 1, 0, 0 ,14},
				{ 73, D_X, E_X, true, true, 1, 0, 0 ,15},
				{ -218, D_X, E_X, true, true, 1, 0, 0 ,17},
				

				//残す横線14~17
				{ -290, A_X, B_X, true, true, 1, 0, 0 ,4},
				{ -73, B_X, C_X, true, true, 1, 0, 0 ,7},
				{ -290, C_X, D_X, true, true, 1, 0, 0 ,13},
				{ -73, D_X, E_X, true, true, 1, 0, 0 ,16},
				

			};



			//あたり判定座標
			
			int Y_1[]{ 290, 145, 0, -145, -290, 
					   218, 73, -73, -218};
			
			int i = 0;
			int a = 0;
			while(true)
			{
			//ifじゃいけないん?
			if (i <= 5){

				LINE_y1 = app_env.random().fromFirstToLast(0, 13);
				
				side[LINE_y1].LINE_ON = false;

				i++;
				
			/*{
				return top_y + (under_y - top_y + 1) * fromZeroToOne()
				}*/
			//while (i < 52){
			//std::swap(cards_info[i],
			//cards_info[app_env.random().fromZeroToLast(52)]);
			
			}

			
			
			
			if (a < 1){		
				pointer_mark1 = app_env.random().fromFirstToLast(0, 19);
				
				pointer[pointer_mark1].dot = true;
				a++;
			}
			
			
			if((a > 1) && (i >= 6))
			{
				break;
			}


			//メインループ
			while (1){
				//ウインドウが閉じられたら終了
				if (!app_env.isOpen()) return 0;
				//描画準備
				app_env.setupDraw();
				//if (!app_env.isPressKey(GLFW_KEY_ENTER)){

				
				
				//表示サイズ(残り時間を矩形の横幅で表現)
				
		
				

				//縦線
				drawLine(A_X, top_y, A_X, under_y, 5, Color(1, 1, 1));
				drawLine(B_X, top_y, B_X, under_y, 5, Color(1, 1, 1));
				drawLine(C_X, top_y, C_X, under_y, 5, Color(1, 1, 1));
				drawLine(D_X, top_y, D_X, under_y, 5, Color(1, 1, 1));
				drawLine(E_X, top_y, E_X, under_y, 5, Color(1, 1, 1));


				//マウスの位置を変数にコピー
				Vec2f mouse_pos = app_env.mousePosition();
				//左クリックをしたかどうかを変数にコピー
				bool left_click = app_env.isPushButton(Mouse::LEFT);

				//横線
				{
					int a = 0;
					int move_x = 0, move_y = 0;
					int yyy = 0;

					int sss = 0;
					int move_d = 0;
					int i = 0;
					/*while文じゃなくてもif文で条件ループはかけると思う。*/
					if (i <= 17)
					{
						if (side[i].LINE_ON){
							drawLine(side[i].x1, side[i].y1, side[i].x2, side[i].y1, 5, Color(1, 1, 1));		//ライン表示
						}
						i++;
					}
					if (a <= 20){
						if (pointer[a].dot){
							drawPoint(pointer[a].x, pointer[a].y, 100, Color(1, 0, 0));							//ドット表示
							drawPoint(pointer[a].x2, pointer[a].y2, 100, Color(1, 0, 0));						//ドット表示
							move_y = move_y - 1;
							move_x = move_x + 1;
							move_d = move_d - 1;

							if (pointer[a].flag = true){														//もしフラグがオンの時

								pointer[a].y += move_y;
								pointer[a].y2 += move_y;
								if (pointer[a].y == Y_1[yyy],side[sss].y1 == Y_1[yyy], yyy <= 8, sss <= 17){													//Y座標が218なら
									
									sss++;
									
										if (side[sss].LINE_ON == true) {												//横線の表示がオンなら
											if (pointer[a].x == B_X) {												//右側なら
												pointer[a].y = Y_1[yyy];
												pointer[a].x += move_d;
												if (pointer[a].x == C_X){											//左に付いたら
													pointer[a].y += move_y;
												}

											}
											else
											{
												if (pointer[a].x == C_X){
													pointer[a].y = Y_1[yyy];
													pointer[a].x += move_x;
													if (pointer[a].x == B_X){
														pointer[a].y += move_y;
													}
												}

											}
											if (pointer[a].x == D_X) {
												pointer[a].y = Y_1[yyy];
												pointer[a].x += move_d;
												if (pointer[a].x == E_X){
													pointer[a].y += move_y;
												}

											}
											else
											{
												if (pointer[a].x == E_X){
													pointer[a].y = Y_1[yyy];
													pointer[a].x += move_x;
													if (pointer[a].x == D_X){
														pointer[a].y += move_y;
													}
												}

											}
										}
											
									yyy++;
								}
								
								if (pointer[a].y <= under_y){
									pointer[a].y = under_y;
								}
								if (pointer[a].y2 <= under_y){
									pointer[a].y2 = under_y;
								}
								if (pointer[a].y == pointer[a].y2){
									break;
								}

								move_y++;

							}
						}



						a++;
					}
						

					

					//残り時間表示
					{
						//位置表示
						float x = -100;
						float y = -Window::HEIGHT / 2 + 50;

						//表示サイズ(残り時間を矩形の横幅で表現)
						float width = (play_time * 200) / (60 * time_1);
						float height = 30;

						//残り時間を矩形で表示
						//drawFillBox(x + width, y, 200-width, height, Color(0, 1, 1));  //右から左に増える
						drawFillBox(x + (200-width), y, width, height, Color(0, 1, 1));  //左から右に減る
						//drawFillBox(x-(200+width), y, width, height, Color(0, 1, 1));
						//ゲージを逆にするならxの値を(x+(200-width))にする
						//0から増やす場合は(200-width)逆は(x+width)を追加
						//枠線
						drawBox(x, y, 200, height, 2, Color(1, 1, 1));
					}

					//得点表示
					//dispPlayPoint(play_point);

					//プレイ時間を減らす
					play_time -= 1;
					//時間が無くなったらループを抜ける
					if (play_time == 0)break;
					
						

					//画面を更新
					app_env.update();
				}

				app_env.flushInput();
			}
		}
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//ハイスコア更新チェック
		while(true)
		{
		if (play_point > hi_score){
			std::ofstream fstr("res/score.txt");
			if (fstr){

				fstr << play_point << std::endl;
			}
		}

			break;

		}

		//結果画面///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		{
			//結果画面の画像
			Texture results_image("res/results.png");

			//結果画面の演出用変数
			float angle = 0.0;

			//メインループ
			while (1){
				//ウインドウが閉じられたら終了
				if (!app_env.isOpen())return 0;

				//描画準備
				app_env.setupDraw();

				//演出用の変数を変更
				angle += 0.2;
				//sinの値が0.0~1.0に収まるように計算
				float color_red = (std::sin(angle) + 1.0) / 2.0;

				//「終了」表示
				drawTextureBox(-512 / 2, -128 / 2, 512, 128,
					0, 0, 512, 128,
					results_image,
					Color(color_red, 1, 1));

				//得点表示
				//dispPlayPoint(play_point);
				//画面を更新
				app_env.update();
				if (app_env.isPushKey(GLFW_KEY_ENTER)) break;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;
				//if (app_env.isPushButton(Mouse::LEFT)) break;
				//if (app_env.isPushButton(Mouse::RIGHT))break;
			}
		}
		app_env.flushInput();

	}
  return 0;
	// アプリ終了////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
Пример #3
0
int main() {
	// アプリウインドウの準備
	AppEnv app_env(Window::WIDTH, Window::HEIGHT);



	while (1){

		int hi_score = 0;
		{
			std::ifstream fstr("score.txt");
			if (fstr)
			{
				fstr >> hi_score;
			}
		}
		Texture title_image("res/title.png");//サイズ512*256
		Texture pstart_image("res/push_start.png");//サイズ512*128
		Texture njp_image("res/NJ-P.png");//サイズ128*256
		Texture suriken_image("res/surikenn.png");//サイズ64*64
		Texture player_image("res/player.png");//サイズ16*16
		Texture ktn_image("res/katana.png");//サイズ64*128
		Texture setu_image("res/Setumei2.png");//サイズ1024*1024
		Texture gst_image("res/gstart.png");//サイズ512*128
		Texture lizlt_image("res/FOR_P.png");//サイズ1024*1024
		Texture titleback_image("res/titleback.png");//サイズ512*128
		Texture yasiki_image("res/yasiki.png");//サイズ512*256
		Texture gover_image("res/p.png");//サイズ900*900
		Texture setu2_image("res/setumei3.png");//サイズ900*900

		Media bg_music("res/bgmusic.wav");
		Media gstart_music("res/gamestart.wav");
		Media gclear_music("res/gameclear.wav");
		Media gover_music("res/gameover.wav");
		Media atk_music("res/atk.wav");

		float pstart_angle = 0.0;
		float gst_angle = 0.0;

		int play_time = 60 * 20;
		int play_point = 0;

		int i1 = 0;
		int i2 = 0;
		int i3 = 0;
		int i4 = 0;
		int i5 = 0;
		int i6 = 0;
		int i7 = 0;
		int i8 = 0;
		int i9 = 0;
		int i10 = 0;
		int i11 = 0;
		int i12 = 0;

		float random1 = 0;
		float random2 = 0;
		float random3 = 0;
		float random4 = 0;
		float random5 = 0;
		float random6 = 0;
		float random7 = 0;
		float random8 = 0;
		float random9 = 0;
		float random10 = 0;
		float random11 = 0;
		float random12 = 0;

		int G1 = 1;
		int G2 = 1;
		int G3 = 1;
		int G4 = 1;
		int G5 = 1;
		int G6 = 1;
		int G7 = 1;
		int G8 = 1;
		int G9 = 1;
		int G10 = 1;
		int G11 = 1;
		int G12 = 1;

		bool on_emy1 = true;
		bool on_emy2 = true;
		bool on_emy3 = true;
		bool on_emy4 = true;
		bool on_emy5 = true;
		bool on_emy6 = true;
		bool on_emy7 = true;
		bool on_emy8 = true;
		bool on_emy9 = true;
		bool on_emy10 = true;
		bool on_emy11 = true;
		bool on_emy12 = true;

		int vx1 = 0;
		int vx2 = 0;
		int vx3 = 0;
		int vx4 = 0;
		int vx5 = 0;
		int vx6 = 0;

		int vy1 = 0;
		int vy2 = 0;
		int vy3 = 0;
		int vy4 = 0;
		int vy5 = 0;
		int vy6 = 0;

		int x1 = 0;

		int x = 0;
		int y = 0;

		app_env.bgColor(Color(0.3, 0.3, 0.3));

		// メインループ

		float ktn_angle = 0;
		bool ktn = false;
		float A = 4;
		int r = 0;
		int r1 = 0;

		gstart_music.play();
		gstart_music.looping(true);
		gstart_music.gain(0.5);

		while (1) {

			int hi_score = 0;
			{
				std::ifstream fstr("score.txt");
				if (fstr)
				{
					fstr >> hi_score;
				}
			}

			{
				// ウィンドウが閉じられたらアプリを終了
				if (!app_env.isOpen()) return 0;

				// 描画準備
				app_env.setupDraw();

				dispPlayPoint(hi_score);

				if (app_env.isPushButton(Mouse::LEFT)) break;
				if (app_env.isPushButton(Mouse::RIGHT)) break;

				drawTextureBox(0 - 512 / 2, 0,
					512, 256,
					0, 0, 512, 256,
					title_image,
					Color(1, 1, 1));

				pstart_angle += 0.1;
				float pstart_color = (std::sin(pstart_angle));
				if (pstart_color > 0){
					pstart_color = 1;
				}

				std::cout << pstart_color << std::endl;

				drawTextureBox(0 - 512 / 2, -330,
					512, 128,
					0, 0, 512, 128,
					pstart_image,
					Color(pstart_color, pstart_color, pstart_color));
				// ここにゲームの処理を書く
				// 
				K = 1;
				// 画面を更新
				app_env.update();
			}

			app_env.flushInput();
		}

		while (1){

			// ウィンドウが閉じられたらアプリを終了
			if (!app_env.isOpen()) return 0;

			// 描画準備
			app_env.setupDraw();

			drawTextureBox(-1000 / 2, -900 / 2 + 10,
				1024, 1024,
				0, 0,
				1000, 900,
				setu_image,
				Color(1, 1, 1));

			if (app_env.isPushKey(GLFW_KEY_ENTER)){
				gstart_music.looping(false);
				gstart_music.stop();
				break;
			}

			gst_angle += 0.1;
			float gst_color = (std::sin(gst_angle));
			if (gst_color > 0){
				gst_color = 1;
			}

			drawTextureBox(0 - 512 / 2, -900 / 2 - 5 + 10,
				512, 128,
				0, 0, 512, 128,
				gst_image,
				Color(gst_color, gst_color, gst_color));

			app_env.update();
		}

		app_env.flushInput();
/*		while (1){

			// ウィンドウが閉じられたらアプリを終了
			if (!app_env.isOpen()) return 0;

			// 描画準備
			app_env.setupDraw();

			drawTextureBox(-900 / 2, -900 / 2,
				1024, 1024,
				0, 0, 900, 900,
				setu2_image,
				Color(1, 1, 1));

			if (app_env.isPushKey(GLFW_KEY_ENTER)){
				gstart_music.looping(false);
				gstart_music.stop();
				break;
			}
			app_env.update();
		}
		app_env.flushInput();
*/

		bg_music.play();
		bg_music.looping(true);
		bg_music.gain(0.1);

		while (1){
			{
				if (!app_env.isOpen()) return 0;

				app_env.setupDraw();


				float angle = 0;
				angle = angle + 0.1;
				Vec2f mouse_pos = app_env.mousePosition();

				drawFillCircle(mouse_pos.x(), mouse_pos.y(),
					8, 8,
					100,
					Color(1, 0, 0));

				ktn_angle -= 0.49;

				if (app_env.isPushButton(Mouse::LEFT)){
					ktn = true;
				}
			   
				if (ktn == true){
					atk_music.play();
					atk_music.gain(0.2);

					drawTextureBox(mouse_pos.x(), mouse_pos.y(),
						64, 128,
						0, 0, 64, 128,
						ktn_image,
						Color(1, 1, 1),
						M_PI*ktn_angle,
						Vec2f(1, 1),
						Vec2f(1, 1));
					A -= 1;
					if (A < 0){
						ktn = false;
						A = 4;
					}
				}

				drawTextureBox(-900 / 2 + 30, -900 / 2,
					128, 256,
					0, 0, 128, 256,
					njp_image,
					Color(1, 1, 1));

				time_t date;
				srand(time(&date));
				r1 = rand() % 4;
				random1 = rand() % 450 * -1;
				random2 = rand() % 450;
//				random3 = rand() % 450 * -1;
				random4 = rand() % 450 * -1;
				random5 = rand() % 450;
//				random6 = rand() % 450 * -1;
				random7 = rand() % 450 * -1;
				random8 = rand() % 450;
//				random9 = rand() % 450 * -1;
				random10 = rand() % 450 * -1;
				random11 = rand() % 450;
//				random12 = rand() % 450 * -1;

				float x1 = -450 + vx1;
				float x2 = -450 + vx2;
//				float x3 = -450 + vx3;
				float x4 = 450 + vx4;
				float x5 = 450 + vx5;
//				float x6 = 450 + vx6;
				float y7 = -450 + vy1;
				float y8 = -450 + vy2;
//				float y9 = -450 + vy3;
				float y10 = 450 + vy4;
				float y11 = 450 + vy5;
//				float y12 = 450 + vy6;

				float y1 = random1;
				float y2 = random2;
//				float y3 = random3;
				float y4 = random4;
				float y5 = random5;
//				float y6 = random6;
				float x7 = random7;
				float x8 = random8;
//				float x9 = random9;
				float x10 = random10;
				float x11 = random11;
//				float x12 = random12;

				on_emyA(G1, x1, y1, mouse_pos, A, on_emy1, play_point);
				on_emy(r1, r, on_emy1, x1, random1, vx1, suriken_image);
				on_emyRf(on_emy1, i1, G1, vx1);

				on_emyA(G2, x2, y2, mouse_pos, A, on_emy2, play_point);
				on_emy(r1, r, on_emy2, x2, random2, vx2, suriken_image);
				on_emyRf(on_emy2, i2, G2, vx2);

/*				on_emyA(G3, x3, y3, mouse_pos, A, on_emy3, play_point);
				on_emy(r1, r, on_emy3, x3, random3, vx3, suriken_image);
				on_emyRf(on_emy3, i3, G3, vx3);
*/
				on_emyA(G4, x4, y4, mouse_pos, A, on_emy4, play_point);
				on_emyR(r1, r, on_emy4, x4, random4, vx4, suriken_image);
				on_emyRf(on_emy4, i4, G4, vx4);

				on_emyA(G5, x5, y5, mouse_pos, A, on_emy5, play_point);
				on_emyR(r1, r, on_emy5, x5, random5, vx5, suriken_image);
				on_emyRf(on_emy5, i5, G5, vx5);

/*				on_emyA(G6, x6, y6, mouse_pos, A, on_emy6, play_point);
				on_emyR(r1, r, on_emy6, x6, random6, vx6, suriken_image);
				on_emyRf(on_emy6, i6, G6, vx6);
*/
				on_emyA(G7, x7, y7, mouse_pos, A, on_emy7, play_point);
				on_emy(r1, r, on_emy7, random7, y7, vy1, suriken_image);
				on_emyRf(on_emy7, i7, G7, vy1);

				on_emyA(G8, x8, y8, mouse_pos, A, on_emy8, play_point);
				on_emy(r1, r, on_emy8, random8, y8, vy2, suriken_image);
				on_emyRf(on_emy8, i8, G8, vy2);

/*				on_emyA(G9, x9, y9, mouse_pos, A, on_emy9, play_point);
				on_emy(r1, r, on_emy9, random9, y9, vy3, suriken_image);
				on_emyRf(on_emy9, i9, G9, vy3);
*/
				on_emyA(G10, x10, y10, mouse_pos, A, on_emy10, play_point);
				on_emyR(r1, r, on_emy10, random10, y10, vy4, suriken_image);
				on_emyRf(on_emy10, i10, G10, vy4);

				on_emyA(G11, x11, y11, mouse_pos, A, on_emy11, play_point);
				on_emyR(r1, r, on_emy11, random11, y11, vy5, suriken_image);
				on_emyRf(on_emy11, i11, G11, vy5);

/*				on_emyA(G12, x12, y12, mouse_pos, A, on_emy12, play_point);
				on_emyR(r1, r, on_emy12, random12, y12, vy6, suriken_image);
				on_emyRf(on_emy12, i12, G12, vy6);
*/
/*      		if (K == 1){
					drawTextureBox(-512 / 2 + 80, -100,
						512, 256,
						0, 0, 512, 256,
						yasiki_image,
						Color(1, 1, 1));
				}

				if (K == 1){
					if (vx1 >= 350 || vx2 >= 350 || vx3 >= 350 || vx4 <= -390 || vx5 <= -390 || vx6 <= -390) {
						if (random1 <= 80 && random1 >= -80 || random2 <= 100 && random2 >= -100 || random3 <= 100 && random3 >= -100 || random4 <= 100 && random4 >= -100 || random5 <= 100 && random5 >= -100 || random6 <= 100 && random6 >= -100){
							K = 0;
							E = 1;
							bg_music.looping(false);
							break;
						}
					}
				}

				if (K == 1){
					if (vy1 >= 350 || vy2 >= 350 || vy3 >= 350 || vy4 <= -460 || vy5 <= -460 || vy6 <= -460) {
						if (random7 <= 256 && random7 >= -256 || random8 <= 256 && random8 >= -256 || random9 <= 256 && random9 >= -256 || random10 <= 256 && random10 >= -256 || random11 <= 256 && random11 >= -256 || random12 <= 256 && random12 >= -256){
							K = 0;
							E = 1;
							bg_music.looping(false);
							break;
						}
					}
				}
*/
				// ここにゲームの処理を書く

				{
					dispPlayPoint(play_point);

					{
						float x = -900 / 2;
						float y = -900 / 2;

						float width = 30;
						float height = (play_time * 250) / (60 * 20);

						drawFillBox(x, y,
							width, height,
							Color(1, 1, 0));
						drawBox(x, y,
							width, 250, 2,
							Color(1, 1, 1));

					}

					play_time -= 1;

					if (play_time == 0) break;

					if (play_point > hi_score){
						std::ofstream fstr("score.txt");
						if (fstr){
							fstr << play_point << std::endl;
						}

					}

				}

				app_env.update();
			}
			app_env.flushInput();

		}
		int M = 1;
		while (1){

			if (!app_env.isOpen()) return 0;

			app_env.setupDraw();
			
			if (E == 1){

					bg_music.stop();

					drawTextureBox(-450, -450,
						1024, 1024,
						0, 0, 900, 900,
						gover_image,
						Color(1, 1, 1));

					if (M == 1){
						gover_music.play();
						gover_music.gain(0.5);
						M = 0;
					}

					if (app_env.isPressKey(GLFW_KEY_ENTER)){
						gover_music.looping(false);
						gover_music.stop();
						break;
					}
				}

				if (E == 0){
					bg_music.stop();

					drawTextureBox(-900 / 2, -900 / 2-100,
						1024, 1024,
						0, 0,
						900, 900,
						lizlt_image,
						Color(1, 1, 1));

					drawTextureBox(-512 / 2, -330,
						512, 128,
						0, 0, 512, 128,
						titleback_image,
						Color(1, 1, 1));

					dispPlayPoint(play_point);

					if (M == 1){
						gclear_music.play();
						gclear_music.looping(true);
						gclear_music.gain(0.5);
						M = 0;
					}

					if (app_env.isPressKey(GLFW_KEY_ENTER)){
						gclear_music.looping(false);
						gclear_music.stop();
						break;
					}
				}

				app_env.update();
			}

			app_env.flushInput();

		}

		// アプリ終了
	}