<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ahmad-cod</title>
    <description>The latest articles on DEV Community by ahmad-cod (@ahmadcod).</description>
    <link>https://dev.to/ahmadcod</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F553848%2Ffa3a9c6e-bf2a-4e00-972a-2c5a89098571.png</url>
      <title>DEV Community: ahmad-cod</title>
      <link>https://dev.to/ahmadcod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmadcod"/>
    <language>en</language>
    <item>
      <title>Collision detection in 2D game development with JavaScript</title>
      <dc:creator>ahmad-cod</dc:creator>
      <pubDate>Wed, 05 Oct 2022 21:43:33 +0000</pubDate>
      <link>https://dev.to/ahmadcod/collision-detection-in-2d-game-development-with-javascript-47ao</link>
      <guid>https://dev.to/ahmadcod/collision-detection-in-2d-game-development-with-javascript-47ao</guid>
      <description>&lt;p&gt;&lt;strong&gt;Collision detection&lt;/strong&gt; also known as &lt;strong&gt;hit testing&lt;/strong&gt; is simply determining when two objects come in &lt;strong&gt;contact&lt;/strong&gt; with one another.&lt;/p&gt;

&lt;p&gt;The collision of objects underlies most game experiences and user-interfaces.&lt;br&gt;
Baseball bats collide with balls, zombies bump into walls, and Mario lands on platforms and stomps turtles. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vfg121qchih9ic08eaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vfg121qchih9ic08eaf.png" alt="Mario lands on platforms and stomps turtles"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  A General Formula For Collision Detection
&lt;/h4&gt;

&lt;p&gt;Detect the positions of each object, compare and calculate if they're overlapping.&lt;/p&gt;
&lt;h4&gt;
  
  
  Instances
&lt;/h4&gt;

&lt;p&gt;Examples of collision between two objects:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;POINT/POINT&lt;/li&gt;
&lt;li&gt;CIRCLE/CIRCLE&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RECTANGLE/RECTANGLE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Point/Point&lt;/strong&gt;&lt;br&gt;
The easiest collision to test is between two points, to test if they're colliding, we simply check if their X and Y co-ordinates are the same! (i.e if their positions are same).&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (x1 == x2 &amp;amp;&amp;amp; y1 == y2) {
  // Points are in the same place: collision
}
else {
// Not colliding
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Circle ⭕ / Circle ⭕&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine you have two circles, each with their own radius. They are placed with a distance between them. The circles would overlap if the &lt;strong&gt;distance&lt;/strong&gt; is &lt;strong&gt;smaller&lt;/strong&gt; than the &lt;strong&gt;sum&lt;/strong&gt; of the &lt;strong&gt;radius&lt;/strong&gt; of both circles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj743txz8xkhlt4xhsacn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj743txz8xkhlt4xhsacn.png" alt="Calculating the distance between 2 circles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Calculating the distance between the center of the two circles requires us to remember middle school math and the Pythagorean Theorem:&lt;br&gt;
&lt;code&gt;Opp² + Adj² = Hyp²&lt;/code&gt; simply &lt;code&gt;∆x² + ∆y² = d²&lt;/code&gt;;&lt;br&gt;
&lt;code&gt;d = √(∆x² + ∆y²)&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;Translated to code, it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = Math.sqrt((∆x*∆x) + (∆y*∆y))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if this distance is smaller than or equal to the radius of circle-a plus radius of circle-b, the circles overlap or touch. This principle is used in the next function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const circlesCollide = (x1, y1, r1, x2, y2, r2) =&amp;gt; {

    // Calculate the distance between the two circles
    let squareDistance = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);

    // When the distance is smaller or equal to the sum
    // of the two radius, the circles touch or overlap
    return squareDistance &amp;lt;= ((r1 + r2) * (r1 + r2))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the formula is tweaked a bit. Multiplication is much faster than getting the square root with &lt;br&gt;
&lt;code&gt;Math.sqrt()&lt;/code&gt; so the distance is calculated without getting the root and the sum of the radii is multiplied by itself. The outcome stays the same, but the performance is better.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>gamedev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Starting an internship with the Zuri Team</title>
      <dc:creator>ahmad-cod</dc:creator>
      <pubDate>Sun, 15 Aug 2021 16:17:49 +0000</pubDate>
      <link>https://dev.to/ahmadcod/starting-an-internship-with-the-zuri-team-55le</link>
      <guid>https://dev.to/ahmadcod/starting-an-internship-with-the-zuri-team-55le</guid>
      <description>&lt;h2&gt;
  
  
  Hello World,
&lt;/h2&gt;

&lt;p&gt;I'm &lt;strong&gt;Ahmad Aroyehun&lt;/strong&gt;, I'm about to embark on an interesting journey with the &lt;a href="https://zuri.team"&gt;Zuri Team&lt;/a&gt;, and I hope to share my adventure with you all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goals for the 8 weeks Internship
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Understand my frontend skills (HTML, CSS, Javascript and React) better.&lt;/li&gt;
&lt;li&gt;Learn Typescript and Graph ql.&lt;/li&gt;
&lt;li&gt;Build Real life Projects.&lt;/li&gt;
&lt;li&gt;Share the difficulties and the interesting part of the internship every Sunday of each week.&lt;/li&gt;
&lt;li&gt;Work and collaborate with other developers.&lt;/li&gt;
&lt;li&gt;By the end of the internship I hope to secure a remote frontend developer, javascript or fullstack developer job.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks at &lt;a href="https://zuri.team"&gt;zuri team&lt;/a&gt;, &lt;a href="https://internship.zuri.team"&gt;Zuri Internship&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here are some awesome beginner's tutorials
&lt;/h4&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FTFaQWZBqQ8"&gt;
&lt;/iframe&gt;
&lt;br&gt;
  &lt;a href="https://www.youtube.com/watch?v=FTFaQWZBqQ8"&gt;Figma tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/RGOj5yH7evk"&gt;
&lt;/iframe&gt;
&lt;br&gt;
   &lt;a href="https://www.youtube.com/watch?v=RGOj5yH7evk"&gt;Version Control with Git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/D-h8L5hgW-w"&gt;
&lt;/iframe&gt;
&lt;br&gt;
   &lt;a href="https://www.youtube.com/watch?v=D-h8L5hgW-w"&gt;Learning HTML and CSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/W6NZfCO5SIk"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=W6NZfCO5SIk"&gt;Using Javascript&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nothing Good comes easy.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>internship</category>
      <category>react</category>
    </item>
  </channel>
</rss>
