#### Archived

This topic is now archived and is closed to further replies.

This topic is 5825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
A few things.

1. You shouldn''t be creating and destroying threads in the middle of your game. Thread creation/destruction are expensive even in the non-VM world, so if you really need a separate thread (and in this case, I would think about whether you really need the new thread or not - it sounds to me like you don''t) then I would create it at the start of the level and leave it running.

2. The generally accepted way of stopping garbage collection in the middle of your run, is to not allocate any new memory. Use object pools, pre-allocate as much as you can, and just avoid new as much as possible.

3. Gravity is a funny thing. If you want to use the "proper" Newtonian equation, it''s something like:

    GmMF = ---    r2

So, G is the gravitation contsant, and is generally a very small number (Work out the best constant for your game depending on your units and the relative scale of things). m is the mass of object 1 (usually the smaller object), M is the mass of the other object (usually the planet or whatever and r is the distance between the two objects centre of mass.

To get from F to a (acceleration), you use Newton''s second (I think?) law F=ma, or a = /m. When you substitute this formula into the one above, you get:

    GMa = --    r2

So you can see that acceleration only depends on the mass of the other object. Anyway, you go from acceleration to velocity by using v += a/FPS each frame.

And there you go! Realistic gravitation!

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

##### Share on other sites
I must say, I like it Only one problem that I could see. Nullpointer when selecting map03. Smooth gameplay with Sun´s 1.4.1 JVM, win9x, 1GhZ.

##### Share on other sites
Thanks for the feedback. Nice that you liked it Aenimal

Yeah, think you''re right at the thread thing. At the start of every map i anyway start a timing thread, which could probably be used for timing the item effects and short text displays. Just got to make up a smart way to follow stuff. Like when you eat a mushroom, and take another one a little later, it should restart the effect

I''ve already tried to get rid of instantiating new objects while running the game, but somehow i seemed to forget about the threads. Or thought i really needed more of them. Think it will do much already if i get rid of the ones not really needed.

Now i''m still wondering about the random thing. The case is like:

new Map():
Math.random() when a random item picked returns 0.75 for example.
Math.random() on another random item returns: 0.2315.

Then, if you take the 1st random item again, the Math.random() returns the same value. Same thing with the 2nd one. But if you create a new instance of the Map, you get different values for that instance again. Just to make it clear.. Any ideas?

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011471
• ### Who's Online (See full list)

There are no registered users currently online

×