Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rocket simulation game with just using tkinter

245 views
Skip to first unread message

Irmen de Jong

unread,
Sep 30, 2016, 6:59:28 PM9/30/16
to
Hi,

I've made a very simple rocket simulation game, inspired by the recent success of SpaceX
where they managed to land the Falcon-9 rocket back on a platform.

I was curious if you can make a simple graphics animation game with just using Tkinter,
instead of using other game libraries such as PyGame.
As it turns out, that works pretty well and it was quite easy to write. Granted, there's
not much going on on the screen, but still the game runs very smoothly and I think it is
fun for a little while where you try to learn to control the rocket and attempt to
successfully land it on the other launchpad!

The physics simulation is tied to the game's frame rate boohoo, but the upside is that
you can change the framerate to control the game's difficulty. It's easy at <=20, fun at
30 and impossible at 60 :) It's running on 30 by default.


You can get the code here if you want to give it a try:
https://github.com/irmen/rocketsimulator

So you just need python 2/3 with tkinter to play this!


Have fun
Irmen

Sayth Renshaw

unread,
Oct 1, 2016, 4:55:54 AM10/1/16
to
Well done. An interesting listen that might be up your alley, how-i-built-an-entire-game-and-toolchain-100-in-python on talkpython

https://talkpython.fm/episodes/show/78/how-i-built-an-entire-game-and-toolchain-100-in-python

Sayth

Christian Gollwitzer

unread,
Oct 1, 2016, 9:44:29 AM10/1/16
to
Am 01.10.16 um 00:59 schrieb Irmen de Jong:
> Hi,
>
> I've made a very simple rocket simulation game, inspired by the recent success of SpaceX

> You can get the code here if you want to give it a try:
> https://github.com/irmen/rocketsimulator

Nice! I'll have to rebind the keys before I can successfully play this,
though. My [] "keys" are in fact combinations of Alt+5 and Alt+6 on a
German Macbook keyboard (on a German PC, it is AltGr+8, AltGr+9). Why
not using the arrow keys? These should be pretty universal

Christian

Irmen de Jong

unread,
Oct 1, 2016, 4:07:25 PM10/1/16
to
On 1-10-2016 15:44, Christian Gollwitzer wrote:
> Am 01.10.16 um 00:59 schrieb Irmen de Jong:
>> Hi,
>>
>> I've made a very simple rocket simulation game, inspired by the recent success of SpaceX
>
>> You can get the code here if you want to give it a try:
>> https://github.com/irmen/rocketsimulator
>
> Nice! I'll have to rebind the keys before I can successfully play this, though. My []
> "keys" are in fact combinations of Alt+5 and Alt+6 on a German Macbook keyboard (on a
> German PC, it is AltGr+8, AltGr+9). Why not using the arrow keys? These should be pretty
> universal

Oh, I'm sorry about that, my little knowledge of non-US keyboard layouts shows.
Arrow keys could be an option. For my education what are the 2 keys to the right of
the P then on your keyboard?

Rebinding the keys should be easy though just change them in the keypress and keyrelease
methods.

Irmen

Irmen de Jong

unread,
Oct 2, 2016, 8:47:19 AM10/2/16
to
I've updated the keybindings and you can now use [ and ] but also the cursor keys to
control the rocket's rotation.

Also I've discovered that there seems to be an issue with some Tkinter versions; it
sometimes doesn't update the screen fast enough. On OSX this problem is not present but
it is on Python 2.7 on Windows for example. I don't know what is causing it or how to
fix it at this time. The FPS counter in the top right of the window should say 30,
that is when the game is updating at the intended speed.


Irmen

Christian Gollwitzer

unread,
Oct 4, 2016, 4:20:25 AM10/4/16
to
Am 02.10.16 um 14:46 schrieb Irmen de Jong:
> On 1-10-2016 22:07, Irmen de Jong wrote:
>> Oh, I'm sorry about that, my little knowledge of non-US keyboard layouts shows.
>> Arrow keys could be an option. For my education what are the 2 keys to the right of
>> the P then on your keyboard?
>>
>> Rebinding the keys should be easy though just change them in the keypress and keyrelease
>> methods.
>
> I've updated the keybindings and you can now use [ and ] but also the cursor keys to
> control the rocket's rotation.

Thanks! It works now with the cursor keys as intended. I'm still having
trouble, but only because my game playing skills are not very good ;)

> Also I've discovered that there seems to be an issue with some Tkinter versions; it
> sometimes doesn't update the screen fast enough. On OSX this problem is not present but
> it is on Python 2.7 on Windows for example. I don't know what is causing it or how to
> fix it at this time. The FPS counter in the top right of the window should say 30,
> that is when the game is updating at the intended speed.

Maybe if the system is simply too slow for your intended speed ? I see
that you are using after_idle if the delay is less than 1 ms. after_idle
performs a different task than after. I think, instead you should skip
frames, i.e. compute how many frames you are behind the clock and
advance the physics by that and draw the next frame instead. Otherwise
the delay might build up.

The drawing itself has also different speed on different system. And,
the canvas is not intended to redraw everything on each frame. Instead,
updating the objects using the coords() method is usually faster. (It
should also be easier)

Christian

>
>
> Irmen
>

Irmen de Jong

unread,
Oct 4, 2016, 2:44:02 PM10/4/16
to
On 4-10-2016 10:20, Christian Gollwitzer wrote:

> Thanks! It works now with the cursor keys as intended. I'm still having trouble, but
> only because my game playing skills are not very good ;)

Have you managed to land the rocket again at all after a takeoff?
You can practice landing a bit by touching down anywhere on the ground, for instance
just a little bit to the right of the starting launchpad.
The real challenge is of course to land it on the other launchpad without touchdowns in
between.


>> Also I've discovered that there seems to be an issue with some Tkinter versions; it
>> sometimes doesn't update the screen fast enough. On OSX this problem is not present but
>> it is on Python 2.7 on Windows for example. I don't know what is causing it or how to
>> fix it at this time. The FPS counter in the top right of the window should say 30,
>> that is when the game is updating at the intended speed.
>
> Maybe if the system is simply too slow for your intended speed ?

Python 2.7 on my windows box shows the slow update behavior, while Python 3.5 on the
same windows box runs fine at 30 fps (or even 60 if you tell it to).
I concluded that it is an implementation problem.

> I see that you are
> using after_idle if the delay is less than 1 ms. after_idle performs a different task
> than after. I think, instead you should skip frames, i.e. compute how many frames you
> are behind the clock and advance the physics by that and draw the next frame instead.
> Otherwise the delay might build up.

Yes you're right but the computer is not too slow I believe, see above.

> The drawing itself has also different speed on different system. And, the canvas is not
> intended to redraw everything on each frame. Instead, updating the objects using the
> coords() method is usually faster. (It should also be easier)

I didn't want to tie it too much to the implementation details of Tkinter canvases.
Usually I think games have some graphics area that has to be redrawn every frame.
That, and Tkinter canvas cannot rotate a polygon so I have to redraw the rocket anyway!

Thanks for your interest in this little game :)
Irmen

Irmen de Jong

unread,
Oct 5, 2016, 3:40:36 PM10/5/16
to
On 5-10-2016 2:43, Dennis Lee Bieber wrote:
> Or do what I once did with the Lunar Lander game on my college
> computer... Target accuracy: Excellent... Landing gear? somewhere on the
> other side of the moon. My vertical velocity was sub-inches per second --
> the horizontal velocity was in multi-feet per second.

My lander game takes the magnitude of the velocity into account and not the direction,
so you will still crash when going down a pixel per second but strafing like mad :)


> I also used to crash with more fuel than I started with... Game didn't
> do a sign check on "lbs of fuel to burn", so -10lbs @ 180deg had the same
> effect as 10lbs @ 0deg, but gained fuel.

I forgot to add a fuel gauge! My rocket can fly for all eternity if you manage to keep
it in the air :P

The first rocket landing game I ever came across must have been a text only version
running on my commodore 64 where it was only printing your current altitude and velocity
and fuel level, and then stopped to ask for input. I think it asked for values for how
long to burn the engine and for how many seconds. Then it recomputed everything and
stopped again for input until you landed safely or crashed...
It must have been a short BASIC listing I copied over from a magazine or something.


Irmen

0 new messages