cscの作法 その164

# 概要
cscの作法、調べてみた。
DxLibDotNet.dll、使ってみた。
DX.PlaySoundMem、使ってみた。
ゲーム、やってみた。

# 参考にしたページ

http://icollegeinnovation.web.fc2.com/other/programming/cs/howtocs/dx-lib/dx_lib_index.html

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/cff5d2f7-f70e-250c-e47e-b078e823702e.png)


# サンプルコード


```
using DxLibDLL;
using System;

namespace app
{
	class Dxtest_prg {
		[STAThread]
		static void Main() {
			DX.ChangeWindowMode(DX.TRUE);
			DX.SetGraphMode(640, 480, 32);
			DX.DxLib_Init();
			DX.SetDrawScreen(DX.DX_SCREEN_BACK);
			int jiki1;
			int tama1;
			int teki1;
			int tama_teki1;
			int s_jiki_1;
			int s_jiki_2;
			int s_teki_1;
			int s_teki_2;
			int jiki_x,
				jiki_y;
			int tama_x,
				tama_y,
				tama_h;
			int teki_x,
				teki_y;
			int t_time;
			double tama_teki_x,
				tama_teki_y;
			int tama_teki_h;
			double tama_teki_vx,
				tama_teki_vy;
			double kyori;
			jiki_x = 0;
			jiki_y = 0;
			tama_x = jiki_x + 60;
			tama_y = jiki_y + 15;
			tama_h = 0;
			teki_x = 780;
			teki_y = 0;
			tama_teki_x = teki_x;
			tama_teki_y = teki_y;
			tama_teki_h = 0;
			tama_teki_vx = 0.0;
			tama_teki_vy = 0.0;
			t_time = 0;
			jiki1 = DX.LoadGraph("image.jpg");
			tama1 = DX.LoadGraph("image8.jpg");
			teki1 = DX.LoadGraph("image11.jpg");
			tama_teki1 = DX.LoadGraph("image13.jpg");
			s_jiki_1 = DX.LoadSoundMem("1326220220.mp3");
			s_jiki_2 = DX.LoadSoundMem("1326219669.mp3");
			s_teki_1 = DX.LoadSoundMem("1326220220.mp3");
			s_teki_2 = DX.LoadSoundMem("1326219669.mp3");
			while (DX.CheckHitKey(DX.KEY_INPUT_ESCAPE) == 0 && DX.ScreenFlip() == 0 && DX.ClearDrawScreen() == 0 && DX.ProcessMessage() == 0)
			{
				if (DX.CheckHitKey(DX.KEY_INPUT_RIGHT) == 1)
					jiki_x++;
				if (DX.CheckHitKey(DX.KEY_INPUT_LEFT) == 1)
					jiki_x--;
				if (DX.CheckHitKey(DX.KEY_INPUT_UP) == 1)
					jiki_y--;
				if (DX.CheckHitKey(DX.KEY_INPUT_DOWN) == 1)
					jiki_y++;
				if (jiki_x < 0)
					jiki_x = 0;
				if (jiki_x > 740)
					jiki_x = 740;
				if (jiki_y < 0)
					jiki_y = 0;
				if (jiki_y > 570)
					jiki_y = 570;
				if (DX.CheckHitKey(DX.KEY_INPUT_SPACE) == 1 && tama_h == 0)
				{
					tama_h = 1;
					tama_x = jiki_x + 60;
					tama_y = jiki_y + 15;
					DX.PlaySoundMem(s_jiki_1, DX.DX_PLAYTYPE_BACK);
				}
				if (tama_h == 1)
				{
					tama_x = tama_x + 5;
					if (tama_x > 800)
						tama_h = 0;
					DX.DrawGraph(tama_x, tama_y, tama1, DX.TRUE);
				}
				t_time++;
				teki_y = (int) (Math.Sin((double) t_time / 100.0) * 100 + 300);
				teki_x = (int) 800 - t_time;
				if (teki_x < 0)
					t_time = 0;
				if (tama_h==1 && tama_x + 13 >= teki_x && tama_x + 13 <= teki_x + 39 && tama_y + 13 >= teki_y && tama_y + 13 <= teki_y + 44)
				{
					tama_h = 0;
					t_time = 0;
					DX.PlaySoundMem(s_teki_2, DX.DX_PLAYTYPE_BACK);
				}
				if (jiki_x + 59 >= teki_x && jiki_x + 59 <= teki_x + 85 && jiki_y + 31 >= teki_y && jiki_y + 31 <= teki_y + 64)
				{
					DX.PlaySoundMem(s_jiki_2, DX.DX_PLAYTYPE_BACK);
					break;
				}
				if (jiki_x + 59 >= tama_teki_x && jiki_x + 59 <= tama_teki_x + 72 && jiki_y + 31 >= tama_teki_y && jiki_y + 31 <= tama_teki_y + 44)
				{
					DX.PlaySoundMem(s_jiki_2, DX.DX_PLAYTYPE_BACK);
					break;
				}
				if (teki_x == 700)
				{
					tama_teki_h = 1;
					tama_teki_x = teki_x;
					tama_teki_y = teki_y;
					kyori = Math.Sqrt((jiki_x - teki_x) * (jiki_x - teki_x) + (jiki_y - teki_y) * (jiki_y - teki_y));
					tama_teki_vx = (jiki_x - teki_x) / kyori * 3;
					tama_teki_vy = (jiki_y - teki_y) / kyori * 3;
					DX.PlaySoundMem(s_teki_1, DX.DX_PLAYTYPE_BACK);
				}
				if (tama_teki_h == 1)
				{
					tama_teki_x += tama_teki_vx;
					tama_teki_y += tama_teki_vy;
					DX.DrawGraph((int) tama_teki_x, (int) tama_teki_y, tama_teki1, DX.TRUE);
				}
				DX.DrawGraph(jiki_x, jiki_y, jiki1, DX.TRUE);
				DX.DrawGraph(teki_x, teki_y, teki1, DX.TRUE);
			}
			DX.SetFontSize(64);
			DX.DrawString(250, 240, "GAME OVER", DX.GetColor(255, 255, 255));
			DX.ScreenFlip();
			DX.WaitTimer(2000);
			DX.DxLib_End();
			return;
		}
	}
}



```

以上。