private void timer1_Tick(object sender, EventArgs e) { long count = timeCount.getCount(); for (int i = 0; i < count; i++) { if (GetAsyncKeyState(Keys.Down) < 0) { ship.Y += 1; } if (GetAsyncKeyState(Keys.Up) < 0) { ship.Y -= 1; } if (GetAsyncKeyState(Keys.Right) < 0) { ship.X += 1; } if (GetAsyncKeyState(Keys.Left) < 0) { ship.X -= 1; } } Refresh(); }
private void timer1_Tick(object sender, EventArgs e) { int mtime = 0; long count = timeCount.getCount(); for (long i = 0; i < count; i++) { if (GetAsyncKeyState(Keys.Down) < 0) { ship.Y += 1; } if (GetAsyncKeyState(Keys.Up) < 0) { ship.Y -= 1; } if (GetAsyncKeyState(Keys.Right) < 0) { ship.X += 1; } if (GetAsyncKeyState(Keys.Left) < 0) { ship.X -= 1; } if (GetAsyncKeyState(Keys.Space) < 0 && mtime <= 0) { for (int j = 0; j < missile.Length; j++) { if (missile[j].Visible == false) { mtime = 16; missile[j].Visible = true; missile[j].X = ship.X + (48 - 16) / 2; missile[j].Y = ship.Y; break; } if (missile[j].Y == -32 && missile[j].Visible == true) { missile[j].Visible = false; } } } mtime--; for (int k = 0; k < missile.Length; k++) { missile[k].Y -= 2; } if (ship.Y < 0) { ship.Y = 0; } if (ship.X < 0) { ship.X = 0; } if (ship.Y > ClientSize.Height - 48) { ship.Y = ClientSize.Height - 48; } if (ship.X > ClientSize.Width - 48) { ship.X = ClientSize.Width - 48; } } Refresh(); }
private void timer1_Tick(object sender, EventArgs e) { long count = timeCount.getCount(); for (long i = 0; i < count; i++) { //キーボード入力 if (GetAsyncKeyState(Keys.Down) < 0) { ship.Y += 1; } if (GetAsyncKeyState(Keys.Up) < 0) { ship.Y -= 1; } if (GetAsyncKeyState(Keys.Right) < 0) { ship.X += 1; } if (GetAsyncKeyState(Keys.Left) < 0) { ship.X -= 1; } if (GetAsyncKeyState(Keys.Space) < 0 && mtime <= 0) { for (int j = 0; j < missile.Length; j++) { if (missile[j].Visible == false) { mtime = 32; missile[j].X = ship.X + (ship.Width - missile[j].Width) / 2; missile[j].Y = ship.Y; missile[j].Visible = true; break; } } } mtime--; //敵の出現処理 if (rand.Next() % 100 == 0) { for (int j = 0; j < enemy.Length; j++) { if (enemy[j].Visible == false) { enemy[j].Visible = true; enemy[j].Y = -enemy[j].Height; enemy[j].X = rand.Next() % (ClientSize.Width - enemy[j].Width); break; } } } //敵の移動処理 for (int j = 0; j < enemy.Length; j++) { if (enemy[j].Visible == true) { enemy[j].Y += 2; if (enemy[j].Y > ClientSize.Height) { enemy[j].Visible = false; } } } //ミサイルの移動処理 for (int j = 0; j < missile.Length; j++) { missile[j].Y -= 2; if (missile[j].Y < -32) { missile[j].Visible = false; } } //リミットチェック if (ship.Y < 0) { ship.Y = 0; } if (ship.X < 0) { ship.X = 0; } if (ship.Y > ClientSize.Height - 48) { ship.Y = ClientSize.Height - 48; } if (ship.X > ClientSize.Width - 48) { ship.X = ClientSize.Width - 48; } } Refresh(); }