<?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>collision | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/collision/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>Sun, 28 Jun 2020 19:47:26 +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>collision | 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>More on pointers in C. The use of typedef</title>
		<link>https://learncgames.com/more-on-pointers-in-c-the-use-of-typedef/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=more-on-pointers-in-c-the-use-of-typedef</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 05 Mar 2020 06:23:19 +0000</pubDate>
				<category><![CDATA[Game]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[collision]]></category>
		<category><![CDATA[masks]]></category>
		<category><![CDATA[pointers]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=64</guid>

					<description><![CDATA[<p>This bit is slightly controversial. I find all the * makes it harder to read code so I use typedefs to hide them. Here&#8217;s an example from the game. Try replacing every pbte with byte * and see if reading it is harder for you. typedef byte * pbyte; // mask arrays byte bulletmask[1][3][3]; byte [&#8230;]</p>
The post <a href="https://learncgames.com/more-on-pointers-in-c-the-use-of-typedef/">More on pointers in C. The use of typedef</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="size-full wp-image-66 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/imminentdestruction.png" alt="Asteroid about to be destroyed" width="263" height="189" />This bit is slightly controversial. I find all the * makes it harder to read code so I use typedefs to hide them. Here&#8217;s an example from the game. Try replacing every pbte with byte * and see if reading it is harder for you.</p>
<pre><code class="language-c" data-line="">typedef byte * pbyte;

// mask arrays
byte bulletmask[1][3][3];
byte plmask[24][64][64];
byte a1mask[24][280][280];
byte a2mask[24][140][140];
byte a3mask[24][70][70];
byte a4mask[24][35][35];
byte alienmask[64][64];

pbyte GetMask(int type, int rotation, int size) {
  switch (type) {
    case tAsteroid: // asteroid
      {
        switch (size)
          {
            case 280:
              return (pbyte)&amp;a1mask[rotation];
            case 140:
              return (pbyte)&amp;a2mask[rotation];
            case 70:
              return (pbyte)&amp;a3mask[rotation];
            case 35:
              return (pbyte)&amp;a4mask[rotation];
          }
      };
    case tBullet: // bullet
      return (pbyte)&amp;bulletmask;
    case tPlayer: // player
      return (pbyte)&amp;plmask[rotation];
    case tAlien:
      return (pbyte)&amp;alienmask;
    } 
  return 0; // null - should never get here!
}</code></pre>
<p>In my post about collision detection I mentioned getting mask bytes. This function GetMask returns a pointer to a byte (i.e. the first byte in a particular mask for a particular type of object (asteroid, bullet, player, alien) and for asteroids and the player a particular rotation. The many (pbyte) are needed because the arrays have different sizes. There are 24 player and asteroid masks.</p>The post <a href="https://learncgames.com/more-on-pointers-in-c-the-use-of-typedef/">More on pointers in C. The use of typedef</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">64</post-id>	</item>
	</channel>
</rss>
