Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411576 Posts in 69386 Topics- by 58444 Members - Latest Member: darkcitien

May 05, 2024, 07:46:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)C# Problems with collision detection, I need serious help!
Pages: [1]
Print
Author Topic: C# Problems with collision detection, I need serious help!  (Read 1781 times)
PlayMeTape
Guest
« on: August 21, 2009, 10:21:38 AM »

I'm finishing up a course I took in programming (for beginners), a pretty lousy one at that. I'm woriking on our last assignment in which we're supposed to make a simple game. I took the framework from a tutorial we took before the last assignment. I'm trying to implement the pixel perfect collision from the education section. I'm having a real hard time getting it to work since I'm using a lot of classes.

I would really appreciate if someone could take a look at my project and see where things should go (I'm really new to programming). If anyone would mind ammending some faults in it our explain to me where things should go I would REALLY appreciate it!!

I'll put up the whole .rar file (which contains the entire project) since I'm using lots of classes and stuff. BTW, there's lots of unused code in there right now just so you know. Plus, right now the different codes from the collision example is probably in all the wrong places since I'm trying to get it right.

To anyone taking the time to look at my project, THANK YOU!

Download link
http://rapidshare.com/files/269902709/WindowsGame1.rar
Logged
Aquin
Level 10
*****


Aquin is over here.


View Profile WWW
« Reply #1 on: August 21, 2009, 10:40:46 AM »

Seriously?  C# for a beginner?  Like your first language ever?  Teaching you all the delightfully specific Windows-only 'features'?

Harsh dude.  I'm looking through it now, be back in a bit.
Logged

I'd write a devlog about my current game, but I'm too busy making it.
Ravine
Level 0
**


View Profile
« Reply #2 on: August 21, 2009, 12:31:38 PM »

Seriously?  C# for a beginner?  Like your first language ever?  Teaching you all the delightfully specific Windows-only 'features'?

Harsh dude.  I'm looking through it now, be back in a bit.
Hmmm quite a weak troll as a first reply does not help much. I cant wait for your next answers where you'll list all these funky "windows only features" you're talking about. In the meantime, i'll start gather links to Mono, definition of the CLR, .Net, the language itself, and the framework used, just to pinpoint how wrong you can be with so few words.

And of course i'll check the code for Christoffer.
Logged
PlayMeTape
Guest
« Reply #3 on: August 21, 2009, 12:38:11 PM »

Seriously?  C# for a beginner?  Like your first language ever?  Teaching you all the delightfully specific Windows-only 'features'?

Harsh dude.  I'm looking through it now, be back in a bit.
Hmmm quite a weak troll as a first reply does not help much. I cant wait for your next answers where you'll list all these funky "windows only features" you're talking about. In the meantime, i'll start gather links to Mono, definition of the CLR, .Net, the language itself, and the framework used, just to pinpoint how wrong you can be with so few words.

And of course i'll check the code for Christoffer.

Actually, he tried to help me a little more in PMs. But he told me that he doesn't have any experiece in C#.

Let me just say thank you beforehand because I'm having major problems with this.
Logged
Ravine
Level 0
**


View Profile
« Reply #4 on: August 21, 2009, 01:11:37 PM »

First problem : your solution does not compile. I guess there's quite copypasta here and there, which leads to that situation.

With some quick comment, i've lauched it in debug, and found that your .Space for all the enemies X and Y coords are stuck at what (i guess) are they spawn coords. The code in _checkCollision() seems to not take current position to check bounding box intersection.

I'll come back with more infos after some debug runs.
Logged
Ravine
Level 0
**


View Profile
« Reply #5 on: August 21, 2009, 01:24:46 PM »

afaik, the "Space" property of Entity (which means of Player and Ennemies) is not updated. In other words, the first test of _checkCollision in GameState.cs will always be a fail, since all ennemies Space will start in Y == -50, outside the screen.

Since this property is not updated, the intersection test between your ennemies and your player is always false : their spaces is somewhere else.

You should have a look at http://creators.xna.com/en-US/tutorial/collision2dperpixeltransformed which i hope will help you set up some Axis Aligned Bounding Box (aka the almighty AABB) on your rotated ennemy sprites.

This should help for now, do not hesitate to tell us is there's more problems, even with those hints.

EDIT (Now with more hints ! seen on TV !)
Or you can just use a dummy rectangle in your GameState.cs, and put the X and Y position of your ennemy as its X and Y (to avoid doing nasty "new Rectangle(x, y, 50, 50)" for each ennemy, each update), and then, test againts your player rectangle.

But that's just a workaround, that does not solve the "Space property of entities is not updated" problem. If you solve that one, this first interesection test should work, and then, the pixel perfect method should be called accordingly.
« Last Edit: August 21, 2009, 01:41:33 PM by Ravine » Logged
Aquin
Level 10
*****


Aquin is over here.


View Profile WWW
« Reply #6 on: August 21, 2009, 02:22:14 PM »

Hurray, I got called a troll!  First time ever, and it's about damn time!  Well, hello there!

As for rattling off a bunch of stuff.  Sorry Ravine, I'm not interested in such a stupid conversation.  I did try to help him out with the basics though.  It seems the teacher is skimping on a lot of the fundamentals and not explaining anything introduced in the example material provided.
Logged

I'd write a devlog about my current game, but I'm too busy making it.
PlayMeTape
Guest
« Reply #7 on: August 21, 2009, 03:30:48 PM »

afaik, the "Space" property of Entity (which means of Player and Ennemies) is not updated. In other words, the first test of _checkCollision in GameState.cs will always be a fail, since all ennemies Space will start in Y == -50, outside the screen.

Since this property is not updated, the intersection test between your ennemies and your player is always false : their spaces is somewhere else.

You should have a look at http://creators.xna.com/en-US/tutorial/collision2dperpixeltransformed which i hope will help you set up some Axis Aligned Bounding Box (aka the almighty AABB) on your rotated ennemy sprites.

This should help for now, do not hesitate to tell us is there's more problems, even with those hints.

EDIT (Now with more hints ! seen on TV !)
Or you can just use a dummy rectangle in your GameState.cs, and put the X and Y position of your ennemy as its X and Y (to avoid doing nasty "new Rectangle(x, y, 50, 50)" for each ennemy, each update), and then, test againts your player rectangle.

But that's just a workaround, that does not solve the "Space property of entities is not updated" problem. If you solve that one, this first interesection test should work, and then, the pixel perfect method should be called accordingly.

Thank you for all the helpful hints, my problem is that I've got no idea of how it compiles the code (in which order) so I don't know where everything goes. That tutorial you linked me to is the the one I've tried to incorporate without success, you can see traces of it here and there in my code. Right now I'm starting over with less classes and not building it on the framework from my teachers tutorial. I figured that the game I'm making isn't going to be very complex so I don't NEED to optimize it with lots of classes and stuff.

I'll get back to you once I've got everything in place on whether I can get it to work or not.

Thanks again.

Edit:
Okay so I redid it but started with the collision engine as the foundation instead of the other way around. It works now but it the collisions register incorrectly. I'm going to keep working on it (I realize that some of the problem comes from rotating my sprite, but it doesn't even register correctly without me rotating the sprite). If anyone has any hints on correcting this, please help me out!

http://rapidshare.com/files/270029012/NewGame.rar
« Last Edit: August 21, 2009, 05:17:14 PM by Christoffer » Logged
Ravine
Level 0
**


View Profile
« Reply #8 on: August 21, 2009, 05:20:17 PM »

Hurray, I got called a troll!  First time ever, and it's about damn time!  Well, hello there!

As for rattling off a bunch of stuff.  Sorry Ravine, I'm not interested in such a stupid conversation.  I did try to help him out with the basics though.

Not interested either, i'm just tired of trolls from every sides. Between foss guys bullshits and msfties dishonesty, with a lot of in-between. Dont like a language ? Fine by me. Just dont throw stupid statements here and there, especially if you dont know the platform. It's not especially for you, dont take it personnally. It's just, i dont get it. Interesting topics gets polluted because of those stuff, help requests are wiped because of threads hijacks, etc etc. No one progresses.

Quote
  It seems the teacher is skimping on a lot of the fundamentals and not explaining anything introduced in the example material provided.

That's another problem, which is not related to the platform nor the framework, but sure does not help at all :/

Chris > can you provide the "raw material" ? I mean, the subject, the context, requirements, the base project, etc ? I'd be glad to help you start it again from scratch.
Logged
PlayMeTape
Guest
« Reply #9 on: August 21, 2009, 05:36:54 PM »

Chris > can you provide the "raw material" ? I mean, the subject, the context, requirements, the base project, etc ? I'd be glad to help you start it again from scratch.

How do you mean? Our last assignment basically consisted of "Make a game". They told us that it would be best if we made some kind of clone off of an old arcade game. To keep it easy. I didn't want to make an exact remake so what I'm making in my game is a different kind of Asteroids. If you look at the player sprite you'll see that it's got two red tips. If those tips collide with the blue squares you're supposed to be destroyed. If you collide with them but within the white zone you'll destroy the blue squares. I want to wrap the screens and use movement that works kind of like the original Asteroids movement (if it's not to hard I would like to use thrust).

If there's anything else you need to know then tell me. As you may have noticed already I'm reeaally new at this, so I haven't grasped the most basic terminology:P.


Edit: Sweeeeet, I fixed the collision problem. I made the players transform matrix exactly the same as the enemies and now I've got pixel perfect collision  Wizard! Now to get working on movement. Any hints at making it move in the images direction. Should I use rays to calculate where the image is "pointed"?
« Last Edit: August 21, 2009, 05:47:58 PM by Christoffer » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic