Click here to Skip to main content
15,881,877 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to get cell values in devexpress gridcontrol via a function Pin
Richard MacCutchan28-Jun-13 23:16
mveRichard MacCutchan28-Jun-13 23:16 
GeneralRe: How to get cell values in devexpress gridcontrol via a function Pin
Member 253280030-Jun-13 15:29
Member 253280030-Jun-13 15:29 
GeneralRe: How to get cell values in devexpress gridcontrol via a function Pin
Member 253280030-Jun-13 18:03
Member 253280030-Jun-13 18:03 
GeneralRe: How to get cell values in devexpress gridcontrol via a function Pin
Richard MacCutchan30-Jun-13 21:19
mveRichard MacCutchan30-Jun-13 21:19 
QuestionGrid Based Games Pin
Midnight Ahri28-Jun-13 1:34
Midnight Ahri28-Jun-13 1:34 
AnswerRe: Grid Based Games Pin
Pete O'Hanlon28-Jun-13 2:22
mvePete O'Hanlon28-Jun-13 2:22 
GeneralRe: Grid Based Games Pin
Midnight Ahri28-Jun-13 6:23
Midnight Ahri28-Jun-13 6:23 
AnswerRe: Grid Based Games Pin
Emmanuel Medina28-Jun-13 9:03
professionalEmmanuel Medina28-Jun-13 9:03 
What you are looking for, as the above poster pointed out, is Collision Detection, you should be able to find plenty of sources on it, I will list a few:

Collision Detection[^] on wikipedia (theory)
Testing for Collisions[^] on MSDN, this is for (the now unsupported) XNA Framework
Pacman in C# (map & collision detection)[^] A question here in CodeProject
C# Game Programming for Teens[^] In this book you will follow the chapters to make a 2D Dungeon Crawler. Chapter 4 deals with collision detection

EDIT:

If you are using sprites (which I guess is the case) you have to check if the object's rectangle intersects with any other object's rectangle, take into account that the rectangle also counts the transparent pixels of your sprite. You could do your own way of checking for an intersection between two rectangles, but you can use the IntersectsWith[^] method.

If your object is non-player controlled, it most likely has a velocity, so you can predict the collision by calculating the coordinates for the next iteration and checking for intersections with those coordinates.

Example:

Player controlled object:
C#
public class PlayerObject
{
  public Point Location {get; set;}
  public Size ObjectSize (get; set;}
  public Rectangle Bounds {get; set;}

  public PlayerObject(Point loc, Size objSize)
  {
    Location = loc;
    ObjectSize = objSize;
    Bounds = new Rectangle(Location.X, Location.Y, Location.X + Size.Width, Location.Y + Size.Height);
  }

  //Collision detection
  public bool IsColliding(ref GameObject obj)
  {
    bool collides = Bounds.IntersectsWith(obj.Bounds);
    return collides;
  }
}

If you think you can do a thing or think you can't do a thing, you're right - Henry Ford

Emmanuel Medina Lopez

Question[RESOLVED] Regular Expressions Problem Pin
Sonhospa27-Jun-13 23:13
Sonhospa27-Jun-13 23:13 
AnswerRe: Regular Expressions Problem Pin
Eddy Vluggen28-Jun-13 1:53
professionalEddy Vluggen28-Jun-13 1:53 
GeneralRe: Regular Expressions Problem Pin
Sonhospa28-Jun-13 2:43
Sonhospa28-Jun-13 2:43 
GeneralRe: Regular Expressions Problem Pin
Eddy Vluggen28-Jun-13 6:28
professionalEddy Vluggen28-Jun-13 6:28 
AnswerRe: Regular Expressions Problem Pin
Richard MacCutchan28-Jun-13 2:22
mveRichard MacCutchan28-Jun-13 2:22 
GeneralRe: Regular Expressions Problem Pin
Sonhospa28-Jun-13 2:48
Sonhospa28-Jun-13 2:48 
GeneralRe: Regular Expressions Problem Pin
Richard MacCutchan28-Jun-13 3:00
mveRichard MacCutchan28-Jun-13 3:00 
GeneralRe: Regular Expressions Problem Pin
Sonhospa28-Jun-13 3:17
Sonhospa28-Jun-13 3:17 
GeneralRe: Regular Expressions Problem Pin
Richard MacCutchan28-Jun-13 3:30
mveRichard MacCutchan28-Jun-13 3:30 
QuestionWord Object Error Pin
bganesan27-Jun-13 22:18
bganesan27-Jun-13 22:18 
QuestionRe: Word Object Error Pin
ZurdoDev28-Jun-13 9:43
professionalZurdoDev28-Jun-13 9:43 
Questionhelp button and f1 key error Pin
User349027-Jun-13 22:09
User349027-Jun-13 22:09 
QuestionControling a scroll bar for Remote Desktop Pin
Andre O Rahming27-Jun-13 7:42
Andre O Rahming27-Jun-13 7:42 
QuestionC# desktop type ahead Pin
dcof27-Jun-13 6:35
dcof27-Jun-13 6:35 
AnswerRe: C# desktop type ahead Pin
Ron Beyer27-Jun-13 6:49
professionalRon Beyer27-Jun-13 6:49 
QuestionParanoid Question of the Day Pin
Keith Barrow27-Jun-13 3:50
professionalKeith Barrow27-Jun-13 3:50 
AnswerRe: Paranoid Question of the Day Pin
PIEBALDconsult27-Jun-13 3:56
mvePIEBALDconsult27-Jun-13 3:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.