Posted by Gasten on January 1, 2008
After discovering Fluxus, I’ve become more and more interested in 3D-graphics, been takin’ Blender for a spin and so on. This comes as quiet a surprise for me, since I’ve always thought that 3D was way hard (3 dimensions?! I’m struggling with only two!), and to use it, you had to implement garbage collection in C. Not my cup of tea, no.
Very well, I had some ideas that I wanted to try out that would be a bit inconvenient to do in Fluxus (bigger games), so I started to look for tools that could help me do what I wanted in Python, which is one of the only languages I feel really comfortable with, even if my biggest problem is that I haven’t worked with enough libraries yet.
After looking at python-wrappers for C-libraries like PyOpenGL and PyOGRE I found out about Soya. Absolutely amazing. I mean, Man…
You can do a simple 3d game in less than 300 lines of code. You can probably do a fun game in under 1 000. And when your project hits 10 000 lines, it still won’t feels scrambled and obfuscated (I believe – haven’t tried).
For those who think PyGame is easy – try soya. it’s way less difficult and focuses much less on boring things like micro management and rendering (It’s true!).
I took 15 minutes of my time to mod the “basic-5.py” tutorial to use my game controller instead of the keyboard. I really love my gamepad. The only thing I’m annoyed about is the lack of joystick standardness. Every application have to recreate some kind of joystick reconfiguration.
Oh well, I changed CaterpillarHead.begin_round() to:
for event in soya.process_event(): # Check for joystick axis events. if event == soya.sdlconst.JOYAXISMOTION: if event == 1: self.speed.z = event / 160000.0 # Up/Down elif event == 4: self.rotation_y_speed = -event / 6000.0 # Left/right # Pressing the escape or 'q' key will exit the main_loop mainloop, and thus terminate # the program. soya.MAIN_LOOP.stop() is the right way to end your application, and # causes the MainLoop.main_loop() method to return. elif event == soya.sdlconst.JOYBUTTONDOWN and event == 16: soya.MAIN_LOOP.stop() elif event == soya.sdlconst.KEYDOWN: if event == soya.sdlconst.K_q: soya.MAIN_LOOP.stop() elif event == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop() elif event == soya.sdlconst.QUIT: soya.MAIN_LOOP.stop() # Do the rotation. self.rotate_y(self.rotation_y_speed)
By the way, round_begin() is the function that’s called on each tick, like a control rate for those who are into synth-development. There is also an advance_time() function which is called each frame.
(also, I’m not very proud of this implementation – in a real project I’ll process the joystick-value to have it in the range of -1 – 1, and not -30 000 something to 30 000 something. And I’ll make it less sensitive so whatever is controlled wont “nudge around” when an axis is on near-zero, but not zero-exact.