Question

How to create solid object in my game.

Asked by: KG1973

Hi,
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 ============================, which I think where the changes should be, or state otherwise.

Thanks.
          

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace WindowsGame1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
 
        //Global Variable Declarations
        Texture2D backgroundTexture;
        Texture2D sprite; 
        Texture2D sprite1;
        Point frameCounter = new Point(0,0);  
        Point frameCounter1 = new Point(0, 0);
        Vector2 position = Vector2.Zero; 
        Vector2 speed = Vector2.Zero; 
        SpriteEffects se =SpriteEffects.FlipHorizontally; 
 
        
        double frameDelay = 0.1; 
        double frameDelay1 = 0.5;
        Level level; //xml level code that will be serialized into this object
        SpriteFont spriteFont;
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
 
        protected override void Initialize()
        {
            XmlSerializer s = new XmlSerializer(typeof(Level));
            TextReader r = new StreamReader("Content/Level.xml");
 
            level = (Level)s.Deserialize(r);
 
            r.Close();
 
            
            foreach (Level.character c in level.allCharacters)
            {
                c.sprite = Content.Load<Texture2D>(c.textureAsset);
                c.bound = new BoundingSphere(new Vector3(c.position , 0), 50);
            }
 
            base.Initialize();
        }
 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont = Content.Load<SpriteFont>("Arial");
 
            backgroundTexture = Content.Load<Texture2D>("Background");
            sprite = Content.Load<Texture2D>("Boy");
            sprite1 = Content.Load<Texture2D>("Tree");
 
 
	    //================= Help me here ============================
	    //
            //create new sprite here called Fence or wall
            //png file will be added into the content called Fence.png
 
 
 
        }
 
        protected override void UnloadContent()
        {
        }
 
        protected override void Update(GameTime gameTime)
        {
 
            KeyboardState kb = new KeyboardState();
            kb = Keyboard.GetState();   
            speed = Vector2.Zero;       
            bool moving = false;         
 
            if (kb.IsKeyDown(Keys.Right))
            {
                
                speed.X = 2;
                moving = true;
                
                se = SpriteEffects.FlipHorizontally;
                frameCounter.Y = 0;
            }
            if (kb.IsKeyDown(Keys.Up))
            {
                speed.Y = -2;
                moving = true;
                frameCounter.Y = sprite.Height * 2 / 3;
            }
            if (kb.IsKeyDown(Keys.Left))
            {
                speed.X = -2;
                moving = true;
                
                se = SpriteEffects.None;
                frameCounter.Y = 0;
            }
            if (kb.IsKeyDown(Keys.Down))
            {
                speed.Y = 2;
                moving = true;
                frameCounter.Y = sprite.Height / 3;
            }
            
            position += speed;
 
            if (moving)  
            {
                
                frameDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                if (frameDelay < 0)
                {
                    
                    frameDelay = 0.1;
                    frameCounter.X += sprite.Width / 8; 
                    if (frameCounter.X >= sprite.Width) frameCounter.X = 0; 
                }
            }
            frameDelay1 -= gameTime.ElapsedGameTime.TotalSeconds;
            if (frameDelay1 < 0)
            {
                
                frameDelay1 = 0.5;
                frameCounter1.X += sprite1.Width / 5; 
                if (frameCounter1.X >= sprite1.Width) frameCounter1.X = 0; 
            }
            base.Update(gameTime);
        }
 
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Green);
            spriteBatch.Begin();
 
            //Draw Background (Background with trees, rock, garden etc...)
            spriteBatch.Draw(backgroundTexture, new Rectangle(0,0,Window.ClientBounds.Width, Window.ClientBounds.Height), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
            
            //Draw Sprite1 (Tree)
            spriteBatch.Draw(sprite1, new Vector2(300, 500), new Rectangle(frameCounter1.X, frameCounter1.Y, sprite1.Width / 6, sprite1.Height), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            
            //Draw Sprite (Boy character)
            spriteBatch.Draw(sprite, position, new Rectangle(frameCounter.X, frameCounter.Y, sprite.Width/8, sprite.Height/3), Color.White,0,Vector2.Zero,1,se,0);
 
	    
 
	    //================= Help me here ============================
	    //
            //Draw new sprite (Fence)
            //The boy cannot past through the fence
 
 
            //create a bounding sphere at the players current position
            BoundingSphere playerSphere = new BoundingSphere(new Vector3(position,0),1);
            
            //In this loop we draw each Male/Female character...
            foreach (Level.character c in level.allCharacters)
            {
                spriteBatch.Draw(c.sprite, c.position, new Rectangle(0, 0, c.sprite.Height, c.sprite.Height), Color.White, 0, Vector2.Zero,c.scale, SpriteEffects.None, 0);
                
                if (c.bound.Intersects(playerSphere))
                {
                    
                    spriteBatch.DrawString(spriteFont, c.greeting, (c.position + new Vector2(10, -10)), Color.White);
                }
 
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-12 at 14:38:03ID24316113
Tags

Strategy Games

Topics

Computer Games

,

Miscellaneous Games

,

Game Programming

Participating Experts
1
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. The Best Sprites!!
    Which way can I produce good-quality sprites? I want to develop a game written in C. 1. use vector to draw the image (The quality is not that good) 2. use bitmaps (but still I have to draw it myself) 3. Scan real images (but I don't have a sc...
  2. Game Sprite Movement
    Ok here is my question I am trying to make a small game where the user can click on the map and the unit automatically goes to that location. what my question is, is how do I design an Eqaution to Take 2 sets of X,Y or X,Y,Z and get a third result that is where the unti needs...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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.

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/readarticle.php?article_id=126

As for drawing of the fence, it looks like you can copy/paste it from Tree and Boy??

 

by: KG1973Posted on 2009-04-13 at 16:25:34ID: 24133767

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.

 

by: KG1973Posted on 2009-04-14 at 05:43:18ID: 24137499

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 ?

 

by: KG1973Posted on 2009-04-14 at 05:45:38ID: 24137515

sorry, actually the code like ths :
   
             if (position.X > 100)
                    position.X = 100;
                if (position.X < 0)
                    position.X = 0;

                // Simular for Y
                if (position.Y > 100)
                    position.Y = 100;
                if (position.Y < 0)
                    position.Y = 0;

but still does not working.

 

by: XconePosted on 2009-04-14 at 11:53:25ID: 24141291

Could you please send me your project, so I'll be able to compile and run it here. I can help you better if I can see what happens.

 

by: KG1973Posted on 2009-04-14 at 17:01:55ID: 24143775

what is your email address?

 

by: XconePosted on 2009-04-14 at 23:31:39ID: 24145184

I'm not sure if posting personal information (like an e-mail address) is allowed by Expert Exchange rules. I've asked the community support about this. Can't you attach the file as part of a comment, or maybe provide it as external link?

 

by: KG1973Posted on 2009-04-15 at 05:58:19ID: 24147408

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.

 

by: XconePosted on 2009-04-15 at 08:22:00ID: 24149057

I agree to that. I think it will be fine without the .sln file.

 

by: KG1973Posted on 2009-04-15 at 14:50:46ID: 24152925

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.


 

by: XconePosted on 2009-04-15 at 15:06:36ID: 24153040

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.

 

by: KG1973Posted on 2009-04-16 at 01:55:04ID: 24155592

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/Expert/Upload/viewFilesQuestion.php?qid=24316113

Direct link to your file
http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=7604

 

by: KG1973Posted on 2009-04-16 at 02:02:01ID: 24155634

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.

 

by: XconePosted on 2009-04-16 at 10:57:51ID: 24160439

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.

protected override void Update(GameTime gameTime)
        {
 
            KeyboardState kb = new KeyboardState();
            kb = Keyboard.GetState();   //current state of the keyboard 
            speed = Vector2.Zero;       //Reset our speed value 
            bool moving = false;          
 
            if (kb.IsKeyDown(Keys.Right))
            {
                //set the speed value, the sprite is now moving
                speed.X = 2;
                moving = true;
                //make our spriteeffect flip the sprite to face right
                se = SpriteEffects.FlipHorizontally;
                frameCounter.Y = 0;
            }
            
            if (kb.IsKeyDown(Keys.Up))
            {
                speed.Y = -2;
                moving = true;
                frameCounter.Y = sprite.Height * 2 / 3;
            }
 
            if (kb.IsKeyDown(Keys.Left))
            {
                speed.X = -2;
                moving = true;
                //reset the spriteeffect 
                se = SpriteEffects.None;
                frameCounter.Y = 0;
            }
            if (kb.IsKeyDown(Keys.Down))
            {
                speed.Y = 2;
                moving = true;
                frameCounter.Y = sprite.Height / 3;
            }
            //add speed value 
            position = MoveBoy(position, speed);
 
            if (moving) //if the sprite has moved this update 
            {
                frameDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                if (frameDelay < 0)
                {
                    //advce to the next frame
                    frameDelay = 0.1;
                    frameCounter.X += sprite.Width / 8; 
                    if (frameCounter.X >= sprite.Width) frameCounter.X = 0; 
                }
            }
 
            base.Update(gameTime);
        }
 
        private Vector2 MoveBoy(Vector2 position, Vector2 speed)
        {
            // Check edges of the playfield
            Vector2 topLeft = new Vector2(0, 0);
            Vector2 bottomRight = new Vector2(750, 550);
            speed = Vector2.Clamp(position + speed, topLeft, bottomRight) - position;
 
            // Check Collision on entities in the World
            BoundingSphere playerPositionSphere = new BoundingSphere(new Vector3(position, 0), 1);
            BoundingSphere playerPositionPlusMovementSphere = new BoundingSphere(new Vector3(position + speed, 0), 1);
            float overlap;
            Vector3 speedCorrection3D;
            foreach (Level.character c in level.allCharacters)
            {
                // Check of the movement causes an overlap.
                if (c.bound.Intersects(playerPositionPlusMovementSphere))
                {
                    // Yes, there's an overlap, how much?
                    overlap = (c.bound.Radius + playerPositionPlusMovementSphere.Radius) - (new Vector3(position, 0) - c.bound.Center).Length();
 
                    // Get the direction from the entity to the boy's position.
                    // Use the direction to correct the direction of speed with the ammount of overlap.
                    speedCorrection3D = (Vector3.Normalize(new Vector3(position, 0) - c.bound.Center) * overlap);
 
                    // Since our result is a Vector3, because the Bounding object from XNA are Vector3's, we need to manually get the XY value.
                    speed.X += speedCorrection3D.X;
                    speed.Y += speedCorrection3D.Y;
 
                    // Create a new sphere containing the new movenent. Required to check for other collisions
                    playerPositionPlusMovementSphere = new BoundingSphere(new Vector3(position + speed, 0), 1);
                }
            }
 
            // Return new position of the boy.
            return position + speed;
        }

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:

Select allOpen in new window

 

by: KG1973Posted on 2009-04-16 at 13:41:30ID: 24162364

Xcone,
That was GREAT !!!!!. We almost there. Now its seems that Bouncing Box or Rectangle is more
appropriate than Spehere one, since the barn/fence are normally either square or rectangle.

How can I change it to rectangle ? ( last one ). The point will be yours........
Thanks a million.


 

by: KG1973Posted on 2009-04-17 at 07:55:31ID: 24168436

Xcone, if you could helpme on the last one. please...

 

by: XconePosted on 2009-04-17 at 08:22:02ID: 24168713

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.

 

by: KG1973Posted on 2009-04-22 at 17:24:48ID: 24210848

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. :)

 

by: XconePosted on 2009-04-22 at 23:23:40ID: 24212192

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.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...