Collision Detection
Author |
Message |
Foxhunter
|
Posted: Thu Jan 13, 2011 10:33 am Post subject: Collision Detection |
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DragAndDropOfImage
{
public partial class Form1 : Form
{
static System.Windows.Forms.Panel curBox=null ;
Bitmap ourBackground;
public Form1()
{
InitializeComponent();
}
private void panel_MouseDown(object sender, MouseEventArgs e)
{
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
//specify either user wants to copy the data or move data
Panel source = (Panel)sender;
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
curBox = (Panel)sender;
}
private void panel_DragEnter(object sender, DragEventArgs e)
{
//As we are interested in Image data only we will check this as follows
if (e.Data.GetDataPresent(typeof(Bitmap)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void panel_DragDrop(object sender, DragEventArgs e)
{
//target control will accept data here
Panel destination = (Panel)sender;
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
}
private void Form1_Load(object sender, EventArgs e)
{
ourBackground =new Bitmap("..\\..\\4.jpg"); //the background
//ba
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(ourBackground,0,0);
g.FillRectangle(Brushes.DarkGreen, new Rectangle(1150, 450, 10, 400));// the pegs
g.FillRectangle(Brushes.DarkGreen, new Rectangle(250, 450, 10, 400));
g.FillRectangle(Brushes.DarkGreen, new Rectangle(700, 450, 10, 400));
}
private void panel3_Paint(object sender, PaintEventArgs e)
{
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (curBox != null)
{
curBox.Left = e.X+1;
curBox.Top = e.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
curBox = null;
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
curBox = null;
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
}
}
}
I am doing a project for school and I need to know how detect a collision between two things. Our game is Towers Of Hanoi, for those of you who don't know what that is, you have a three pegs with a number of rings on them. The goal is to move all of the rings from one peg to another, but you can only move one ring at a time and you can not move a larger peg on to a smaller peg. So far we have figured out how to drag the rings (which are in image boxes) on to the pegs, but we can not figure out how to detect a collision between the pegs and the rings. Please help. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Thu Jan 13, 2011 4:34 pm Post subject: RE:Collision Detection |
|
|
Look at the collision detection tutorial here. The examples are written in Turing but the concepts are the same. |
|
|
|
|
|
Velocity
|
Posted: Wed Nov 23, 2011 9:52 am Post subject: RE:Collision Detection |
|
|
try to put it in syntax form next time please, and why dont you look in if statements with the math arithmatic you might have learned |
|
|
|
|
|
md
|
Posted: Wed Nov 23, 2011 10:22 am Post subject: RE:Collision Detection |
|
|
Do not revive dead threads.
This thread is also in the wrong forum it seems... but I'm not sure I want to move it now. |
|
|
|
|
|
|
|