Getting started: Newbie Frustration (XNA 4.0, Bounding Boxes, and Joining Classes)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to get into using the XNA add-on to develop games. Ive followed the documentation and gotten far enough that I have a sprite (for now its a tree) that falls on a screen. And a row of sprites (grass) generated with a for loop to represent the
floor. Naturally, at this stage the tree sprite falls and goes through the grass. Now I need to figure out how to create a bounding box.
Ive found bits and pieces of code in other so-called "tutorials". Mainly the ping pong one that instructs me to replace non-existant lines of code with given lines. In the end Im stuck with dozens of errors that I cannot figure out for the life of me how
to resolve. Not with my current experience anyways. The other snippets of code that Ive found are very large, complex, contain irrelevant information, and dont really tell you whats what.
The problem is that I learn best with a hands-on approach. In fact, Im extremely good at doing so. On the opposite end however, I seem to have serious trouble trying to comprehend written instructions on complex subjects. Videos are good, but its a rather
bad medium to teach scripting through. Ive worked with another scripting language in the past and managed to become very adept at that particular language simply through self-teaching by manipulation of copied blocks of code. The reason Im posting all of
this is because I came from a community in which posting straight examples in response to script requests was relatively frowned upon. As it was believed that it hindered the learning process by giving people simple copy-paste material. Im unsure of whether
or not the same belief is held on these forums, but I really need help here so Im caving in and asking it here.
With that out of the way, what Im in dire need of is a straight bare bones working example of a bounding box. I put some thought into it, and I think the simplest example that would provide all the information I need would be an example where we have
two squares on either side of the screen that move towards the center, collide, and react by moving backwards. (Dont care what happens after that. They could stop at the edges, do it again, or just keep going outwards forever. It doesnt really matter.)
If anyone could provide such a script, It would be greatly, greatly appreciated.
Secondly, I know that an important part of keeping scripts manageable is breaking them up into other classes. Im unsure about whether or not I should keep these within the same .cs file, or break them up into multiple .cs files. Im looking for what code
would be required in order to call a function/method/whatever from another .cs file. The programming language that I came from seems to have approached this very differently. So if someone could also provide two scripts. one which simply calls the script from
the other, and returns a boolean or a string. (i.e. lets say calling "Hello World!" from a different script.) That would also be great.
Thank you for taking the time to read this.

View the full article
 
Back
Top