Posts Tagged pygame

Game Design: Galcon

Like furniture from IKEA, much of the beauty of Galcon comes from its simplicity.  But like all good games, there are layers of depth beneath the surface.

Galcon

Galcon

Galcon is a game of momentum similar to Risk in which the goal is to control the galaxy.  Players send fleets to nearby planets and use these planets to attack even more planets.  The flow of the game is naturally exciting and can be understood by anyone within a few minutes of picking up the game.

In addition to his work on Galcon, the developer Phil Hassey has contributed enormously to the Pygame community.   One of the projects he wrote that I use all the time is PGU (Mr. Frog vs. OSIRIS, LORD OF THE UNDERWORLD uses it for its GUI).  Its great that there are developers out there who not only make fun games but also contribute to the open source movement.

Tags: , ,

Summer Projects

I’ve got some spare time this summer so I’ve decided to get some work done on a few projects:

  • I programmed my first iPhone game (a Breakout clone), following along with the tutorials in this book.  XCode is powerful, but the learning curve isn’t as bad as I first thought.  Everything in the IDE is really polished, which I guess is what I should expect from Apple.  Soon I’ll port Adrift over to the iPhone and hopefully launch it in the iTunes App store.  More on that in the coming weeks.
  • I want to do some kind of C++ puzzle game – probably something multiplayer but with simple graphics.
  • I’m going to put together a package for special effects in Pygame – as well as try and put together a complete, purely Pythonic, physics / lighting engine.  If possible I’d like to showcase all of these in some sort of simple game.

Since I’m heading to graduate school in August, I’ve decided to brush up on my reading too.  High on the list are Introduction to Algorithms and Computational Geometry.  Game programming is half art and half science, so it pays to refresh your math skills every so often and learn new techniques.

Tags: , , ,

Rapid Development

Work is continuing at a nice, rapid pace on my submissions for Indiecade and PAX.  I have a workable demo now and have been doing playtesting.

None of which would be possible if I wasn’t using Pygame.  When working with Pygame, I literally have something to tweak within 24 hours of starting on a project – something that is invaluable in checking to see if an idea is good or not.  You’re never really sure until you start playing.

In addition to Pygame, I’m also using a module called PGU.  PGU, among other things, takes a lot of the grunt work out of building graphical user interfaces and hooking them up into your game.  For game competitions, polish counts enormously and using existing code bases will help me achieve that.

Tags: , ,

Adrift v1.0 Released!

Adrift

Adrift

I’m very excited to announce that today I am releasing my puzzle game Adrift!  Click here for more information.  I’ve had a blast designing this game and I hope you all enjoy it.  Contact me if you have any questions or find any bugs.  So far I’ve tested it on Macintosh and Windows.

You can find the Pygame project page here.

Tags: ,

Adrift v0.1 Release!

Adrift is ready for testing!

Adrift v0.1

Adrift v0.1

Adrift is a puzzle game where your goal is to guide a lost ship home by controlling the wind.  Of course, there are numerous obstacles such as pirates blocking your path.  Note that this is a “beta” release and there are probably still bugs left to find.

Download it here.  It should run on any Windows system:  just double click AdriftDriver.exe to start it up.  If you’re interested, the Python source code can be found here.

Tags: ,

Algorithm: Lightning

Another simple graphical trick you can play with in games is lightning.  One algorithm for this is to draw a white square over the entire bounds of the screen for a very short time.  The following code can be used to flash every second:

#Lightning.py
#Flash of lightning visual effect.

import pygame

from engine.AtlanSprite import AtlanSprite

class Lightning(AtlanSprite):

“”"
AtlanSprite is one of my game engine classes.
Replace this with your own basic sprite class.
“”"

def __init__(self, m):

“”"
Constructor – set up the counter variable and bounds.
m = whatever container class you are using
“”"
AtlanSprite.__init__(self)
#make the bounds however large your screen size is
self.bounds = pygame.Rect(0, 0, 800, 600)
self.master = m
self.counter = 0
self.flashing = False

def draw(self, surface):

“”"
Called from the main game loop every frame.
Draw a white square when the lightning is flashing.
“”"

if self.flashing:

#see pygame.org’s documentation on the surface.fill() method
surface.fill((255, 255, 255), self.bounds)

def update(self, time):

“”"
Should be called every game frame with the time that has ellapsed.
time = time elapsed in milliseconds

“”"

self.counter = self.counter + time
#flash every second

if self.counter >= 1000:

if not self.flashing:

self.flashing = True

#only flash for 50 milliseconds

if self.counter >= 1050:

self.flashing = False
self.counter = 0

This works best if you have a thunder sound effect to go with it.  The reason it works is that the square is drawn so quickly that the human eye can’t really tell what is going on.  All you see is everything get brighter so it looks like lightning flashed.  Note that you’ll probably want to draw the lightning last in your list of sprites so that it doesn’t get covered up by anything else.

Tags: , , ,

Algorithm: Procedural Clouds

Lately, I’ve been working on a game idea where you guide a sailboat through dangerous waters by controlling the wind.  It’s not quite ready for primetime just yet, but today I wanted to share a code snippet for the procedural generation of 2D clouds that I’m using in it.

Clouds

Clouds

Designing games is a lot like being a magician:  you provide illusions for other people’s entertainment.  You want your player to think that a collection of pixels on a screen is really a cloud.  What do clouds look like in real life?  They are white, fluffy, semi-transparent, and each one looks unique.  To pull off the magic trick, you need an algorithm to produce objects that satisfy all of these conditions.

You also want to do it in a way that is easy on their processor.  My solution is to create a surface and draw a lot of small circles on it in pseudorandom positions.  It seems to work pretty well.  Below is the Python code for the algorithm (using the Pygame module):

#uses the random and pygame modules

#build the cloud at location 100, 100.  Note that for a game you’d probably want to randomize its location

bounds = pygame.Rect(100, 100, random.randint(50, 300), random.randint(50, 300))

#create a surface with an alpha channel

cloudSurface = pygame.Surface((bounds.width, bounds.height), flags=pygame.SRCALPHA).convert_alpha()

#drawing to locked surfaces is more efficient

cloudSurface.lock()

center = (bounds.x + (bounds.width / 2), bounds.y + (bounds.height / 2))

#little bit of black magic here – I found out how many circles to draw through trial and error

#this value seems to work reasonably well

for i in xrange((bounds.width * bounds.height) / 200):

#draw circles randomly in 30% to 70% range of the rectangle

centerX = random.randint(int(bounds.width * 0.3), int(bounds.width * 0.7))

centerY = random.randint(int(bounds.height * 0.3), int(bounds.height * 0.7))

#circles should have a radius between 3 and 10

radius = random.randint(3, 10)

#draw the circle to the surface, make it halfway transparent and white

pygame.draw.circle(cloudSurface, (255, 255, 255, 128), (centerX, centerY), radius)

cloudSurface.unlock()

Now that you’ve created the surface, blit it in your draw loop.  If you’re not satisfied with the clouds this algorithm draws, mess with the constants I’ve used a little.  Try changing the size of the circles drawn, how many are drawn, and in what range of the rectangle they are drawn.

Tags: , , ,