<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by asanka sandaruwan on Medium]]></title>
        <description><![CDATA[Stories by asanka sandaruwan on Medium]]></description>
        <link>https://medium.com/@asankasandruwan?source=rss-ce1ccdd98207------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iaYVSjPVuS0LKHYA0bijOw.png</url>
            <title>Stories by asanka sandaruwan on Medium</title>
            <link>https://medium.com/@asankasandruwan?source=rss-ce1ccdd98207------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:03:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asankasandruwan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Responsive Game for National Doughnut Day]]></title>
            <link>https://medium.com/@asankasandruwan/building-a-responsive-game-for-national-doughnut-day-06b674ef4f73?source=rss-ce1ccdd98207------2</link>
            <guid isPermaLink="false">https://medium.com/p/06b674ef4f73</guid>
            <dc:creator><![CDATA[asanka sandaruwan]]></dc:creator>
            <pubDate>Thu, 12 Dec 2024 06:03:16 GMT</pubDate>
            <atom:updated>2024-12-12T06:03:16.397Z</atom:updated>
            <content:encoded><![CDATA[<p>In my journey as a full-stack developer at Enfection, I recently undertook a unique and exciting project: developing an interactive game for Keels Supermarket’s network. The game was crafted to celebrate <strong>National Doughnut Day</strong> and was hosted on AWS, ensuring seamless accessibility for users across both mobile and desktop platforms. Here’s an inside look at how this responsive game was designed and built using modern web technologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*zDN_nvgz96QEFvjmxwHrMw.png" /></figure><h3>The Idea Behind the Game</h3><p>The primary goal of the project was to engage users with a fun and captivating game that worked flawlessly on all devices. Given the thematic alignment with <strong>National Doughnut Day</strong>, the game revolved around doughnuts, designed to be visually appealing and entertaining for players of all ages.</p><h3>Tech Stack and Tools Used</h3><p>To create this game, I used the following technologies:</p><ul><li><strong>HTML</strong> and <strong>SCSS</strong> for the game’s structure and styling.</li><li><strong>Bootstrap</strong> for responsive design and cross-platform compatibility.</li><li><strong>JavaScript</strong> for the game’s logic and dynamic interactions.</li><li><strong>AWS</strong> for hosting, ensuring reliable performance even under high traffic.</li></ul><h3>Features of the Game</h3><ol><li><strong>Responsive Design</strong><br>The game was designed to be fully responsive, ensuring it worked seamlessly on desktop and mobile devices without compromising the user experience.</li><li><strong>Smooth Animations</strong><br>Using the browser’s requestAnimationFrame API, I ensured the animations were fluid and didn’t strain the device’s resources. This created an immersive gaming experience.</li><li><strong>Dynamic Gameplay</strong><br>The game included a variety of platforms (normal, moving, breakable, and vanishing), a player character with realistic physics (affected by gravity and velocity), and interactive controls for a challenging yet enjoyable experience.</li><li><strong>Cross-Browser Compatibility</strong><br>The game was tested across multiple browsers to ensure a consistent experience, regardless of the user’s choice of platform.</li></ol><h3>Game Development: Under the Hood</h3><p>Here’s a glimpse into the key aspects of the game development:</p><h4>1. Responsive Canvas Setup</h4><p>The game uses an HTML5 &lt;canvas&gt; element to render the game environment dynamically. Setting up the canvas dimensions and adapting it to various screen sizes were crucial steps in ensuring responsiveness.</p><pre>var canvas = document.getElementById(&#39;canvas&#39;),<br>    ctx = canvas.getContext(&#39;2d&#39;);<br><br>var width = 422, height = 552;<br>canvas.width = width;<br>canvas.height = height;</pre><h4>2. Smooth Animations with requestAnimationFrame</h4><p>Animations were optimized using the requestAnimationFrame API to reduce flickering and deliver seamless transitions.</p><pre>window.requestAnimFrame = (function() {<br>  return window.requestAnimationFrame || <br>         window.webkitRequestAnimationFrame || <br>         window.mozRequestAnimationFrame || <br>         function(callback) {<br>           window.setTimeout(callback, 1000 / 60);<br>         };<br>})();</pre><h4>3. Platform Variety</h4><p>To make the gameplay engaging, I introduced multiple platform types:</p><ul><li><strong>Normal platforms</strong> for regular jumps.</li><li><strong>Moving platforms</strong> to add a dynamic challenge.</li><li><strong>Breakable platforms</strong> that disappear after use.</li><li><strong>Vanishable platforms</strong> for unpredictable gameplay.</li></ul><p>The type of platform was determined by the player’s score, ensuring the difficulty scaled progressively.</p><h4>4. Physics-Based Player Movement</h4><p>Player movement was powered by simple physics, with velocity and gravity affecting jumps and falls.</p><pre>player.vy = 11; // Vertical velocity<br>player.jump = function() {<br>  this.vy = -8.7; // Adjust jump height<br>};<br>player.y += player.vy;<br>player.vy += gravity;</pre><h4>5. Event Handling for Interactivity</h4><p>The game featured keyboard controls to enhance interactivity, allowing players to move left, right, or jump.</p><pre>document.onkeydown = function(e) {<br>  if (e.keyCode == 37) player.isMovingLeft = true;  // Left arrow<br>  if (e.keyCode == 39) player.isMovingRight = true; // Right arrow<br>};</pre><h3>Challenges and Solutions</h3><ul><li><strong>Responsive Design:</strong> Ensuring the game adapted seamlessly to both small and large screens was a priority. This was tackled using <strong>Bootstrap</strong> and CSS media queries.</li><li><strong>Smooth Animations:</strong> Managing performance was critical, especially for mobile devices. By leveraging requestAnimationFrame, I reduced lag and ensured smooth frame rates.</li><li><strong>Hosting and Scalability:</strong> Hosting on <strong>AWS</strong> allowed the game to handle large numbers of concurrent users, ensuring stability and reliability.</li></ul><h3>Takeaways from the Project</h3><ol><li><strong>Cross-Platform Compatibility:</strong> Building a responsive game reinforced the importance of testing on multiple devices and browsers.</li><li><strong>User-Centered Design:</strong> Prioritizing the user experience helped me design a game that was easy to play yet challenging enough to keep players engaged.</li><li><strong>Scalable Hosting:</strong> Deploying on AWS taught me the significance of robust hosting for dynamic web applications.</li></ol><h3>Final Thoughts</h3><p>Developing this game was an exhilarating experience, blending creativity with technical expertise. The overwhelmingly positive feedback from users made the hard work worthwhile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*R72rHd3dYmMS8Dz7AYnVPw.jpeg" /></figure><p>If you’re a developer or someone passionate about web games, I’d love to hear your thoughts on this project. Let’s connect and exchange ideas on how to make web games even more engaging!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06b674ef4f73" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>