質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Windows Forms

Windows Forms(WinForms)はMicrosoft .NET フレームワークに含まれる視覚的なアプリケーションのプログラミングインターフェイス(API)です。WinFormsは管理されているコードの既存のWindowsのAPIをラップすることで元のMicrosoft Windowsのインターフェイスのエレメントにアクセスすることができます。

Q&A

解決済

1回答

2188閲覧

pictureBoxに当たるとゲームオーバーとなるような、当たり判定を作成したい。

KeilyX07

総合スコア29

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Windows Forms

Windows Forms(WinForms)はMicrosoft .NET フレームワークに含まれる視覚的なアプリケーションのプログラミングインターフェイス(API)です。WinFormsは管理されているコードの既存のWindowsのAPIをラップすることで元のMicrosoft Windowsのインターフェイスのエレメントにアクセスすることができます。

0グッド

0クリップ

投稿2020/09/29 11:55

編集2020/09/29 16:16

インターネットにて当たり判定についての情報を調べましたが、やり方が非常にバラバラな上、どのやり方が適しているか、どこにそのコードを入れればいいかがわからなくなり質問させていただきます。

C#

1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10 11namespace assignments_creategame 12{ 13 public partial class Form1 : Form 14 { 15 int[] posx = new int[10]; 16 int[] posy = new int[10]; 17 int[] movx = new int[10]; 18 int[] movy = new int[10]; 19 int[] iW = new int[10]; 20 int[] iH = new int[10]; 21 int seed = Environment.TickCount; 22 int W, H; 23 public Form1() 24 { 25 InitializeComponent(); 26 } 27 28 private void Form1_Load(object sender, EventArgs e) 29 { 30 W = this.ClientRectangle.Width; 31 H = this.ClientRectangle.Height; 32 33 //dishpic 34 posx[0] = dishpic.Location.X; 35 posy[0] = dishpic.Location.Y; 36 movx[0] = 450; 37 movy[0] = 574; 38 iW[0] = dishpic.Width; 39 iH[0] = dishpic.Height; 40 41 //potato 42 posx[5] = pictureBox5.Location.X; 43 posy[5] = pictureBox5.Location.Y; 44 movx[5] = 102; 45 movy[5] = -400; 46 iW[5] = pictureBox5.Width; 47 iH[5] = pictureBox5.Height; 48 49 50private void Form1_KeyDown(object sender, KeyEventArgs e) 51 { 52 if (e.KeyCode == Keys.D) 53 { 54 movx[0] += 5; 55 } 56 if (e.KeyCode == Keys.A) 57 { 58 movx[0] -= 5; 59 } 60 } 61 62 private void timer1_Tick(object sender, EventArgs e) 63 { 64 // [0]Dish 65 posx[0] = movx[0]; 66 posy[0] = movy[0]; 67 dishpic.Location = new Point(posx[0], posy[0]); 68 69 } 70 71 72 private void runbutton_Click(object sender, EventArgs e) 73 { 74 timer1.Enabled = !timer1.Enabled; 75 loop.Enabled = !loop.Enabled; 76 pictureBox5.Top = -400; 77 } 78 79private void timer2_Tick(object sender, EventArgs e) 80 { 81 posy[5] += 5; 82 pictureBox5.Location = new Point(posx[5], posy[5]); 83 84 if(posx[5] == posx[0] && posy[5] == 222) 85 { 86 textBox6.Text = "GAME OVER"; 87 } 88 } 89private void loop_Tick(object sender, EventArgs e) 90 { 91 //potato 92 Random potatotime = new Random(seed++); 93 int potatorand; 94 potatorand = potatotime.Next(1, 10); 95 textBox1.Text = Convert.ToString(potatorand); 96 if (potatorand >= 7) 97 { 98 //X軸設定 99 Random rndx = new Random(seed++); 100 posx[5] = rndx.Next(0, W - iW[5]); 101 102 loop.Enabled = false; 103 timer2.Enabled = true; 104 105 } 106 } 107

非常にコードが長くなってしまいましたが、どうかご理解ください。
dishpicに対しpictureBox5が触れた場合にGAME OVERと表示されるようにしたいと思っています。
現状はdishpicの座標値(posx[0],posy[0])とpotatoの座標値(posx[5],posy[5])が全く同じ座標に当たると表示される仕組みになっているはずです。
※色々なサイトのものを試しに代入してみたりしているので、そのような表記ができていないかもしれません。

ご回答よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ここから使えそうな奴を選ぶとよいのではないでしょうか。
2Dだと円接触、矩形接触が良く使われます。
当たり判定記事リスト

投稿2020/09/29 23:26

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問