<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Game Programming at scriptedfun &#187; arinoid</title>
	<atom:link href="http://www.scriptedfun.com/category/arinoid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptedfun.com</link>
	<description>Game Programming for Beginners: Video Tutorials, Source Code, and Articles</description>
	<lastBuildDate>Thu, 11 Sep 2008 17:45:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
		<item>
		<title>Arinoid with Sound</title>
		<link>http://www.scriptedfun.com/arinoid-with-sound/</link>
		<comments>http://www.scriptedfun.com/arinoid-with-sound/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:08:44 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[pygame]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/arinoid-with-sound/</guid>
		<description><![CDATA[Arinoid now has sound! I think that sound plays a very important role in the overall game experience, and I hope that you will all like this minor update.
Download Arinoid with Sound. Requires Python and Pygame.
The sounds were taken from Flashkit, which I think is a fantastic resource for game developers looking for free sound [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scriptedfun.com/arinoid-an-arkanoid-clone/">Arinoid</a> now has sound! I think that sound plays a very important role in the overall game experience, and I hope that you will all like this minor update.</p>
<p><a href="http://www.scriptedfun.com/wp-content/uploads/2006/08/arinoidv2.zip">Download Arinoid with Sound</a>. Requires <a href="http://www.python.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.python.org');">Python</a> and <a href="http://www.pygame.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.pygame.org');">Pygame</a>.</p>
<p>The sounds were taken from <a href="http://www.flashkit.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.flashkit.com');">Flashkit</a>, which I think is a fantastic resource for game developers looking for <a href="http://www.flashkit.com/soundfx/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.flashkit.com');">free sound effects</a> and <a href="http://www.flashkit.com/loops/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.flashkit.com');">free sound loops for background music</a>. There are many sound samples to choose from, and they are neatly categorized to make browsing easier. What makes browsing the sound collection fun is the site&#8217;s use of preview consoles, which allows the user to play sound samples on the page, with matching visualization. Once you find what you want, you may download the sound sample as an MP3 or as a WAV, which may be used immediately in your game, or edited using an audio editor like the highly-recommended <a href="http://audacity.sourceforge.net/" onclick="javascript:pageTracker._trackPageview ('/outbound/audacity.sourceforge.net');">Audacity</a>.</p>
<p>Picking sounds for this project was a very interesting activity &#8211; there were so many sounds to choose from! I hope that my choices were okay <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>I would really appreciate it, and I&#8217;m sure everyone would, if you know of a resource which can help game developers add sound to their games easily, just like <a href="http://www.flashkit.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.flashkit.com');">Flashkit</a>, and share it with us! <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Just leave a comment if you have something in mind. I suppose that these types of resources will be particularly useful for those who plan to join <a href="http://www.pyweek.org/3/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.pyweek.org');">PyWeek 3</a> <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Thanks in advance!</p>
<p><!--adsense#admedrect--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/arinoid-with-sound/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Video Tutorial 4 &#8211; Arinoid &#8211; Ball Physics</title>
		<link>http://www.scriptedfun.com/video-tutorial-4-arinoid-ball-physics/</link>
		<comments>http://www.scriptedfun.com/video-tutorial-4-arinoid-ball-physics/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:07:20 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[screencasts]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/video-tutorial-4-arinoid-ball-physics/</guid>
		<description><![CDATA[
At last, video tutorial 4 is here! I would like to apologize for the terrible delay, and thank you so much for your patience!  
You may notice some mistakes in the screenshots though &#8211; in particular when the code that converts between integers and floating point numbers is displayed. The highlighted code is correct, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.scriptedfun.com/wp-content/uploads/2006/08/screencast04.gif" alt="arkanoid clone ball physics" /></p>
<p>At last, video tutorial 4 is here! I would like to apologize for the terrible delay, and thank you so much for your patience! <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You may notice some mistakes in the screenshots though &#8211; in particular when the code that converts between integers and floating point numbers is displayed. The highlighted code is correct, but the way that it appears in the following slides (without the float and int conversions) is incorrect.</p>
<p>The transcript for this will be available shortly, and the fifth video tutorial is in the works. Thank you so much, especially to all those who have left comments of encouragement! They really keep me going <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I hope you find these helpful!</p>
<p><span id="more-35"></span></p>
<p><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="646" HEIGHT="521" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"><br />
<PARAM NAME=movie VALUE="screencast04.swf"><br />
<PARAM NAME=play VALUE=true><br />
<PARAM NAME=loop VALUE=false><br />
<PARAM NAME=quality VALUE=low><br />
<EMBED SRC="http://www.scriptedfun.com/screencasts/screencast04.swf" WIDTH=646 HEIGHT=521 quality=low loop=false TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><br />
</EMBED><br />
</OBJECT></p>
<p><a href="http://www.scriptedfun.com/wp-content/uploads/2006/08/screencast04.txt">Source Code for Video Tutorial 4</a></p>
<p><!--adsense#admedrect--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/video-tutorial-4-arinoid-ball-physics/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Transcript 3 &#8211; Arinoid &#8211; The Paddle</title>
		<link>http://www.scriptedfun.com/transcript-3-arinoid-the-paddle/</link>
		<comments>http://www.scriptedfun.com/transcript-3-arinoid-the-paddle/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:06:39 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[transcripts]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/?p=29</guid>
		<description><![CDATA[Hello and welcome to scriptedfun.com screencast number 3. Today, we will continue building our game Arinoid by adding a paddle. We will use the paddle to deflect the ball, and we want to be able to control it using the mouse.

The paddle image is contained in our sprite sheet. However, the image spans two tiles, [...]]]></description>
			<content:encoded><![CDATA[<p>Hello and welcome to scriptedfun.com screencast number 3. Today, we will continue building our game Arinoid by adding a paddle. We will use the paddle to deflect the ball, and we want to be able to control it using the mouse.</p>
<p><img alt="paddle image in the sprite sheet" src="http://www.scriptedfun.com/wp-content/uploads/2006/06/paddle.gif" /></p>
<p>The paddle image is contained in our sprite sheet. However, the image spans two tiles, which means that we cannot just extract the paddle image from the sprite sheet and use it as is. We have to get rid of the boundary at the middle. We can do this by extracting the left and right halfs of the paddle image, and joining them together. We will do these things without resorting to manual image editing. Since we want to be able to use the sprite sheet without manually editing it, we will do all the image manipulations within our program.<br />
<!--adsense#admedrect--><br />
<span id="more-29"></span><br />
<img alt="left half of paddle" src="http://www.scriptedfun.com/wp-content/uploads/2006/06/paddleleft.gif" /></p>
<p>The first thing that we have to do is get the numbers needed to extract the left half of the paddle. We will pass these numbers to spritesheet.imgat, which will extract the image for us.</p>
<p><img alt="right half of paddle" src="http://www.scriptedfun.com/wp-content/uploads/2006/06/paddleright.gif" /></p>
<p>We also have to get the numbers for the right side of the paddle.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">def</span> paddleimage<span class="br0">&#40;</span>spritesheet<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; paddle = pygame.<span class="me1">Surface</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">55</span>, <span class="nu0">11</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">convert</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="co1"># left half</span><br />
&nbsp; &nbsp; paddle.<span class="me1">blit</span><span class="br0">&#40;</span>spritesheet.<span class="me1">imgat</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">261</span>, <span class="nu0">143</span>, <span class="nu0">27</span>, <span class="nu0">11</span><span class="br0">&#41;</span><span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="co1"># right half</span><br />
&nbsp; &nbsp; paddle.<span class="me1">blit</span><span class="br0">&#40;</span>spritesheet.<span class="me1">imgat</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">289</span>, <span class="nu0">143</span>, <span class="nu0">28</span>, <span class="nu0">11</span><span class="br0">&#41;</span><span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="nu0">27</span>, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; paddle.<span class="me1">set_colorkey</span><span class="br0">&#40;</span>paddle.<span class="me1">get_at</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>, RLEACCEL<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> paddle</div>
</div>
<p><!--adsense-->Let us write a function that will produce the paddle image. The first step is to define a surface on which we will have the finished product, the paddle. Our surface is 11 pixels in height, corresponding to the height of each of the half-paddles. Since the width in pixels of the left half of the paddle is 27 while the width in pixels of the right half is 28, we just have to add these numbers to get 55, the width of the entire paddle, and use this number as the width of the surface.</p>
<p>Then, we use spritesheet.imgat to extract the image of the left half of the paddle, then we blit the left half to the left side of our new surface.</p>
<p>Then, we do the same thing with the right half of the paddle, blitting the image to the right side of the surface. We do this by placing the left edge of the half-paddle image at x = 27. This ensures that both paddle images are seamlessly connected.</p>
<p>Then, we want to set a colorkey for our image, so that it will blend seamlessly with the background, instead of looking rectangular.</p>
<p>When setting the colorkey, we have to make one of the pixel colors transparent. Since the upper left corner pixel of the sprite surface is not actually part of the actual paddle, but a part of the background, we took its color, and set pixels of this color as transparent. Again, we use the flag RLEACCEL to make using the surface fast.</p>
<p>Finally, we return the paddle image, making it ready for use. And that&#8217;s it &#8211; we have a paddle graphic that we can use!</p>
<p>In pygame, game elements are usually defined by deriving from the pygame Sprite class. Let us define a Paddle class which we will use later on to make our paddle appear on the screen and make it move using the mouse. The __init__ method that we have defined here will be called every time a new Paddle instance is made.</p>
<div class="codesnip-container" >
<div class="codesnip">Paddle.<span class="me1">image</span> = paddleimage<span class="br0">&#40;</span>spritesheet<span class="br0">&#41;</span></div>
</div>
<p>To attach the paddle image that we have made earlier to our Paddle class, we set the image attribute of our Paddle class to our paddle image.</p>
<div class="codesnip-container" >
<div class="codesnip">Paddle.<span class="me1">arena</span> = arena</div>
</div>
<p>Also, we have to make our paddle aware of its surroundings, the world it is in. In order for the Paddle class to access the world it is in, which is actually contained in the variable arena, we can define the attribute arena for our Paddle class and set it to our arena variable.<br />
<!--adsense#adbanner--></p>
<div class="codesnip-container" >
<div class="codesnip">Paddle.<span class="me1">containers</span> = all</div>
</div>
<p>In screencast number 1, we defined the variable all, which is a pygame RenderUpdates group, whose contents will be displayed on the screen. Since we want to make our paddle appear on the screen, we have to place instances of the Paddle class inside the RenderUpdates group all. We can accomplish this in two steps. First, let us define the attribute containers, which states the group or groups which we want instances of our class to belong to, and make this contain the RenderUpdates group all.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">class</span> Paddle<span class="br0">&#40;</span>pygame.<span class="me1">sprite</span>.<span class="me1">Sprite</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; pygame.<span class="me1">sprite</span>.<span class="me1">Sprite</span>.<span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span>, <span class="kw2">self</span>.<span class="me1">containers</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">rect</span> = <span class="kw2">self</span>.<span class="me1">image</span>.<span class="me1">get_rect</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">rect</span>.<span class="me1">bottom</span> = <span class="kw2">self</span>.<span class="me1">arena</span>.<span class="me1">rect</span>.<span class="me1">bottom</span> &#8211; <span class="kw2">self</span>.<span class="me1">arena</span>.<span class="me1">tileside</span><br />
&nbsp; &nbsp; <span class="kw1">def</span> update<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">rect</span>.<span class="me1">centerx</span> = pygame.<span class="me1">mouse</span>.<span class="me1">get_pos</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">rect</span>.<span class="me1">clamp_ip</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">arena</span>.<span class="me1">rect</span><span class="br0">&#41;</span></div>
</div>
<p>Whenever we derive from the pygame Sprite class, we have to call its __init__ method. We can pass the containers attribute to the __init__ method of the pygame Sprite class to make sprite instances belong to the groups contained in the attribute containers. Since we let the containers attribute of the Paddle class contain the RenderUpdates group all, this command will place instances of the Paddle sprite in the RenderUpdates group all. Since we have already laid down the game loop code in screencast number 1, simply placing instances of sprites in the group all will make them appear on the screen. So our paddle will appear on the screen!</p>
<p>To display pygame Sprite instances on the screen using pygame render groups, our Sprite instances should have two attributes &#8211; the image attribute and the rect attribute. The image attribute, which we have already taken care of when we attached the paddle graphic to the Paddle class, is the actual image which our pygame render group will put on the screen. The rect will determine where the image will be on the screen. To make the rect for our paddle, we just have to call the get_rect() method of our paddle surface.</p>
<p>Next, we have to determine where to place the paddle on the screen. Definitely, we want it to be at the bottom area of our playing field. To do this, we can set the y-coordinate of the bottom edge of our paddle to correspond to the top edge of the last row of tiles in the playing field. We do this by taking the y-coordinate of the bottom edge of the playing field, subtracting the length of one tile edge from it, and making the resulting value the y-coordinate of the bottom edge of the paddle image.</p>
<p>At this point, we can define the update method of our sprite. This method is called every time the update function of the group it belongs to is called. In general, this is the rendering group which contains all the sprites, such as the group named all in our code. Since we call the update method of the group all during every iteration of our game loop, we should expect this update function to be called once per frame.</p>
<p>For our paddle, we want it to follow the x-coordinate of the mouse to allow it to move along the bottom area of our playing field. To do this, we may set the x-coordinate of its center to correspond to the x-coordinate of the mouse pointer, which is obtained by taking the first element, which is indexed 0 as shown in the code, of the ordered pair corresponding to the position of the mouse, which is obtained by calling pygame.mouse.get_pos().</p>
<p>We are free to move the mouse pointer anywhere in the entire screen, even outside the playing field or even outside the game window. Of course, we do not want to see the paddle go out of the playing field even when the x-coordinate of the mouse pointer goes out of bounds. To restrict the paddle inside the playing field, we can use the built-in clamping functions of pygame. This particular piece of code restricts the rect of the paddle inside the rect of the playing field, ensuring that the paddle doesn&#8217;t go outside the playing field.</p>
<div class="codesnip-container" >
<div class="codesnip">paddle = Paddle<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p>Finally, we can go inside our main function again and make an instance of our paddle, which makes it present on the screen and in our game. We store our Paddle instance inside a variable so that we can easily access it later on.</p>
<p>And we are done! Finally, we have put a sprite on the screen, and we actually have something that we can interact with. Adding other game elements, which are usually represented as sprites, should be easier for us later on, since the procedure should be more or less similar to the one we did here.</p>
<p>I would love to hear from you! I really encourage you to leave a comment on the site. For the next screencast, we will be adding the ball to the game, together with some basic physics. Thank you so much and I hope to see you again for the next screencast!<br />
<!--adsense#linkhoriz--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/transcript-3-arinoid-the-paddle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Video Tutorial 3 &#8211; Arinoid &#8211; The Paddle</title>
		<link>http://www.scriptedfun.com/video-tutorial-3-arinoid-the-paddle/</link>
		<comments>http://www.scriptedfun.com/video-tutorial-3-arinoid-the-paddle/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:05:27 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[screencasts]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/?p=24</guid>
		<description><![CDATA[Finally! Today, we will be adding the first sprite in our game, the paddle, which is controlled using the mouse. At this point, we will be able to benefit from the setting-up that we have done in the first two screencasts.










screencast 3 source

]]></description>
			<content:encoded><![CDATA[<p>Finally! Today, we will be adding the first sprite in our game, the paddle, which is controlled using the mouse. At this point, we will be able to benefit from the setting-up that we have done in the first two screencasts.</p>
<p><img src="http://www.scriptedfun.com/wp-content/uploads/2006/06/screencast03.gif" alt="paddle sprite" /></p>
<p><span id="more-24"></span></p>
<p><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="646" HEIGHT="521" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"><br />
<PARAM NAME=movie VALUE="screencast03.swf"><br />
<PARAM NAME=play VALUE=true><br />
<PARAM NAME=loop VALUE=false><br />
<PARAM NAME=quality VALUE=low><br />
<EMBED SRC="http://www.scriptedfun.com/screencasts/screencast03.swf" WIDTH=646 HEIGHT=521 quality=low loop=false TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><br />
</EMBED><br />
</OBJECT></p>
<p><a href="http://www.scriptedfun.com/wp-content/uploads/2006/06/screencast03.txt">screencast 3 source</a><br />
<!--adsense#admedrect--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/video-tutorial-3-arinoid-the-paddle/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Transcript 2 &#8211; Using Sprite Sheets and Drawing the Background</title>
		<link>http://www.scriptedfun.com/transcript-2-using-sprite-sheets-and-drawing-the-background/</link>
		<comments>http://www.scriptedfun.com/transcript-2-using-sprite-sheets-and-drawing-the-background/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:04:51 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[transcripts]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/?p=21</guid>
		<description><![CDATA[Hello again and welcome to scriptedfun.com screencast number 2. Today, we are going to look into using sprite sheets and drawing the background for the game Arinoid.

The graphics for Arinoid were all taken from a single bitmap file called a sprite sheet. We have to find a way to extract the graphics that we need [...]]]></description>
			<content:encoded><![CDATA[<p>Hello again and welcome to scriptedfun.com screencast number 2. Today, we are going to look into using sprite sheets and drawing the background for the game Arinoid.<br />
<img src="http://www.scriptedfun.com/wp-content/uploads/2006/06/spritesheet.gif" alt="arinoid sprite sheet" /><br />
The graphics for Arinoid were all taken from a single bitmap file called a sprite sheet. We have to find a way to extract the graphics that we need from this file and use them in our games.<br />
<!--adsense#admedrect--><br />
<span id="more-21"></span></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">class</span> Spritesheet:<br />
&nbsp; &nbsp; <span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span>, filename<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">sheet</span> = pygame.<span class="me1">image</span>.<span class="me1">load</span><span class="br0">&#40;</span><span class="kw3">os</span>.<span class="me1">path</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&#8216;data&#8217;</span>, filename<span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">convert</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">def</span> imgat<span class="br0">&#40;</span><span class="kw2">self</span>, rect, colorkey = <span class="kw2">None</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; rect = Rect<span class="br0">&#40;</span>rect<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; image = pygame.<span class="me1">Surface</span><span class="br0">&#40;</span>rect.<span class="me1">size</span><span class="br0">&#41;</span>.<span class="me1">convert</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; image.<span class="me1">blit</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">sheet</span>, <span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span>, rect<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> colorkey <span class="kw1">is</span> <span class="kw1">not</span> <span class="kw2">None</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> colorkey <span class="kw1">is</span> -<span class="nu0">1</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colorkey = image.<span class="me1">get_at</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image.<span class="me1">set_colorkey</span><span class="br0">&#40;</span>colorkey, RLEACCEL<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> image<br />
&nbsp; &nbsp; <span class="kw1">def</span> imgsat<span class="br0">&#40;</span><span class="kw2">self</span>, rects, colorkey = <span class="kw2">None</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; imgs = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> rect <span class="kw1">in</span> rects:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgs.<span class="me1">append</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">imgat</span><span class="br0">&#40;</span>rect, colorkey<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> imgs</div>
</div>
<p>Let us define a Spritesheet class, and the first thing that we want it to do is load the sprite sheet file.<br />
Since the file we want to load is in the data subdirectory, we can use os.path.join to describe the location of the file in a platform-independent way. This means that the code will work regardless of the operating system that we use &#8211; Windows, Mac OS X, or Linux.<br />
Let&#8217;s not forget to convert the image to the correct pixel format so that using it will be fast.<br />
Let us define the method imgat, which will allow us to extract subimages from the sprite sheet. <!--adsense-->This method takes two arguments &#8211; a rect which describes the region we want to extract, and the colorkey, which will allow us to make the background transparent. Making the background transparent is very useful in games, because we want our graphics to blend in seamlessly with the background, instead of retaining their solid background, which makes them look rectangular.<br />
Note that we converted the rect argument into a Rect object. This will allow us to pass 4-tuples, representing the upper-left corner and the size of the subregion, instead of actual Rect objects, to the imgat method because converting the 4-tuple into a Rect object is already done for us.<br />
Then, let us make an empty pygame Surface, and convert it to the correct pixel format. This is where we will place the image that we want.<br />
Then, let us transfer the subregion which we want from the sprite sheet into our blank image.<br />
By default, we will not make the image transparent. Passing the parameter -1 will make the color of the upper-left pixel of the image transparent. This is often the case. Otherwise, we can specify the color which we want to make transparent.<br />
Finally, let us apply the colorkey. We used the flag RLEACCEL to make using the resulting image fast. And we&#8217;re done!<br />
It can also be useful for us to extract many images from the sprite sheet at the same time, and store all the resulting images in a list. Let us define the imgsat method to do this. First, let us make an empty list which we will use to store our images.<br />
Then, we simply use imgat for each given rect, use the same colorkey for each image, and store the resulting images in the list. And we&#8217;re done!</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">import</span> <span class="kw3">os</span>, pygame</div>
</div>
<p>By the way, we should import the os module as well, so that we can use os.path.join when we initialize the Spritesheet class.<br />
The Spritesheet class is a general-purpose class which we may paste into our barebones pygame application. We will definitely use this class again in our future projects.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">class</span> Arena:<br />
&nbsp; &nbsp; tileside = <span class="nu0">31</span><br />
&nbsp; &nbsp; numxtiles = <span class="nu0">12</span><br />
&nbsp; &nbsp; numytiles = <span class="nu0">14</span><br />
&nbsp; &nbsp; topx = <span class="br0">&#40;</span>SCREENRECT.<span class="me1">width</span> &#8211; SCREENRECT.<span class="me1">width</span>/tileside*tileside<span class="br0">&#41;</span>/<span class="nu0">2</span><br />
&nbsp; &nbsp; topy = <span class="br0">&#40;</span>SCREENRECT.<span class="me1">height</span> &#8211; SCREENRECT.<span class="me1">height</span>/tileside*tileside<span class="br0">&#41;</span>/<span class="nu0">2</span><br />
&nbsp; &nbsp; rect = Rect<span class="br0">&#40;</span>topx + tileside, topy + tileside, tileside*numxtiles, tileside*numytiles<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">background</span> = pygame.<span class="me1">Surface</span><span class="br0">&#40;</span>SCREENRECT.<span class="me1">size</span><span class="br0">&#41;</span>.<span class="me1">convert</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p>Let us define the Arena class, which will represent our playing field. The constant tileside, which contains the value 31, represents the width and height of the tiles in our sprite sheet. You can obtain this value by opening the sprite sheet file using your favorite image editor.<br />
The numxtiles and numytiles correspond to the width and height of the playing field in tiles. This means that our playing field will be 12 tiles in width and 14 tiles in height.<br />
Finally, it is useful to define a rect object which will correspond to the actual playing field. The upperleft corner of the playing field is one tile away from the corner of the screen because we can use the resulting space to draw a border around the playing field. The actual size of the playing field is then computed by multiplying the number of tiles to the size in pixels of each tile.<br />
Note that having a tileside of 31 is a bit strange, because the dimensions of the screen, 640 by 480, are not divisible by 31. If we try to fill the screen with 31 by 31 tiles, using only whole tiles, you will see that there will be extra space left, corresponding to the remainder when you divide 640 by 31 and 480 by 31. So it would be good if we could make some adjustments to center the image on the screen, which we can do by evenly distributing the extra space around the screen as a border.<br />
To do this, we must first determine the number of tiles that will fit in our screen. We do this by dividing the width of the screen by the tile size and the height of the screen by the tile size. Since both values are integers, the divisions will result in integers as well, leaving out the fractional part. Performing these divisions will give us the exact number of tiles that will fit crosswise and lengthwise.<br />
Then, let us multiply both by tileside, so that we will get the width and height of the region if an exact number of tiles were used. This may surprise you initially, because it may seem that you just cancelled the effect of multiplying tileside. However, remember that the fractional part was discarded during the previous division, so you should end up with a number that is less than or equal to the original width or height.<br />
Then, let us subtract the value that we currently have to the original width and height. This will give us the remainder, or the amount of extra space, when you divide the width or height by tileside.<br />
Finally, since we want the border to be evenly distributed around the screen, which effectively centers the image, we divide the remainder by 2. This ensures that the amount of space at the top is equal to the amount of space at the bottom. The same goes for the extra spaces at the left and at the right.<br />
To apply the border, we add topx and topy to the coordinates of the upper-left corner of the playing field, which moves the playing field by the computed amount, centering the screen. That does it for centering the screen!<br />
Let us now draw the background. Let us define a pygame Surface as large as the screen.<br />
<!--adsense#adbanner--></p>
<div class="codesnip-container" >
<div class="codesnip">spritesheet = Spritesheet<span class="br0">&#40;</span><span class="st0">&#8216;arinoid_master.bmp&#8217;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; Arena.<span class="me1">tiles</span> = spritesheet.<span class="me1">imgsat</span><span class="br0">&#40;</span><span class="br0">&#91;</span><span class="br0">&#40;</span><span class="nu0">129</span>, <span class="nu0">321</span>, <span class="nu0">31</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,&nbsp; &nbsp;<span class="co1"># purple &#8211; 0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="nu0">161</span>, <span class="nu0">321</span>, <span class="nu0">31</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,&nbsp; &nbsp;<span class="co1"># dark blue &#8211; 1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="nu0">129</span>, <span class="nu0">353</span>, <span class="nu0">31</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,&nbsp; &nbsp;<span class="co1"># red &#8211; 2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="nu0">161</span>, <span class="nu0">353</span>, <span class="nu0">31</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,&nbsp; &nbsp;<span class="co1"># green &#8211; 3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="nu0">129</span>, <span class="nu0">385</span>, <span class="nu0">31</span>, <span class="nu0">31</span><span class="br0">&#41;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>&nbsp; <span class="co1"># blue &#8211; 4 </span><br />
&nbsp;</div>
</div>
<p>The background elements will come from the sprite sheet. Let us make a Spritesheet instance using the Arinoid graphics sprite sheet.<br />
<img src="http://www.scriptedfun.com/wp-content/uploads/2006/06/bgtiles.gif" alt="arinoid background tiles" /><br />
The background graphics are contained in this part of the sprite sheet.<br />
<img src="http://www.scriptedfun.com/wp-content/uploads/2006/06/rect.gif" alt="upper-left corner and dimensions of a tile" /><br />
To extract one of the tileable backgrounds, we need to know two things about it: the coordinates of its upper-left corner and its dimensions. You can use your favorite image editor to do this. In my case, I used The GIMP, a free image editor, and used the Crop and Resize Tool to determine the information that I need. Here, we see that the upper-right corner of this purple tile is at (129, 321), and its dimensions are 31 by 31.<br />
All we have to do is take these numbers and use imgsat. As you can see, I used the numbers corresponding to the coordinates of the upper-left corner of the tile and the dimensions.<br />
Then, we just do the same for the other background tiles.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">def</span> drawtile<span class="br0">&#40;</span><span class="kw2">self</span>, tile, x, y<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">background</span>.<span class="me1">blit</span><span class="br0">&#40;</span>tile, <span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">topx</span> + <span class="kw2">self</span>.<span class="me1">tileside</span>*x,&nbsp; &nbsp; \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">topy</span> + <span class="kw2">self</span>.<span class="me1">tileside</span>*y<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">def</span> makebg<span class="br0">&#40;</span><span class="kw2">self</span>, tilenum<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> x <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">numxtiles</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> y <span class="kw1">in</span> <span class="kw2">range</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">numytiles</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">drawtile</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">tiles</span><span class="br0">&#91;</span>tilenum<span class="br0">&#93;</span>, x + <span class="nu0">1</span>, y + <span class="nu0">1</span><span class="br0">&#41;</span></div>
</div>
<p>The next thing we have to do is draw the background of our playing field using the tiles we have extracted from the sprite sheet. For this, let us define the drawtile method, which will draw an individual tile at the given place. For this, we just use blit, blitting the given tile image to the coordinates shown in the code. By multiplying tileside by x, we will get an exact multiple of tileside, which allows us to blit tiles which are situated exactly beside one another and do not overlap or have any gaps. By adding topx, we are making sure that the border that we constructed awhile ago to center the screen is followed. The same goes for y.<br />
To make the background, all we have to do is use drawtile to lay down each tile individually in the proper place. We do this by using 2 for loops. Take note that we added 1 to both x and y, so that we will have space left for the border, just like when we constructed the rect for the playing field.<br />
makebg takes the argument tilenum, corresponding to the tile color which we want to use. Recall that we placed 5 tile images with different designs in the list tiles. All we have to do is index this list, using the index of the tile image which we want to use. We made note of these indices as comments, as you can see at the bottom right of the screen. 0 corresponds to purple, 1 to dark blue, and so on.</p>
<div class="codesnip-container" >
<div class="codesnip">arena = Arena<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; arena.<span class="me1">makebg</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="co1"># you may change the background color here</span><br />
&nbsp; &nbsp; screen.<span class="me1">blit</span><span class="br0">&#40;</span>arena.<span class="me1">background</span>, <span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
<p>Next, we have to make some changes to our original background code. We have to replace the highlighted code, which drew our blue background in the barebones pygame program, with code that will draw our playing field background.<br />
Since all the background code is in the Arena class, all we have to do is make an Arena instance, then use its makebg method. Here, we used 0 as an argument to draw a purple background.<br />
Then, we just have to change background to arena.background, since the arena instance stores the background image in its own background variable.</p>
<div class="codesnip-container" >
<div class="codesnip">all.<span class="me1">clear</span><span class="br0">&#40;</span>screen, arena.<span class="me1">background</span><span class="br0">&#41;</span></div>
</div>
<p>We have to make the same change in the clear part of our game loop.<br />
And we are done! Although it may seem that we had to do quite a bit of work to do something as simple as this, we have actually written some code, in particular the sprite sheet code, which we will have to use later when we add the other game elements. At the same time, we have also tackled some of the principles behind drawing tile maps, which will come in handy if we decide to make tile and map-based games later on.<br />
I&#8217;d love to hear from you! I highly encourage you to leave a comment on the site if you have any questions, comments, suggestions, or anything at all. In the next screencast, we will add the paddle to our game, and look into simple mouse handling. Thank you and I hope to see you again for the next screencast!<br />
<!--adsense#linkhoriz--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/transcript-2-using-sprite-sheets-and-drawing-the-background/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Video Tutorial 2 &#8211; Using Sprite Sheets and Drawing the Background</title>
		<link>http://www.scriptedfun.com/video-tutorial-2-using-sprite-sheets-and-drawing-the-background/</link>
		<comments>http://www.scriptedfun.com/video-tutorial-2-using-sprite-sheets-and-drawing-the-background/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:03:35 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[screencasts]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/?p=16</guid>
		<description><![CDATA[To run the code for this screencast, you will need to have a data subdirectory containing the Arinoid sprite sheet file. You can easily fulfill this requirement by downloading the arinoid source from the post on Arinoid. Also, this will be needed for most, if not all, of the upcoming screencasts.



If you want to follow [...]]]></description>
			<content:encoded><![CDATA[<p>To run the code for this screencast, you will need to have a data subdirectory containing the Arinoid sprite sheet file. You can easily fulfill this requirement by downloading the <a href="http://www.scriptedfun.com/wp-content/uploads/2006/06/arinoid.zip">arinoid source</a> from the <a href="http://www.scriptedfun.com/?p=5">post on Arinoid</a>. Also, this will be needed for most, if not all, of the upcoming screencasts.</p>
<p><img alt="tiled background" src="http://www.scriptedfun.com/wp-content/uploads/2006/06/screencast02.gif" /><br />
<!--adsense#admedrect--><br />
<span id="more-16"></span></p>
<p>If you want to follow along the screencast, you will need an image editor that will allow you to select subregions of images and get the size and location of the selected subregion. To do this, I use <a href="http://www.gimp.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.gimp.org');">The GIMP</a>, a free and full-featured image editor. Of course, you can use any image editor that you&#8217;re comfortable with. In fact, I would love to know about your image editor suggestions <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> !</p>
<p><!--adsense#linksquare-->By the way, once you view the screencast, you may notice that I select regions using The GIMP&#8217;s <a href="http://manual.gimp.org/en/gimp-tool-crop.html" onclick="javascript:pageTracker._trackPageview ('/outbound/manual.gimp.org');">Crop and Resize Tool</a>. Although it does the job, I still think that there&#8217;s a tool that&#8217;s more appropriate for the job. Can you help me out on this <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ?</p>
<p>I know I haven&#8217;t posted the transcript for the first screencast yet <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , but I plan to do so soon, and the same goes for this screencast <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="646" HEIGHT="521" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"><br />
<PARAM NAME=movie VALUE="screencast02.swf"><br />
<PARAM NAME=play VALUE=true><br />
<PARAM NAME=loop VALUE=false><br />
<PARAM NAME=quality VALUE=low><br />
<EMBED SRC="http://www.scriptedfun.com/screencasts/screencast02.swf" WIDTH=646 HEIGHT=521 quality=low loop=false TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><br />
</EMBED><br />
</OBJECT></p>
<p><a href="http://www.scriptedfun.com/wp-content/uploads/2006/06/screencast02.txt">screencast 2 source</a><br />
<!--adsense#adbanner--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/video-tutorial-2-using-sprite-sheets-and-drawing-the-background/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Arinoid &#8211; an Arkanoid clone</title>
		<link>http://www.scriptedfun.com/arinoid-an-arkanoid-clone/</link>
		<comments>http://www.scriptedfun.com/arinoid-an-arkanoid-clone/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:00:06 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[arinoid]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[pygame]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/?p=5</guid>
		<description><![CDATA[For our first game, let&#8217;s try to write an Arkanoid clone. The graphics in the game were taken from the freely available Spritelib by Ari Feldman.



The prototype contains only one level, and I&#8217;m pretty sure that a lot of people out there can do a much better job with level design and color coordination  [...]]]></description>
			<content:encoded><![CDATA[<p>For our first game, let&#8217;s try to write an <a href="http://en.wikipedia.org/wiki/Arkanoid" onclick="javascript:pageTracker._trackPageview ('/outbound/en.wikipedia.org');">Arkanoid</a> clone. The graphics in the game were taken from the freely available <a href="http://www.flyingyogi.com/fun/spritelib.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.flyingyogi.com');">Spritelib by Ari Feldman</a>.</p>
<p><img alt="arinoid screenshot" src="http://www.scriptedfun.com/wp-content/uploads/2006/06/arinoid.gif" /><br />
<!--adsense#admedrect--><br />
<span id="more-5"></span></p>
<p>The prototype contains only one level, and I&#8217;m pretty sure that a lot of people out there can do a much better job with level design and color coordination <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The game is very much playable, although I think there are better ways of implementing the ball/brick &#8220;physics&#8221;.</p>
<p><!--adsense#linksquare-->So this is how it&#8217;s going to work (this will be the general routine for most of the games): this first post will include a general overview of the project, and a zip file containing the prototype. The next posts shall discuss how the game was put together. Along the way, I hope to gather comments, suggestions, and help <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  from everyone, and these will all be factored into the next iteration of the project. This process will just repeat itself until we come up with something that most, if not all of us, will be happy about <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>This game was written in <a href="http://www.python.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.python.org');">Python</a>, using the <a href="http://www.pygame.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.pygame.org');">Pygame</a> library. For me, Python is great to work with, and I would recommend it as a good first programming language. As most of you already know, Python code is very readable, and this is very important for an undertaking like this. I would just like to stress that this project could have been implemented in any other language &#8211; the choice of language is mainly due to personal preference.</p>
<p>To understand what&#8217;s about to happen, I would consider a working knowledge of Python as a prerequisite. For those of you who already know how to program, I assure you that you can easily pick up Python. With some basic knowledge of C and familiarity with programming, I was able to learn Python by reading the <a href="http://docs.python.org/tut/tut.html" onclick="javascript:pageTracker._trackPageview ('/outbound/docs.python.org');">Python Tutorial</a> that comes with the Python package. I think that a weekend is more than enough to go through this tutorial.</p>
<p>For those who haven&#8217;t programmed before, the Python website has a <a href="http://www.python.org/about/gettingstarted/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.python.org');">Getting Started</a> page, which includes <a href="http://wiki.python.org/moin/BeginnersGuide/NonProgrammers" onclick="javascript:pageTracker._trackPageview ('/outbound/wiki.python.org');">resources for non-programmers</a>. If you&#8217;re a non-programmer, I encourage you to give it a shot! <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I was a non-programmer myself before, and I think that the effort was worth it.</p>
<p>To run the code, you will need to have Python and Pygame installed. Here is the zip file which contains the Arinoid source code and graphics (this should work for Windows, Mac OS X, and Linux).</p>
<p><a href="http://www.scriptedfun.com/wp-content/uploads/2006/06/arinoid.zip">arinoid source</a><br />
<!--adsense#adbanner--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/arinoid-an-arkanoid-clone/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>
