Computer Science Canada Help with Side Scroller |
Author: | goober999 [ Fri Jan 05, 2007 4:43 pm ] | ||
Post subject: | Help with Side Scroller | ||
Ok I am in grade 10 and this project is for my summative. I am designing a mario game and so far your forums have been very useful when I'm stuck. Currently, I am having a problem getting the mario sprite to interact with the tiles in the level i have created. I have created a somewhat working collision detection system, but it is very glitchy, especially while mario is jumping. Here is the code:
I apologize, sloppy code, and many useless variables :p Any help would be greatly apprecited! Oh, and attached is the files. |
Author: | Ultrahex [ Fri Jan 05, 2007 5:27 pm ] |
Post subject: | |
Im Just Curious, But Did you ever actually write out this stuff on paper, had some initial plan before starting this??? and yes your code is quite horendus in terms of variable naming for someone to notice what your trying to do... by running the program it appears as though you are only doing vertical collision and not horizontal collision at all Ill look at it a little more, depends on how much my head hurts, but ill try... |
Author: | Ultrahex [ Fri Jan 05, 2007 8:06 pm ] | ||
Post subject: | |||
This is as far as i got trying to figure out what your code even does..... ... Yes i removed the jump and all collision detection for hope that it would help you somewhat.... the jump you implemented does not make logical sense to me BTW.
|
Author: | ericfourfour [ Fri Jan 05, 2007 8:24 pm ] | ||
Post subject: | |||
The naming convention for constants is almost always all capitals. Check out wtd's draft of style guidelines for more information. I also noticed some unnecessarily awkward variable names. chng, lend, and cntr. I assume the first means change, the second left_end and the third centre. Never sacrifice something as important as clarity for something as trivial as a few characters. |
Author: | CodeMonkey2000 [ Sat Jan 06, 2007 11:15 am ] | ||
Post subject: | |||
Wow that code is really messy, and has bad variable names. As for the code, i think it is you detection procedure, it should be a function and it should only return what you are looking for or "f".
this should work, assuming that this collision system is correct. Normally I would have the detection function take in x1,y1,x2,y2 and see if they are colliding in anyway and return true or false, that way the same function can be use for detecting enemies too. |
Author: | CodeMonkey2000 [ Sat Jan 06, 2007 11:27 am ] | ||
Post subject: | |||
And if you are not sure how to use that in your program, here
It doesn't work right. Mabey because you didnt implement it right or I did it wrong. But at least Mario get stuck in the blocks |
Author: | goober999 [ Sat Jan 06, 2007 2:57 pm ] | ||
Post subject: | |||
Ok thanks a lot for the help I have taken spearmonkey2000's idea of using functions and expanded on it a bit using two functions: 1 for verticle collision, and one for horrizontal collision. Now a new problem , for some reason, mario freezes when he encounters either type of collision. I'm oblivious to this any idea's?
|
Author: | CodeMonkey2000 [ Mon Jan 08, 2007 4:50 pm ] |
Post subject: | Re: Help with Side Scroller |
You need to rethink your collision system. You should be using only 1 function for detection. It should be taking in x1,y1,x2,y2 for mario and sx1,sy2,sx2,sy2 for blocks/enemies. When you call the function you should shouldn't input mario's current position, but rather the position he is going to be in. Check with all the objects, and if any of them return true then dont allow mario to move if they all return false then it is safe to move. |
Author: | ericfourfour [ Mon Jan 08, 2007 8:49 pm ] | ||||
Post subject: | Re: Help with Side Scroller | ||||
Don't hardcode these values. What you should do is read them from a file along with the tile map. The file would look something like this:
This way if you want to change maps you can choose which file to load it from. |
Author: | Clayton [ Mon Jan 08, 2007 9:44 pm ] |
Post subject: | Re: Help with Side Scroller |
an even better idea for the number of tiles being used is to have a flexible array that has it's upper bounds changed for each tile that comes into the game. Check out the flexible arrays tutorial in the Turing Walkthrough. |