Hiragi(GKUTH)の日常
理系大学生の日記

暇つぶしプログラミング

アバター
Hiragi(GKUTH)
記事: 167
登録日時: 14年前
住所: 大阪府
連絡を取る:

暇つぶしプログラミング

投稿記事 by Hiragi(GKUTH) » 10年前

暇つぶしにプログラミングをするような高校生と会ってみたいものです。
楽しそう。



まぁ課題は終わってないんですけど。

やっぱり何も考えずにガリガリと書き続けるプログラミングが楽だなー←

今後のモチベのためにも日記に今日の暇つぶし分置いときます。


そういえばココでのポイントが地味に上がってきて「熟練のプログラマー」とかになってしまいました。
プログラマでさえ無いぐらいのスキルなのに掲示板利用するときに恥ずかしい^^; ぴよぴよまでポイント下げてくれないですかね(;´・ω・)

そして相変わらず関数化とかの機能の独立化を面倒臭がるスパゲッティーコーティング(´・ω・)

CODE:

# include 

void Main()
{
		//SystemInit
	/*************************************************/
	Graphics::SetBackground(Palette::Black);
	Graphics::SetVSyncEnabled(true);
	Window::Resize(1280, 720);
	Window::SetTitle(L"The MiniGame");

	Font px64(64);
	Font px32(32);

	int SEvol = 0;
	int BGMvol = 0;

	int scene = 0; //Manage Scenes

	enum
	{
		TITLE,
		GAMEMAIN,
		OPTION,
		EXIT,
		RESULT,
	};



		//TitleInit
	/*************************************************/


	const Sound titlemusic(L""); //オプションと共有

	const String title00 = L"The MiniGame";
	const String title01 = L"GameStart!";
	const Rect pos_t1 = px32(title01).regionCenter({ 640, 400 });
	const String title02 = L"Option";
	const Rect pos_t2 = px32(title02).regionCenter({ 640, 480 });
	const String title03 = L"Result";
	const Rect pos_t3 = px32(title03).regionCenter({ 640, 560 });
	const String title04 = L"Exit";
	const Rect pos_t4 = px32(title04).regionCenter({ 640, 640 });

		//OptionInit
	/*************************************************/

	//Siv3D標準装備のGUIをつかってみる

	GUI optionGUI(GUIStyle::Default);
	optionGUI.setCenter({ 320, 320 });

	optionGUI.add(GUIText::Create(L"SE Volume   "));
	optionGUI.addln(L"SE Volume", GUISlider::Create(0, 128, 100, 480, true));
	optionGUI.add(GUIText::Create(L"BGM Volume"));
	optionGUI.addln(L"BGM Volume", GUISlider::Create(0, 128, 100, 480, true));

	optionGUI.show(false);

		//GameMainInit
	/*************************************************/
	const int BALLMAX = 128;

	typedef struct Ball{
		double x, y;
		double vx, vy;
		double g;
		Color color;
		int r;
		int life;
		bool flag;
	};

	Ball ball[BALLMAX];
	int score;
	Circle effect[20];
	int cntB=1;

	for (int i = 0; i < BALLMAX; i++)
		ball[i].flag = false;

	

		//ExitInit
	/*************************************************/

	bool exit = false;



	while (System::Update())
	{

		switch (scene)
		{
			case TITLE:
			{
					//マウスとの接触?
				const bool hit1 = pos_t1.mouseOver;
				const bool hit2 = pos_t2.mouseOver;
				const bool hit3 = pos_t3.mouseOver;
				const bool hit4 = pos_t4.mouseOver;

					//クリックされてたらそれぞれシーンへと飛ぶ
				if (pos_t1.leftClicked)scene = GAMEMAIN;
				if (pos_t2.leftClicked)scene = OPTION;
				if (pos_t3.leftClicked)scene = RESULT;
				if (pos_t4.leftClicked)scene = EXIT;

					//タイトルの描画
				px64(title00).drawCenter({ 640, 128 }, HSV(System::FrameCount() % 100 * 3.6));
				px32(title01).drawCenter({ 640, 400 }, hit1 ? Color(Random() * 255, Random() * 255, Random() * 255) : Palette::White);
				px32(title02).drawCenter({ 640, 480 }, hit2 ? Color(Random() * 255, Random() * 255, Random() * 255) : Palette::White);
				px32(title03).drawCenter({ 640, 560 }, hit3 ? Color(Random() * 255, Random() * 255, Random() * 255) : Palette::White);
				px32(title04).drawCenter({ 640, 640 }, hit4 ? Color(Random() * 255, Random() * 255, Random() * 255) : Palette::White);

				break;
			}


			case GAMEMAIN:
			{

					//5秒に一回ほどボールを生成する
				if (System::FrameCount() % 300 == 0)cntB++;
				for (int i = 0; i < cntB; i++)
				{
						//空きを見つけて初期化
					if (ball[i].flag == false)
					{
						const double rand = Random();

						ball[i].r = (rand+1) * 30;

						ball[i].x = rand * 1280;
						ball[i].y = -60;
						ball[i].vx = 0;
						ball[i].vy = 0;
						ball[i].g = (rand+1)/8;
						ball[i].life = 0;
						ball[i].color = HSV(Random() * 360);
						ball[i].flag = true;
					}
				}


				for (int i = 0; i < cntB; i++)
				{
						//フラグ立ってたら計算と描画
					if (ball[i].flag == true)
					{
						ball[i].vy += ball[i].g;
						ball[i].life++;
						ball[i].x = ball[i].x + ball[i].vx;
						ball[i].y = ball[i].y + ball[i].vy;

						Circle(ball[i].x, ball[i].y, ball[i].r).draw(ball[i].color);
					}
				}



				if (Input::KeyT.clicked)scene = TITLE;

				break;
			}


			case OPTION:
			{
				optionGUI.show(true);

				px32(L"Press T to return Title").draw(0, 0);
				SEvol = optionGUI.slider(L"SE Volume").valueInt;
				BGMvol = optionGUI.slider(L"BGM Volume").valueInt;
				Println(BGMvol);
				if (Input::KeyT.clicked)
				{
					scene = TITLE;
					optionGUI.show(false);
				}

				break;
			}

			case RESULT:
			{
				px32(L"さーせんまだ未実装です^^\n Tキーを押してタイトルへ戻る。").draw(0, 0);
				if (Input::KeyT.clicked)scene = TITLE;

				break;
			}

			case EXIT:
			{
				exit = true; //終了のフラグを立てる
				break;
			}


			default:
			{
				Println(L"Error:定義されていないシーンが呼ばれました。");
				break;
			}
		}
		if (exit == true) break; //終わり
	}
	
}

アバター
usao
記事: 1889
登録日時: 12年前

Re: 暇つぶしプログラミング

投稿記事 by usao » 10年前

どうでもいい話ですが,コードの入り組みっぷり(?)を例えるのに
>スパゲッティー
って,微妙だと思うんですよね.
実物は言うほど絡まらないですよね(麺類の中でも).

#私のコードはちぢれ麺