Learning Python and OpenGL
In an effort to get back into doing more creative stuff, I've decided to start learning Python and OpenGL in order to get back into doing some game programming. It's probably been over fifteen years since I've written a complete computer game. I ought to go digging through my archives and see if I can find any of them.
Anyway... Python's pretty cool. It's an interpreted language so you'll lose a bit on performance, but it makes it very easy to test your code. It seems to take the best of lots of languages like Perl and C (and other) and does a lot of stuff automatically for you that you'd normally have to do manually in other languages. It's also got a lot of nice, powerful built in routines and add-ons that make it really nice for game coding.
There's also an OpenGL binding called pyOpenGL. And I'm using pyGame which is a set of Python modules with binding to the SDL Library.
It was actually an article on GameDev called How To Build a Game In A Week From Scratch With No Budget that got me interested in Python. In the article, a seasoned game programmed uses these tools to create a playable RPG game called hackenslash. It's a very good article and I highly recommend it for anyone who does any time of program development under a tight schedule or budget.
On to my game...
I decided I wanted to do something along the lines of Risk or Slay. I wanted it to be on a hex grid and I wanted it to be projected into 3D space. I considered doing an isometric view but really wanted to actually model it in 3D and let the user change their viewing angles, zoom, etc. I also really wanted to learn OpenGL. :-).
My first task was to get a hex grid to display in 3D. That was actually pretty easy. I created a simple routine to build a single hex mathmatically. Yes, I know I could have done all these calcs myself and just hard coded the numbers, but I wanted to make the routine flexible in case I wanted to change the scale of the hexes later.
You can take a look at the source code for this here: TW_03.py
All this code will do is draw a hex map in 3D space and let you maneuver the camera around to look at it from different angles. You can use the arrow keys to scan across the map. Use the Q and Z keys to zoom in and out. Use the W and S keys to raise or lower your viewing angle. The A and D keys to rotate left and right around your focus point. The R key will reset your view in case you get lost and the ESC key will exit the program.
This little test program exhibits more camera control than the final game would have, but I wanted to experiment with this pretty extensively so I decided to make the camera completely controllable.
The next stage will be to lock the camera at a preset angle and make the map clickable. Then, when the map is clicked, the camera will move in a controlled fashion to focus on the new area.
I'll post additional updates and I make progress.
0 Comments:
Post a Comment
<< Home