Haunted House

Origo is a funnyface (0,0)

Soya-tastic!

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[0] == soya.sdlconst.JOYAXISMOTION:
						
		if   event[1] == 1: self.speed.z = event[2] / 160000.0	# Up/Down
		elif event[1] == 4: self.rotation_y_speed = -event[2] / 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[0] == soya.sdlconst.JOYBUTTONDOWN and event[1] == 16:
		soya.MAIN_LOOP.stop()

	elif event[0] == soya.sdlconst.KEYDOWN:
		if event[1] == soya.sdlconst.K_q:      soya.MAIN_LOOP.stop()
		elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop()
				

	elif event[0] == 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.

Simple, huh?

(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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: