April 20, 2024, 04:09:56 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Earth Save

Started by GWS, January 29, 2010, 05:48:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi folks,

Here's a simple 2D game - more an exercise in sprite collision really - in which you control a 'plasma field' to stop the Earth falling out of space ..   :)

I thought it would be an easy exercise in collision detection and rebound, but it proved quite tricky.

Why? .. well consider a circular sprite and a rectangular sprite.

They are moving past each other, and make a sliding contact - that is, the angle of incidence is very small.

This means the collision detection command will make multiple reports of contact, until the two sprites have passed each other.  In fact I found it made so many reports, I think the program encountered some kind of limit, and crashed with the usual 'Want to Report this to Microsoft' dialog.

I think this will be a problem in any language.  It's OK if collision results in an explosion, thus removing one sprite, but if you require a rebound, things are not so simple.

I had to insert a number of logic tests in this example, to ensure that the collision test only takes place if the plasma field sprite is more or less directly under the Earth sprite.

A glancing contact on the Earth circumference will not be tested, and so no rebound occurs.  Aim to get the plasma beneath the Earth using the arrow keys.

There's also another little snag with rebounding sprites.
If you don't include a bit of control logic, you will see an effect of, in this case, the Earth sprite, bouncing along the Plasma sprite .. 

It's an effect which also occurs in electronics.  When a switch closes, there are rapid on/off bounces for a short time until the switch finally settles to closed.  In fact the effect also occurs when you open a switch.

In the case of sprite collision, the collision is detected - the sprite direction reverses - but the distance travelled in the new direction is insufficient to prevent a new collision being detected - and so the sprite reverses again -- and so on.  You see a juddering instead of a clean bounce.

To prevent this, I included a statement that requires the Earth sprite to be moving down the screen before a collision test is made.  This is sufficient to make sure the sprite moves a short distance away from the initial collision point and avoids the bouncing effect.     

Anyway, it's a bit of fun, and you might want to play with the logic tests to get the gameplay more to your liking .. I hope I've got the game timing OK.

I've included the .exe file ..

all the best,  :)

Graham

Tomorrow may be too late ..

metalfoot

Graham,

Just wanted to thank you for taking over CreativeBasic. I'm looking forward to learning/using it! Also, thanks for this game.
-Alex

GWS

You're welcome Alex .. I hope you enjoy using Creative as much as I have.

It's pretty unique, and very versatile.  You'll find it suitable for many applications, and it's a pleasure to use.

all the best, :)

Graham
Tomorrow may be too late ..