Welcome! Log In Create A New Profile

Advanced

Solid sprites

Posted by Bowserkoopa 
Solid sprites
March 14, 2010 02:23PM
It's me again ;)
I have again a problem with the MLlib. So there're two questions: How can I make some sprites solid because I try to make a game, and it's a little bit strange when Mario would fall through the bottom^^
There's also a second quesion: How I can I make, that there's a gravity?
And at last the third question: How can I make, that the screen scrolls?

I'm not sure if it's possible to make a game with the MLlib but if somebody knows an easier way, tell me. Maybe I will only make a little fighting game so, I don't need a scrolling screen.
I know, it's not the best english but I'm still in education ;)
Re: Solid sprites
March 14, 2010 02:27PM
Quote
Bowserkoopa
How can I make some sprites solid because I try to make a game, and it's a little bit strange when Mario would fall through the bottom^^
There's also a second quesion: How I can I make, that there's a gravity?
And at last the third question: How can I make, that the screen scrolls?
Dude, it's not even close to being that simple. Since you seem to know C/C++ you need to go learn how to apply it to game programming. I could waste several hours of your life answering each of these questions.
Re: Solid sprites
March 14, 2010 08:19PM
I thought I could do something like that:
if(ML_IsCollision(&Hero, &Ground){
SetXPosition(GetX(&Ground));
SetYPosition(GetY(&Ground));
}

The only problem is, that there aren't commands like SetPosition() ;D For the gravity, I would have used the same mode like SetYPosition(GetY(AllSprites)+1) every three Frames. AllSprites would first be declared in an array .But for the screen scrolling, I haven't any ideas :(
Re: Solid sprites
March 14, 2010 08:39PM
The collision function just tells you if two sprites are touching each other. You'd need to write a custom collision detection method for landing on a platform for true precision. If you want to do some simple porting work, I wrote libwiisprite one's for my Hauntiing platformer game that you're welcome to borrow here: [wiibrew.org] Just be sure to play it before you steal stuff from the code to make sure it's what you are looking for.

For the gravity, yeah you're on the right track. But remember, the force of gravity is only a physical acceleration. You'd have to work in appropriate mass and velocity quantities so things aren't flying all over the place (unless you want them to of course). What you showed me would work, but it wouldn't look very realistic.

Screen scrolling isn't hard to do, but you have to understand the basic theory behind the coding of it. Do a little research and maybe at look at some examples of it.



Edited 1 time(s). Last edit at 03/14/2010 08:40PM by Arikado.
Re: Solid sprites
March 15, 2010 08:26AM
For simple platform games, you generally want to create a gravity variable for each of your objects and if there is no collision between the object and somthing tangible (like the floor) then you increase this variable and then move the object that amount towards the gravity source (usually the floor in platform games). This simulates acceleration...the longer that the object is not touching the floor the larger the gravity force will get and thus the faster the object will fall (i.e. acceleration). As was stated before the amount that this gravity variable is increased depends on the mass of gravitational object. On Earth the acceleration is approx 9.8m/s^2. However for a simple platform game you can just play with the numbers to see what "looks good".

Also be aware that this method needs care to ensure that the object does not start to move too fast. For example if you G is high then an object falling from the top of the screen to the bottom could pick up a lot of speed. If you just adjust the object position by this amount then you can run into problems because the object can eventually fall through things.

Consider a overdramatic example. Say you object is at the top of the screen and you are going to increase the gravity variable by 1 for each frame. In the first frame we adjust the object by 1 pixel. Next by 2 pixels. Next by 3 pixels. Next by 4 pixels. And so on. As you can see, at this point we are 1+2+3+4=10 pixels down the screen and we are already jumping by 5. By the time we would get to mid screen we would be jumping at intervals which could actually cause the object to jump over solid floor. For example, say the floor object is only 8 pixels high and is half way down the screen. Well by the time our object gets half way down the screen it will be jumping at more than 8 pixels every frame. As such it is possible that it will jump over the 8 pixel floor and keep going. Generally this can be avoided by setting your gravity variable at an appropriate value (starting with fractions of a pixel).
Re: Solid sprites
March 15, 2010 06:41PM
It seems that a realistic gravity would be one of the hardest problems to solve. Especially because C isn't a object-orientated programming languag like C++ . But I have a concept now, so everything is only a question of the transcription. A constant gravity variable and other variables for each sprite. I began to read the LibWiiSprite Tutorial but I think I have to read it again because it's not as easy as I thought...
Re: Solid sprites
March 16, 2010 01:11AM
Quote
Bowserkoopa
Especially because C isn't a object-orientated programming languag like C++ .
You know you can code for Wii homebrew in C++ right? IIRC MLIB has classes?
Re: Solid sprites
March 18, 2010 08:51PM
C++ for wii? That suprises me. I thougt that it is only possible to program with C for Wii. But it's good to know that it's possible to use C++ ;)
Re: Solid sprites
March 18, 2010 09:43PM
Take a look at the source code for FMyLife, as I use MLlib under a C++ type environment. I may have had to modify some of the headers in order to properly compile it as C++, I don't exactly remember.
Re: Solid sprites
March 19, 2010 12:43AM
GuitarsOnFire is a strange mix of C and C++ code: [wiibrew.org]

From the machine perspective there is no difference in C or C++, all the magic is in the compiler. And in our case, GCC just as happily uses C as C++
Sorry, only registered users may post in this forum.

Click here to login