現在、Pictureboxのプロパティでボールを入れるカゴを表示していて、solidbrushで描いたボールをカゴに入れるようなゲームを作成しているのですが、ボールがカゴに重なるとボールがPictureboxの裏に隠れてしまいます。
ボールを表に重ねるにはどうしたらいいでしょうか?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace _1108_ボール_斜方投射
{
public partial class Formballshoot : Form
{
double ballPos_x; double ballPos_y; double vx = 10; //x座標の初速度 double vy = -30; //y座標の初速度 double g = 1.0; //加速度 double power = 1; int t = 0; //時間 int ballRadius = 10; //ボールの半径 double deg; //打ちだし角度 Timer timer = new Timer(); Random rand = new Random(); //乱数を発生させるrandを生成 public Formballshoot() { //角度を30度~60度の間で発生 deg = rand.Next(30, 60); this.ballPos_x = 10; //x座標の初期位置 this.ballPos_y = 650; //y座標の初期位置 InitializeComponent(); //マウスホイールイベントの追加 this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Scroll_MouseWheel); //タイマーイベント Timer timer = new Timer(); timer.Interval = 50; timer.Tick += new EventHandler(Update); //timer.Start(); } private void Update(object sender, EventArgs e) { ballPos_x += vx * Math.Cos(deg * (Math.PI / 180)); //vy += g; ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t; this.t++; //再描写 Invalidate(); //ボールが画面の下を超えた場合 //繰り返しボールを飛ばす if (ballPos_y > 650) { this.vx = power; //初速をpowerにする this.vy = -30; //y座標の初速度を再び示す this.g = 1.0; //加速度を再び示す this.ballPos_x = 10; //x座標の初期位置に戻す this.ballPos_y = 650; //y座標の初期位置に戻す deg = rand.Next(30, 60); //角度を30度~60度に設定 this.t = 0; this.t++; ballPos_x += vx * Math.Cos(deg * (Math.PI / 180)); ballPos_y += vy * Math.Sin(deg * (Math.PI / 180)) + g * t; } } private void DrawFiguare(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //円を描画する SolidBrush brush = new SolidBrush(Color.Red); float px = (float)this.ballPos_x - this.ballRadius; float py = (float)this.ballPos_y - this.ballRadius; e.Graphics.FillEllipse(brush, px, py, this.ballRadius * 2, this.ballRadius * 2); } private void endEToolStripMenuItem_Click(object sender, EventArgs e) { //ゲーム終了 Close(); } private void Scroll_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { int Wheel = (e.Delta / 120); label1.Text = (e.Delta * SystemInformation.MouseWheelScrollLines / 120).ToString(); //ホイールを上方向に動かす場合 if (e.Delta > 0) { this.power++; //初速を上げる } //ホイールを下方向に動かす場合 else if (e.Delta < 0) { this.power--; //初速を下げる } } private void Formballshoot_KeyDown(object sender, KeyEventArgs e) { Timer timer = new Timer(); timer.Interval = 50; //エンターキーを押した場合 if (e.KeyData == Keys.Enter) { timer.Tick += new EventHandler(Update); timer.Start(); //タイマースタート } } }
}