<?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>code | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Mon, 08 Jun 2020 18:26:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>code | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Another Visual Studio Code source &#8211; VSCodium</title>
		<link>https://learncgames.com/another-visual-studio-code-source-vscodium/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=another-visual-studio-code-source-vscodium</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 13 Jun 2020 23:00:16 +0000</pubDate>
				<category><![CDATA[alternative]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[vscodium]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=808</guid>

					<description><![CDATA[<p>As they say &#8220;This is not a fork. This is a repository of scripts to automatically build Microsoft&#8217;s vscode repository into freely-licensed binaries with a community-driven default configuration.&#8221; Microsoft&#8217;s code includes telemetry and tracking code. The code built here is the same as Microsoft&#8217;s but with that telemetry and tracking code removed. Also it includes builds [&#8230;]</p>
The post <a href="https://learncgames.com/another-visual-studio-code-source-vscodium/">Another Visual Studio Code source – VSCodium</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:669,&quot;href&quot;:&quot;https:\/\/github.com\/VSCodium\/vscodium&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260204172555\/https:\/\/github.com\/VSCodium\/vscodium&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:23:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 05:56:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 12:17:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:02:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 16:13:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 05:10:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 10:12:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 14:20:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-29 18:51:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 06:45:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 05:44:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 02:58:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 14:39:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 11:10:29&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 11:10:29&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:670,&quot;href&quot;:&quot;https:\/\/github.com\/VSCodium\/vscodium\/blob\/master\/DOCS.md&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20231027075644\/https:\/\/github.com\/VSCodium\/vscodium\/blob\/master\/DOCS.md&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:24:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-13 05:56:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 12:17:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-24 11:07:59&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-27 23:11:40&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-05 16:13:20&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-10 05:18:22&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-14 10:12:38&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-26 14:20:23&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-29 18:51:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-03 06:45:09&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 05:44:28&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-12 02:58:36&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-16 14:39:34&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-20 09:38:12&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 09:38:12&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><a title="Link to VsCodium on GitHub" href="https://github.com/VSCodium/vscodium" target="_blank" rel="noopener noreferrer"><img fetchpriority="high" decoding="async" class="alignleft size-medium wp-image-809" src="https://learncgames.com/wp-content/uploads/2020/06/vscodium-300x169.png" alt="VSCodium" width="300" height="169" srcset="https://learncgames.com/wp-content/uploads/2020/06/vscodium-300x169.png 300w, https://learncgames.com/wp-content/uploads/2020/06/vscodium-768x432.png 768w, https://learncgames.com/wp-content/uploads/2020/06/vscodium.png 800w" sizes="(max-width: 300px) 100vw, 300px" />As they say</a> &#8220;This is not a fork. This is a repository of scripts to automatically build Microsoft&#8217;s <code class="" data-line="">vscode</code> repository into freely-licensed binaries with a community-driven default configuration.&#8221;</p>
<p>Microsoft&#8217;s code includes telemetry and tracking code. The code built here is the same as Microsoft&#8217;s but with that telemetry and tracking code removed. Also it includes builds for both ARM (32 and 64-bit) which you don&#8217;t get from Microsoft.</p>
<p>The <a title="Link to VSCodium page" href="https://github.com/VSCodium/vscodium/blob/master/DOCS.md" target="_blank" rel="nofollow noopener noreferrer">Docs page</a> provides info on how to copy JSON bindings from Visual Studio Code to VSCodium. I shall be giving this a try. Much as I like the code.headmelted.com Visual Studio Code, it doesn&#8217;t appear to be updated very often whereas VSCodium seems to be built every night.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/another-visual-studio-code-source-vscodium/">Another Visual Studio Code source – VSCodium</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">808</post-id>	</item>
		<item>
		<title>Identifying a Linux system in code</title>
		<link>https://learncgames.com/identifying-a-linux-system-in-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=identifying-a-linux-system-in-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 23:00:54 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[code]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=412</guid>

					<description><![CDATA[<p>Since I got asteroids running on a Raspberry Pi, I have decided I want to incorporate the temperature in the window caption when you switch it to debug mod by pressing Tab. Currently all that does is display position info on moving objects and bounding boxes. But if I include that code in, I want [&#8230;]</p>
The post <a href="https://learncgames.com/identifying-a-linux-system-in-code/">Identifying a Linux system in code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:772,&quot;href&quot;:&quot;https:\/\/linux.die.net\/man\/1\/uname&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251128020850\/https:\/\/linux.die.net\/man\/1\/uname&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 18:26:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 06:16:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 12:00:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-28 19:52:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 00:38:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 03:25:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 18:43:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 20:18:19&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 20:18:19&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:773,&quot;href&quot;:&quot;https:\/\/stackoverflow.com\/questions\/3596310\/c-how-to-use-the-function-uname&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20241123064104\/https:\/\/stackoverflow.com\/questions\/3596310\/c-how-to-use-the-function-uname&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 18:26:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 06:16:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 12:00:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-28 19:52:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 00:38:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 03:25:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 18:43:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 20:18:20&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 20:18:20&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<p>Since I got asteroids running on a Raspberry Pi, I have decided I want to incorporate the temperature in the window caption when you switch it to debug mod by pressing Tab. Currently all that does is display position info on moving objects and bounding boxes.</p>
<p>But if I include that code in, I want to be sure that it only works when running on a Raspberry Pi. So I need some code to identify the system. A bit of digging and I discovered the Linux <a href="https://linux.die.net/man/1/uname" target="_blank" rel="noopener noreferrer">uname</a> command. That link goes to an online man page for uname.</p>
<p>If I run <em>uname -a</em> on my Ubuntu 18.04LTS I get this.</p>
<pre><code class="language-bash" data-line="">Linux david-Virtual-Machine 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<p>And on my PI.</p>
<pre><code class="language-bash" data-line="">Linux raspberrypi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux</code></pre>
<p>In fact the <em>uname -n</em> command gives <strong>david-Virtual-Machine</strong> on Ubuntu and <strong>raspberrypi</strong> on the PI. These are the names though names are often changeable and what if someone is running ubuntu on a PI? Yes it is a thing. But the <em>uname -m</em> identifies the CPU.  x86-64 on my Ubuntu and armv71 on the pi.</p>
<p>I did a bit of digging and found a C program on <a href="https://stackoverflow.com/questions/3596310/c-how-to-use-the-function-uname" target="_blank" rel="noopener noreferrer">stackoverflow</a> that will do the same as uname.</p>
<pre><code class="language-c" data-line="">#include 
#include 
#include 
#include &lt;sys/utsname.h&gt;

int main(void) {

   struct utsname buffer;

   errno = 0;
   if (uname(&amp;buffer) != 0) {
      perror(&quot;uname&quot;);
      exit(EXIT_FAILURE);
   }

   printf(&quot;system name = %s\n&quot;, buffer.sysname);
   printf(&quot;node name   = %s\n&quot;, buffer.nodename);
   printf(&quot;release     = %s\n&quot;, buffer.release);
   printf(&quot;version     = %s\n&quot;, buffer.version);
   printf(&quot;machine     = %s\n&quot;, buffer.machine);

   #ifdef _GNU_SOURCE
      printf(&quot;domain name = %s\n&quot;, buffer.domainname);
   #endif

   return EXIT_SUCCESS;
}</code></pre>
<p>And this is what it outputs on a PI.</p>
<pre><code class="language-bash" data-line="">
system name = Linux
node name   = raspberrypi
release     = 4.19.97-v7+
version     = #1294 SMP Thu Jan 30 13:15:58 GMT 2020
machine     = armv7l</code></pre>
<p>So that bit is easy to do. Next is getting the temperature, but that&#8217;s for another blog entry&#8230;</p>The post <a href="https://learncgames.com/identifying-a-linux-system-in-code/">Identifying a Linux system in code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">412</post-id>	</item>
		<item>
		<title>How pixel perfect collision detection works</title>
		<link>https://learncgames.com/how-pixel-perfect-collision-detection-works/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-pixel-perfect-collision-detection-works</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 01 Mar 2020 10:08:50 +0000</pubDate>
				<category><![CDATA[Ebook]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[collision detection]]></category>
		<category><![CDATA[game]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=22</guid>

					<description><![CDATA[<p>There are four types of moving object in the games. Asteroids in four sizes from 35&#215;35, 70&#215;70, 140&#215;140 and 280&#215;280 pixels, the player&#8217;s ship (fits in 64 x 64 pixels), alien ships (also in 64 x 64)  and a bullet which is solid 3&#215;3 pixels with the four corners empty. As these move around the [&#8230;]</p>
The post <a href="https://learncgames.com/how-pixel-perfect-collision-detection-works/">How pixel perfect collision detection works</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:834,&quot;href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL_IntersectRect&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20220216102708\/https:\/\/wiki.libsdl.org\/SDL_IntersectRect&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:48:03&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-20 19:53:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-27 04:28:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-05 04:49:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-10 06:22:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-17 10:04:36&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-21 05:21:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-29 08:33:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-02 00:24:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-05 10:39:45&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-13 21:12:28&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-17 22:52:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-23 02:04:09&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-23 02:04:09&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="size-full wp-image-29 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/collisiondetection.png" alt="Asteroid and player ship about to collide near an explosions" width="276" height="284" />There are four types of moving object in the games. Asteroids in four sizes from 35&#215;35, 70&#215;70, 140&#215;140 and 280&#215;280 pixels, the player&#8217;s ship (fits in 64 x 64 pixels), alien ships (also in 64 x 64)  and a bullet which is solid 3&#215;3 pixels with the four corners empty.</p>
<p>As these move around the screen at 60 frames per second, they will come into contact and the collision detection has to figure out when they hit or miss.</p>
<p>To make it more complicated, the asteroids and player&#8217;s ship come in 24 rotations, each by 15 degrees so detection has to take that into account. The image shows an asteroid just about to hit the player&#8217;s ship.. At the bottom you can see where another asteroid has been blown up (the 50 is the score) and there&#8217;s a bullet to the right.</p>
<p>The detection occurs in several stages. First each object has a bounding square.<img decoding="async" class="size-full wp-image-31 alignright" src="https://learncgames.com/wp-content/uploads/2020/03/boundingboxes.png" alt="This shows the bounding boxes for the player's ship and an asteroid" width="174" height="190" /> This is an invisible square that just fits round each object. For the player&#8217;s ship it&#8217;s 64 x 64 and it corresponds to the sizes of each asteroid. As the image shows, the two bounding boxes overlap and it&#8217;s in this overlap rectangle that we have to check for a possible collision.</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-34 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/cells-300x222.jpg" alt="A large asteroid and the cells it overlaps" width="300" height="222" srcset="https://learncgames.com/wp-content/uploads/2020/03/cells-300x222.jpg 300w, https://learncgames.com/wp-content/uploads/2020/03/cells.jpg 494w" sizes="auto, (max-width: 300px) 100vw, 300px" />First things first. Every frame all objects are moved and we have to detect if there&#8217;s a chance of a collision. This is done by dividing the entire playing area (set in the book to 1024 x 768) into 64 x 64 pixels cells.  I chose that as a convenient size. Once the object&#8217;s new x,y location has been calculated, I determine which cells it overlaps.</p>
<p>The player&#8217;s ship can fit completely into one cell but most times it is either overlapping two or four cells. Even a 3 x 3 bullet will occasionally overlap two or four cells but most of the time it will fit completely in one.  The largest Asteroid (280 x 280) always overlaps five or six cells in each direction so it gets added into to 25,30 or 36 cells each frame.  The image shows the grid of 64 x 64 cells and the asteroid overlaps 25 cells, the player&#8217;s ship just overlaps 4 cells. The number is a count of the number of overlapping item in each cell.   It&#8217;s the bounding box size that determines if it overlaps which is why the top left and bottom right empty cells of the asteroid still show 1.</p>
<p>In each cell, I keep a list of objects that overlap that cell. The first step is scanning all cells with overlapping objects in to see if there are two or more objects overlapping in that cell. The SDL library includes a function <a href="https://wiki.libsdl.org/SDL_IntersectRect" target="_blank" rel="noopener noreferrer">SDL_IntersectRect()</a>  You pass in the two bounding rectangles of overlapping objects and it returns a rectangle of the intersection, which corresponds to the overlap in the image above. If there are multiple objects in a cell e.g. four then you have to check to see if any of those (1,2), (1,3), (1,4), (2,3), (2,4), (3,4) overlap.</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-35 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/playershipmask-300x265.png" alt="A text file representation of a mask" width="300" height="265" srcset="https://learncgames.com/wp-content/uploads/2020/03/playershipmask-300x265.png 300w, https://learncgames.com/wp-content/uploads/2020/03/playershipmask.png 600w" sizes="auto, (max-width: 300px) 100vw, 300px" />The next bit is what makes it pixel perfect. For every object and its rotations, I have created a mask. It&#8217;s a file of bytes with a 1 value corresponding to every coloured pixel in the object and 0 to empty pixels.</p>
<p>I have stretched this image to make it the same aspect ratio and it shows 0s and 1s in the player&#8217;s ship mask.</p>
<p>The collision detection algorithm processes the intersection rectangle and calculates where each pixel in that rectangle falls in the corresponding mask (adjusting for rotations) of each object.  If either mask pixel is 0 then no collision occurs but if both are 1 then bam!</p>
<p>Although I could have used a mask of bits, it was quicker to use bytes.</p>
<p>During development I wanted to verify that it was pixel perfect, so I disabled explosions and instead when two pixels overlapped, I output a green pixel to highlight it. The image shows the player&#8217;s ship passing through an asteroid!<img loading="lazy" decoding="async" class="size-full wp-image-37 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/touching.png" alt="Showing pixel perfect touching" width="171" height="200" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/how-pixel-perfect-collision-detection-works/">How pixel perfect collision detection works</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">22</post-id>	</item>
		<item>
		<title>Fast Random Number Generators in C</title>
		<link>https://learncgames.com/fast-random-number-generators-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fast-random-number-generators-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 29 Feb 2020 19:59:37 +0000</pubDate>
				<category><![CDATA[Game]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rng]]></category>
		<category><![CDATA[romu]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=17</guid>

					<description><![CDATA[<p>Today I found out about Romu (Rotate and Multiply) random number generators. Typically I&#8217;ve been using srand() in my asteroids game, so this is well worth a look.  Their code page lists functions, so they should be easy to plugin.</p>
The post <a href="https://learncgames.com/fast-random-number-generators-in-c/">Fast Random Number Generators in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:835,&quot;href&quot;:&quot;http:\/\/www.romu-random.org&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206195901\/https:\/\/www.romu-random.org\/&quot;,&quot;redirect_href&quot;:&quot;https:\/\/www.romu-random.org\/&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-14 10:21:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 23:37:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 23:26:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 20:10:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 09:52:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 17:56:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 18:40:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 16:17:48&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 16:17:48&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:836,&quot;href&quot;:&quot;http:\/\/www.romu-random.org\/code.c&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250521132917\/https:\/\/romu-random.org\/code.c&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:58:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-14 10:21:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 23:37:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 23:26:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 20:10:16&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-17 09:52:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 17:56:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 18:40:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 16:17:42&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 16:17:42&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-19" src="https://learncgames.com/wp-content/uploads/2020/02/romu-300x165.png" alt="" width="300" height="165" srcset="https://learncgames.com/wp-content/uploads/2020/02/romu-300x165.png 300w, https://learncgames.com/wp-content/uploads/2020/02/romu-768x422.png 768w, https://learncgames.com/wp-content/uploads/2020/02/romu.png 847w" sizes="auto, (max-width: 300px) 100vw, 300px" />Today I found out about <a href="http://www.romu-random.org/" target="_blank" rel="noopener noreferrer">Romu</a> (Rotate and Multiply) random number generators. Typically I&#8217;ve been using srand() in my asteroids game, so this is well worth a look.  Their <a href="http://www.romu-random.org/code.c">code page</a> lists functions, so they should be easy to plugin.</p>The post <a href="https://learncgames.com/fast-random-number-generators-in-c/">Fast Random Number Generators in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">17</post-id>	</item>
	</channel>
</rss>
