Xcone,
Yes you are right. It's C# not c++. Sorry for this.
I would do an object for the fence (rectangular shape, just for a simple test). But I don't know how to create do collision detection with simple object.
Main Topics
Browse All TopicsHi,
I am new with game development. Currently I am creating simple game (VS 2008 C++ and XML). The game should be simple. The following code actually contain :
1. Background (garden)
2. Tree
3. Boy character, walking around the garden.
The boy can walk around including passig through the Tree.
What I want to do is,
1. to create a new object/sprite called "Fence". And the boy can walk anywhere around the garden, but he should not be allowed to pass through the fence. I assumed that the fence is solid object. At this stage I don't border so much the location of the fence.
2. create another obeject, let say "Tunnel" or "Cave". When the boy go into the tunnel/Cave, then new screen will be displayed, as if new level of the game with new background but with the same character (Boy).
I'd marked the code //================= Help me here ==========================
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Xcone,
I had added the code as follow :
position += speed;
if (position.X > 100)
position.X = 100;
if (position.X < 0)
position.X = 0;
// Simular for Y
if (position.X > 100)
position.X = 100;
if (position.X < 0)
position.X = 0;
But the Boy character still able to walk entire screen.
Can you helpme on this ?
ok, I will try to attach my project file here (zip file).
But failed due to the file type .sln .
The extension of one or more files in the archive is not in the list of allowed extensions: XML Demo/WindowsGame1.sln
Strange, it says that it can accept zip file.
So I cannot post i here. I can rezip all files again but without 1 file (.sln) Will that ok for you, coz probably you may create new project and then copy & paste all my files.
But I will only post it if you agreed.
Thanks.
Xcone,
It is not just shl file but there are some files still not allowed (.xna, .xml, .shl, .exe, .pbd, .spritefont , contentproj, .cache, .db).... i dont know how else..
modus operandi,
>>One thing you can do, if the file(s) get blocked by EE, is upload them to a related site,
>>www.ee-stuff.com, which allows darn near any file type, and then post a link to the uploaded file.
Can you helpme on this. I couldn't find anything at the site that you gave to upload my project files.
At www.ee-stuff.com, login with the same username and password that you use on this page. If succesful, a new tab 'Expert Area' will appear, click it. There's a list of 5 items on that page. The 4th is 'File Upload/Storage' and contains a subitem with a link to upload files. Follow that link, then follow the instructions on the screen.
Xcone,
Finally I uploaded the flle.
Your file has successfully been uploaded!
To download the file, you must be logged into EE-Stuff. Here are two pages that will display your file,
View all files for Question ID: 24316113
http://www.ee-stuff.com/Ex
Direct link to your file
http://www.ee-stuff.com/Ex
Xcone,
In the program, Ive 2 sprites. Boy and other the Barn.
If the boy walk thru the Barn, it wll collide and display a message.
What I want is, asssuming the Barn is a fence, the Boy should not e able to walk through the Barn/fence.
Similarly if he walk through the end of the windows.
Simple logic that I want to implement, when we press , let say "Right" key, the moment it collide, thefunction key "Right" will be disabled until other key pressed. This would prevent us to press Right key, stop moving the boy further right direction.
I need the solution urgently.
Thanks a million.
Hi, I've worked it out for you. Replace you Update Method for the in the attached code, and eveything should work fine. Exept for some minor tweaking on your part.
The collision detection was working nicely the way you had it in the Draw Method, so I used the same way to detect them. In the MoveBoy function there's also Collision HANDLING.
Don't be suprised if the result is not completely to your desire. The topleft position of the sprites are drawn on the centerposition of your levelentities. Therefor it looks like it is wrong, but it actually isn't. But this is something you have to correct yourself.
Your level.character object doesn't support bounding boxes. It uses bounding spheres. That's why I used bounding spheres in the collision handling as well.
If you want bounding boxes, you have to alter your level.character class to support bounding boxes, or maybe even multiple types of bounding shapes (which is even more advanced). Then you need to alter the MoveBoy method, to work with bounding boxes, which basicly requires a different type of collision handling.
Judging by you current knowledge of vector math (no offence), this is not a step you want to take right now. I suggest you keep it with bounding spheres for the moment. And focus your attention on other aspects of the game, or maybe take a crash course vector math using a few tutorials. Basic understanding of vector math is essential for collision detection and handling.
I won't be able to help you on this the next few days, due to some problems with my computer. I'm sorry for that. Please let me know if you need more help. I'll help you the best I can in a few days.
Xcone,
>>Judging by you current knowledge of vector math (no offence),
No problem at all. You are right. I am still newbie with this game development.
Now I realised that once it get work, one by one, its getting excited. Now I almost finish the 1s level of the game. The square bouncing box that I mention earlier, I can forget it for now coz with sphere one, I can manipulate it. I also managed to create an invisible object that I can use it as the wall or fence. These objects were placed on top of the backgorund. The user wont realised that the character are actually collided with invisible object.
Very interesting. Even sound also I managed to add easily. The solution that you gave me, really helpful++ :) Now I want to do the ext level, with different storyline but I don't know how to create 2nd level in the same project. Can I create level2.xml for this ? Please advise so that I can open new question.
Thanks a miliion. You really save my life. :)
That's the whole problem with development of a project. You build something, you add something, you realise something and then suddenly, you want something extra you didn't anticipate and it's gonna be a HARD time getting it to work neatly in the rest of the code. There's only one solution to this problem. Planning.
Before you create something, you sit down and think REAL hard on what you want it to accomplish. Then you create diagrams and start planning on the things you need to accomplish this. This is quite a common step in profesional development, but it's a step which is easily forgotten when doing devlopment as hobby. Hehe, I forget it all time as well.
Obviously, you're beyond this step now. You've created a big part of your game, and now you want something extra you didn't anticipate on. The steps you have to take now are these:
- Make sure you want what you want. (is this step really nessecary)
- Decide how you want it. (Level change, new games, multiplayer modes, different gametypes)
- Decide which additional support is required. (savegames perhaps?)
- Create a plan on how to create this. Ignoring the current state of your game.
- Use that plan to determine how well it's going to fit in your current game.
- The issues you get here, you've got to decide if you will change your plan, or if you change your game to support your plan.
Well, that's the theory. In practice you'd probably want to use the XMLserializer you allready have. That's the way your levels are loaded. So you need to create way to trigger a level change (collision?). Unload the current level, load the new level, position your boy character to the position which is expected after change of level and then you've got most of it to work.
Business Accounts
Answer for Membership
by: XconePosted on 2009-04-13 at 14:28:36ID: 24133088
Are you sure it's C++ with XML?. It looks like C# with XNA.
eadarticle .php?artic le_id=126
You're trying to test for movement in your draw method. This should actually be part of the Update method. To prevent movement, you should calculate the movement (which you do) and then test if that movement is allowed by the World you're in (which you don't). In your code you simply execute: "position += speed" with no testing at all.
If your fence is square (the edges of the screen) testing is really simple, something like:
position += speed;
if (position.X > 1000)
position.X = 1000;
if (position.X < 0)
position.X = 0;
// Simular for Y
If you also have diagonal fences, or other complicated shapes, you really should advance to somesort of collision detection. Try these sites to find a good tutorial on the matter:
http://www.ziggyware.com
http://creators.xna.com
This link points to a simple tutorial that looks like you can use it:
http://www.ziggyware.com/r
As for drawing of the fence, it looks like you can copy/paste it from Tree and Boy??