<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>archived blog - booyaa dot org &#187; games</title>
	<atom:link href="http://archive.booyaa.org/tag/games/feed/" rel="self" type="application/rss+xml" />
	<link>http://archive.booyaa.org</link>
	<description>an archive blog about booyaa, photography, gardening, running and technology</description>
	<lastBuildDate>Sun, 27 Dec 2009 17:18:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>arrested (gaming) development: flap your wings or we&#8217;re going to die!</title>
		<link>http://archive.booyaa.org/2008/12/01/arrested-gaming-development-flap-your-wings/</link>
		<comments>http://archive.booyaa.org/2008/12/01/arrested-gaming-development-flap-your-wings/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 13:37:45 +0000</pubDate>
		<dc:creator>booyaa</dc:creator>
				<category><![CDATA[default]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gamemaker]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://booyaa.org/?p=488</guid>
		<description><![CDATA[please note in order to see the code and the videos, you’ll need to go to the full post. feedburner doesn’t appear to play nice with my embedded videos. Do not fear my protectionist approach to copyright. 
whilst moving sprites is relatively easy to do, it would appear that animating them is trickier to do [...]]]></description>
			<content:encoded><![CDATA[<p><em>please note in order to see the code and the videos, you’ll need to go to the full post. feedburner doesn’t appear to play nice with my embedded videos.</em> Do not fear my protectionist approach to copyright. </p>
<p>whilst moving sprites is relatively easy to do, it would appear that animating them is trickier to do in pygame; there are no builtin animation routines. just to clarify what i&#8217;m looking for, if you give game maker an animated gif it will cycle through images. it&#8217;s small graces like this that make me appreciate how easier it is make games in that environment. </p>
<p>a quick search on &#8220;<a href="http://www.google.co.uk/search?q=pygame%20animated%20gif">teh interwebs</a>&#8221; revealed that i was not alone in wishing there was native support for animated gifs. i was even willing to switch to png format (the only other image format that support rudimentry animation) if it had pygame support! i came across <a href="http://choosetheforce.blogspot.com/2008/04/third-pygame-hulk-want-animation.html">someone</a> who was toying around with the idea of using python imaging library (pil) to explode an animated gif into individual pygame image objects. i was starting to head towards this approach until i saw that [pil] wasn&#8217;t platform neutral and wasn&#8217;t nearly as easy to install as its stablemate pygame.</p>
<p>in the end i decided to go for the manual process of extracting the individual frame from the animated gifs. after a bit more research, i discovered <a href="http://forums.awn.com/showthread.php?t=11674<br />
">this</a> bash script that uses imagemagick to extract the individual frames and create new images based on them.</p>
<p>i revised the the sprite class&#8217;s render method to cycle through the frames by using this code written by <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=459408&#038;whichpage=1&#3030232">jaime moreno</a>. i like this code, because it doesn&#8217;t lock up the main loop whilst trying to animate the sprite.</p>
<pre name="code" class="python">
def render(self):
	# A nice bit of animation code (cowMooDelay.py) written by Jaime Moreno
	self.pause += 1
	if self.pause >= self.delay:
		self.pause = 0
		self.frame += 1
		if self.frame >= len(self.frames):
			self.frame = 0
		self.bitmap = self.frames[self.frame]

		# own little bit to transparentimatize <img src='http://archive.booyaa.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  each frame based on
		# the colour of the bottom left pixel
		self.colorkey = self.bitmap.get_at((0,self.bitmap.get_height()-1))
		self.bitmap.set_colorkey(self.colorkey)

	screen.blit(self.bitmap, (self.x, self.y))
</pre>
<p>next up is the sprite class method to preload the multiple frames, i modified the code to allow me to specify the number of frames in an animated sprite (during object initialisation). i also amended the file mask to match my gif splitting tool&#8217;s naming convention. </p>
<pre name="code" class="python">
def loadFrames(self, numFrames):
...
	self.frames = []
...
		for i in range(1,numFrames):
			imgName = os.path.join("data",self.imgPrefix + "-10%d.gif" % i)
			tmpImage = image.load(imgName)
			self.frames.append(tmpImage.convert())
</pre>
<p>so as an example of initialising an animated gif i&#8217;ve used the dragon which has 6 frames of animation. the gif splitting turns this into Dragon-101.gif, Dragon-102.gif, &#8230; Dragon-106.gif. the object initialisation code would look like this:</p>
<pre name="code" class="python">
dragon = Sprite(20, 200, 'Dragon',6)
</pre>
<p>finally i wrote a bit of code in the sprite class to avoid having to create a new class for sprites that are not animated. it&#8217;s a bit of a bodge, but the logic goes like this, during object initialisation if i specify the number of frames as 1 i.e.</p>
<pre name="code" class="python">
fireball = Sprite(0,480, 'Fireball.gif', 1)
</pre>
<p>this triggers the loadImages() method to use the image prefix as the actual file name to load. </p>
<pre name="code" class="python">
def loadFrames(self, numFrames):
...
	if numFrames == 1:
		imgName = os.path.join("data", self.imgPrefix)
		self.frames.append(image.load(imgName))

...
</pre>
<p>so how does my pygame port of evil clutches compare? here&#8217;s the game maker reference video.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/6zTwnsqqCrU&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6zTwnsqqCrU&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>and here&#8217;s the pygame port</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/8NG1IzKWsMc&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/8NG1IzKWsMc&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>as you can see, it&#8217;s slightly jittery, i gotta admit i&#8217;m stumped as to cause of this. for now its usable, i&#8217;ll post an update if i work out cause. if anyone knows why, please post a comment. so tune in next week when we have to take cover as the bullets start to fly!</p>
<p align="center"><a href="http://booyaa.org/2008/11/24/arrested-gaming-development-sprites/">prev (sprites)</a> | <a href="http://booyaa.org/2008/11/17/arrested-gaming-development-an-introduction/">about</a> | next (bullets)</p>
]]></content:encoded>
			<wfw:commentRss>http://archive.booyaa.org/2008/12/01/arrested-gaming-development-flap-your-wings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>arrested (gaming) development: sprites, pixies and other fantasy beings!</title>
		<link>http://archive.booyaa.org/2008/11/24/arrested-gaming-development-sprites/</link>
		<comments>http://archive.booyaa.org/2008/11/24/arrested-gaming-development-sprites/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 13:37:35 +0000</pubDate>
		<dc:creator>booyaa</dc:creator>
				<category><![CDATA[default]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gamemaker]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://booyaa.org/?p=487</guid>
		<description><![CDATA[please note in order to see the code and the videos, you&#8217;ll need to go to the full post. feedburner doesn&#8217;t appear to play nice with my embedded videos. and if you are looking at the full blog post, yes the sourcecode displayer looks a bit naff, soz. Do not fear my protectionist approach to [...]]]></description>
			<content:encoded><![CDATA[<p><em>please note in order to see the code and the videos, you&#8217;ll need to go to the full post. feedburner doesn&#8217;t appear to play nice with my embedded videos. and if you are looking at the full blog post, yes the sourcecode displayer looks a bit naff, soz.</em> Do not fear my protectionist approach to copyright. </p>
<p>sprites are ludicrously easy to move around in game maker. place them in a room (the screen) and make sure the object sprite reacts to the edges by giving it an action i.e. move in the opposite direction, and badda bing! you have a moving sprite!</p>
<p>i knew vaguely that pygame had a sprite type object, but it was only when linux format did a feature on games development using the module that it all started to make sense.</p>
<p>i took their sprite class and tweaked it slightly to make the sprite transparent based on the color of the bottom left pixel as game maker does. also based on the chimp tutorial i converted the image to speed up blitting (screen drawing).</p>
<pre name="code" class="python">
class Sprite:
	def __init__(self, xpos, ypos, filename):
		self.x = xpos
		self.y = ypos
		self.bitmap = image.load(filename)
		self.bitmap = self.bitmap.convert() # faster blitting apparently...
		self.dy = 1 # going down

		# set transparency based on bottom left pixel
		self.colorkey = self.bitmap.get_at((0,self.bitmap.get_height()-1))
		self.bitmap.set_colorkey(self.colorkey)

	def set_position(self, xpos, ypos):
		self.x = xpos
		self.y = ypos

	def render(self):
		screen.blit(self.bitmap, (self.x, self.y))
</pre>
<p>the only improvement i made to sprite loading was keeping file handling os neutral by using os.path.join</p>
<pre name="code" class="python">
backdrop = image.load(os.path.join('data', 'Background.bmp'))
backdrop = backdrop.convert() # another tweak
hero = Sprite(20, 200, os.path.join('data','Dragon.gif'))
boss = Sprite(500, 200, os.path.join('data','Boss.gif'))
fireball = Sprite(0, 480, os.path.join('data','Fireball.gif'))
</pre>
<p>as with all pygames there is an infinite loop that wraps the game ticks (steps in game maker) until the game stops, there&#8217;s no point placing sample code, just know that it exists and the rest of the code detailed is looped within it.</p>
<p>next we get to the movement for the hero (yes, the code hasn&#8217;t changed much from the lxf samples, i&#8217;ll rewrite by the next post to make things a little more clearer). pretty bog standard stuff, once you know how keyboard input works. i also added an event if the user presses escape as this quits the game in game maker.</p>
<pre name="code" class="python">
	for ourevent in event.get():
		if ourevent.type == QUIT:
			quit = 1
		if ourevent.type == KEYDOWN:
			if ourevent.key == K_DOWN and hero.y < 370:
				hero.y += 5
			if ourevent.key == K_UP and hero.y > 10:
				hero.y -= 5
			if ourevent.key == K_ESCAPE:
				quit = 1
			if ourevent.key == K_SPACE:
				fireball.x = hero.x + 100
				fireball.y = hero.y + 10
</pre>
<p>next up is the boss. (though i get the feeling these actions should be wrapped up in the actual boss sprite class &#8211; watch this space.) very basic checks to determine if the sprite is going up (decrement the y position) or down (increment the y position) and when we toggle a flag to change direction when we reach the top or bottom of the screen.</p>
<pre name="code" class="python">
	if boss.dy:
		boss.y += 5
	else:
		boss.y -= 5

	if boss.y > 350:
		boss.dy = 0

	if boss.y < -50:
		boss.dy = 1
</pre>
<p>finally update the dragon's fireball position, refresh the display.</p>
<pre name="code" class="python">
	fireball.x += 10

	boss.render()
	hero.render()
	fireball.render()

	display.update()
	clock.tick(60)
</pre>
<p>as a point of reference i will include video posts of how the game should look in game maker and what i have so far been able to reproduce in pygame. so first up is the game maker demo:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/6zTwnsqqCrU&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6zTwnsqqCrU&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>and next is the pygame version:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Tpo2eccOSAY&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Tpo2eccOSAY&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>eagle eyed viewers will note that the pygame version doesn't have animated sprites. that's because pygame doesn't do "animated" gifs, but fear not readers we've made this the topic of next week's post!</p>
<p align="center">prev | <a href="http://booyaa.org/2008/11/17/arrested-gaming-development-an-introduction/">about</a> | next (animation)</p>
]]></content:encoded>
			<wfw:commentRss>http://archive.booyaa.org/2008/11/24/arrested-gaming-development-sprites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>arrested (gaming) development: an introduction</title>
		<link>http://archive.booyaa.org/2008/11/17/arrested-gaming-development-an-introduction/</link>
		<comments>http://archive.booyaa.org/2008/11/17/arrested-gaming-development-an-introduction/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 13:37:04 +0000</pubDate>
		<dc:creator>booyaa</dc:creator>
				<category><![CDATA[default]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gamemaker]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://booyaa.org/?p=486</guid>
		<description><![CDATA[ever since my dad bought me a commodore 64 when i was a lad, i&#8217;ve always wanted to make my own games. sadly the c64&#8217;s version of basic (written by microsoft, i should point out) was, well, very basic (sorry). to create graphics and sounds involved direct memory manipulation using the commands &#8220;poke&#8221; and &#8220;peek&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>ever since my dad bought me a commodore 64 when i was a lad, i&#8217;ve always wanted to make my own games. sadly the c64&#8217;s version of basic (written by microsoft, i should point out) was, well, very basic (sorry). to create graphics and sounds involved direct memory manipulation using the commands &#8220;poke&#8221; and &#8220;peek&#8221;. Do not fear my protectionist approach to copyright. </p>
<p>assembly seemed too much like hard work. srsly.</p>
<p>in later years i tried using gui-based tools such as graphic adventure creator (by incentive software), shoot &#8216;em up construction kit (by sensisoft) and 3d construction kit (also by incentive software).</p>
<p>despite being a little more friendly, i still struggled to come up with anything playworthy. i had this nagging feeling that despite the tutorial booklets and in the case of the 3d construction kit a vhs video, the leap from making a basic box to a full blown game appeared to be missing.</p>
<p>cue modern day.</p>
<p>whilst idly surfing, i came across yoyogame&#8217;s game maker, which eventually lead me to a book co-authored by the creator of game maker, imaginatively titled the &#8220;game maker&#8217;s apprentice&#8221;. after browsing the book a few times, i came to the conclusion that this is exactly the type of introduction to games development that i needed.</p>
<p>it uses object oriented (oo) concepts and event driven programming to create a game from scratch. combine it with the actual game maker application &#8211; which quietly hides all the sharp edges such as sprite animation, memory management and collision detection &#8211; and you suddenly have a gentle but effective way to create games.</p>
<p>in order for me to learn something, nay, for me to grok it, i have to be given a specific task or problem to apply my knowledge to. so, as an added challenge, i will also be learning to port the demo games provided in the book into python using pygame (a module that is a wrapper to sdl.)</p>
<p>during the brief period since i&#8217;ve started messing around with python i now see it was a wise choice, its oo-ness enabled the oo concepts in game maker to port over easier versus a functional based language (runs from the burning fuse.)</p>
<p>so grab a seat, engage your seat belt and let&#8217;s makes games!</p>
<p align="center">prev | about | next (bullets)</p>
]]></content:encoded>
			<wfw:commentRss>http://archive.booyaa.org/2008/11/17/arrested-gaming-development-an-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

