<?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: Mr. Linxed</title>
    <description>The latest articles on DEV Community by Mr. Linxed (@mrlinxed).</description>
    <link>https://dev.to/mrlinxed</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%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png</url>
      <title>DEV Community: Mr. Linxed</title>
      <link>https://dev.to/mrlinxed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrlinxed"/>
    <language>en</language>
    <item>
      <title>Nexus - An analytics tool for Threads</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Fri, 16 Aug 2024 05:37:55 +0000</pubDate>
      <link>https://dev.to/mrlinxed/nexus-an-analytics-tool-for-threads-1605</link>
      <guid>https://dev.to/mrlinxed/nexus-an-analytics-tool-for-threads-1605</guid>
      <description>&lt;p&gt;TL;DR: If you don't feel like reading all of this and just want to try out the app. Scroll to the end.&lt;/p&gt;




&lt;p&gt;A couple of weeks ago I decided to try out &lt;a href="https://nexus.mrlinxed.com/" rel="noopener noreferrer"&gt;Threads&lt;/a&gt;. Which in case you've been living under a rock, is Meta's attempt at making a competitor for Twitter/X. &lt;/p&gt;

&lt;p&gt;And so far I am having a great time over there. The vibe seems to be much friendlier than on Twitter/X and there are actually interesting discussions going on.&lt;/p&gt;

&lt;p&gt;However, when I joined there seemed to be missing a very important function and this function is; Analytics.&lt;/p&gt;

&lt;p&gt;It was very hard to see how well my posts were doing. You could click on individual posts and see how many views they got. But that's about it.&lt;/p&gt;

&lt;p&gt;Therefore I decided to make my own tool utilizing their API. I do have to mention here, that in recent days Threads has announced its own Analytics, or as they call it; insights. But this is at the moment not &lt;em&gt;yet&lt;/em&gt; available for everyone. And since I was already quite far into building my tool, I still wanted to share it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The stack
&lt;/h2&gt;

&lt;p&gt;For this project, I chose a stack I am very comfortable with.&lt;/p&gt;

&lt;p&gt;As my back-end/API, I am using ExpressJS with Typeorm and Zod on Node.&lt;br&gt;
And for the front end, I use Vue with Pinia bundled with Vite.&lt;/p&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;I've implemented a few features for now, but not everything I want to make eventually. It was important to me to get a test version out for people to use and provide me with some early feedback.&lt;/p&gt;
&lt;h3&gt;
  
  
  Basic insights
&lt;/h3&gt;

&lt;p&gt;This was the first feature I implemented. It shows your username with followers. And below that, you'll find 5 important stats over your overall Threads account. Compared to the previous 7 days. It's nice to see how you're doing compared to past periods. &lt;/p&gt;

&lt;p&gt;One thing I will still add to this is the option to select your own period instead of having it fixed to 7 days.&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%2Fupvyu9umjr0az2srgj8j.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%2Fupvyu9umjr0az2srgj8j.png" alt="Basic Statistics" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Activity Tracker
&lt;/h3&gt;

&lt;p&gt;Inspired by GitHub's activity graph, I've implemented my own. This currently only counts your posts, not replies. This is because Threads seem to treat these as different things and you need to call 2 different endpoints to get this information.&lt;/p&gt;

&lt;p&gt;I added a little disclaimer that it can be slow to load. Because this graph has to load in all your posts of last year. On my shortlist, I have written that I will improve this by saving into a DB the post counts into a DB. Usually, post counts don't change anymore for days in the past. This way I only have to check occasionally if something has changed, and this can be done asynchronous from user interaction&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%2Fmw2y3mug6qhe2nd693bl.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%2Fmw2y3mug6qhe2nd693bl.png" alt="Activity Tracker" width="800" height="273"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Demographics
&lt;/h3&gt;

&lt;p&gt;Another useful feature is the ability to see who follows you. Other info that I'll add at a later date are the top 10 countries and top 10 cities.&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%2Fc9fb6f5av937gmpjk2g7.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%2Fc9fb6f5av937gmpjk2g7.png" alt="Demographics" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Threads list
&lt;/h3&gt;

&lt;p&gt;Last, but not least. A list of your own Threads sorted by most recent first. Where each post shows immediately how many views it has and the other common stats.&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%2Fkpiqocnnyz9hq1550hpk.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%2Fkpiqocnnyz9hq1550hpk.png" alt="Thread Example" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Dark mode
&lt;/h3&gt;

&lt;p&gt;Initially, I made this application exclusively in light mode. But I kept being annoyed at it every time I was working on it during evenings. Switching from my dark editor to the light screen was frustrating. So I quickly added dark mode.&lt;/p&gt;

&lt;p&gt;Luckily this was quite simple as my components are few and quite simple.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use it.
&lt;/h2&gt;

&lt;p&gt;Right now, I will still need to manually add you to the list of testers. You need a Threads account for this. Drop your username in the comments, or &lt;a href="https://www.threads.net/@mrlinxed" rel="noopener noreferrer"&gt;ping me on Threads&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, you'll need to accept the invite in your Threads App: &lt;br&gt;
&lt;code&gt;Settings &amp;gt; Account &amp;gt; Website Permissions &amp;gt; Invitations&lt;/code&gt;&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%2Fxy6un4xegqz3mzcffy6b.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%2Fxy6un4xegqz3mzcffy6b.png" alt="The permissions modal" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, you can head towards &lt;a href="https://nexus.mrlinxed.com/" rel="noopener noreferrer"&gt;https://nexus.mrlinxed.com/&lt;/a&gt; and start using it!&lt;/p&gt;

&lt;p&gt;I am aware it's a bit annoying however, Threads recommends having your app feature complete before submitting it and having it approved, as it might disapprove incomplete apps.&lt;/p&gt;

&lt;p&gt;If you are willing to help me test it and provide feedback; thank you so much. I appreciate it a lot.&lt;/p&gt;

&lt;p&gt;That's it for now, have a lovely day!&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up for my newsletter&lt;/a&gt; to be the first to know about updates for Nexus and other future projects.&lt;/p&gt;

</description>
      <category>socialmedia</category>
      <category>showdev</category>
      <category>softwaredevelopment</category>
      <category>vue</category>
    </item>
    <item>
      <title>I added an RSS Feed – You Should Too!</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Thu, 01 Aug 2024 08:00:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/i-added-an-rss-feed-you-should-too-26bo</link>
      <guid>https://dev.to/mrlinxed/i-added-an-rss-feed-you-should-too-26bo</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;RSS feeds, aren't those like from 2005? &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I hear you ask. And I guess in a way you are right! But hear me out okay!&lt;/p&gt;

&lt;p&gt;Let's start with what an RSS feed is.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an RSS feed?
&lt;/h2&gt;

&lt;p&gt;RSS stands for "Really Simple Syndication".. whatever that means. It's simply put, an XML feed with all your latest posts. And the user can use it to quickly and periodically check if you have new content on your website. You can almost compare it with a sitemap.&lt;/p&gt;

&lt;p&gt;Even GitHub provides RSS feeds for repositories, so you can be updated on releases, commits or issues!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why would you still use it?
&lt;/h2&gt;

&lt;p&gt;There are still plenty of tools out there that utilize RSS feeds from various websites. Including a bunch of tools where a user can combine RSS feeds from multiple websites they want to follow and they'll get updates whenever there is a new post on any of them. &lt;/p&gt;

&lt;p&gt;You could see it as a social media feed but with blog posts&lt;/p&gt;

&lt;p&gt;Instead of following your favourite author on &lt;a href="https://www.threads.net/@mrlinxed" rel="noopener noreferrer"&gt;Threads&lt;/a&gt; or &lt;a href="https://x.com/MrLinxed" rel="noopener noreferrer"&gt;X&lt;/a&gt;, and having to deal with a bunch of junk, content that the platform thinks you like or ads. You can curate your feed and only receive what you care about. Quality blog posts.&lt;/p&gt;

&lt;p&gt;Did you know that dev.to also &lt;a href="https://dev.to/feed/mrlinxed"&gt;provides an RSS feed&lt;/a&gt; for individual authors?&lt;/p&gt;

&lt;h2&gt;
  
  
  Is it worth my time to implement?
&lt;/h2&gt;

&lt;p&gt;As with everything... it depends. &lt;/p&gt;

&lt;p&gt;Depending on how complicated your system is, it could range from no effort to some effort.&lt;/p&gt;

&lt;p&gt;If you have a blog on WordPress for example, it's no effort at all, you can add &lt;code&gt;/feed/&lt;/code&gt; at the end of your category, tags and author collections&lt;/p&gt;

&lt;p&gt;I think, if it is little effort for you to add an RSS feed to your site, you should do it.&lt;/p&gt;

&lt;p&gt;After all, it is another way of getting your content in front of more people.&lt;/p&gt;

&lt;p&gt;For me, it took me under 45 minutes to implement it into my site. This is because my site is fully custom. I don't think I wasted this time adding this feature since it is useful, and fun to create and I learned something.&lt;/p&gt;




&lt;p&gt;I hope this has inspired you to also add an RSS feed to your site if you haven't yet.&lt;/p&gt;

&lt;p&gt;And if you're a person who uses RSS feeds, feel free to &lt;a href="https://mrlinxed.com/rss.xml" rel="noopener noreferrer"&gt;add mine&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Space Defender - part 5 - Game States</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Jul 2024 14:25:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/space-defender-part-5-game-states-404c</link>
      <guid>https://dev.to/mrlinxed/space-defender-part-5-game-states-404c</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/mrlinxed/space-defender-part-4-adding-a-hud-300c"&gt;the previous post&lt;/a&gt; we've made use of the HUD and now our game is basically done, but it's missing a few things. We need to add a game over screen with a way to restart the game. We also want to add a screen when you just started the game, instead of just starting the game right away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Game States
&lt;/h2&gt;

&lt;p&gt;We're going to add a few game states to our game. We're going to have a &lt;code&gt;gameState&lt;/code&gt; enum that will hold the different states of the game. We'll also have a variable that holds the current state of the game.&lt;/p&gt;

&lt;p&gt;Add the following code right at the beginning of your &lt;code&gt;main.ts&lt;/code&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PLAYING&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PAUSED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GAME_OVER&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PAUSED&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code creates an enum called &lt;code&gt;gameStates&lt;/code&gt; that holds the different states of the game. We then create a variable called &lt;code&gt;gameState&lt;/code&gt; that holds the current state of the game. We set the initial state to &lt;code&gt;PAUSED&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Before we do anything with these states, we need a reset function. This function will be called right before we start the game. Add the following code to the bottom of your &lt;code&gt;main.ts&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resetGame&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;lives&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLives&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lives&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLevel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameScore&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setEnemySpawnInterval&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;spawnEnemy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This will set all the values to their initial starting values, clear the bullets and enemies from the stage and the arrays, reset the player's position, and set the enemy spawn interval. Then start the game by spawning an enemy.&lt;/p&gt;

&lt;p&gt;Now that that's set, let's add a way to start the game.&lt;/p&gt;
&lt;h2&gt;
  
  
  Starting the game
&lt;/h2&gt;

&lt;p&gt;We're going to add a new KeyHandler for that. Add the following code right after where we defined the KeyHandler for the left and right arrow keys:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nc"&gt;KeyHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAYING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GAME_OVER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;resetGame&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAYING&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nf"&gt;togglePauseText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code will start the game when the player presses the Enter key. If the game is not in the &lt;code&gt;PLAYING&lt;/code&gt; state, it will set the game state to &lt;code&gt;PLAYING&lt;/code&gt;. If the game is in the &lt;code&gt;GAME_OVER&lt;/code&gt; state, it will reset the game and then set the game state to &lt;code&gt;PLAYING&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But the player wouldn't know this, so we need some text to tell the player what to do. Add the following code right after where we defined the KeyHandlers&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// A simple text style, 24px white text&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textsStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;0xFFFFFF&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;startGameText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Press enter to start the game&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;textsStyle&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;togglePauseText&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PAUSED&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GAME_OVER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Since the text can change, we need to reposition it.&lt;/span&gt;
        &lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;togglePauseText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code creates a new text object that says "Press enter to start the game" and positions it in the middle of the screen. It then creates a function called &lt;code&gt;togglePauseText&lt;/code&gt; that will show or hide the text based on the current game state. It then calls this function to show the text when the game is paused or over.&lt;/p&gt;

&lt;p&gt;Now, we would also like to pause the game.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pausing the game
&lt;/h2&gt;

&lt;p&gt;Add the following code right after where we defined the KeyHandler for the left and right arrow keys:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nc"&gt;KeyHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Escape&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PAUSED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PAUSED&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Press enter to resume the game&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nf"&gt;togglePauseText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In this code we'll set the &lt;code&gt;gameState&lt;/code&gt; to &lt;code&gt;PAUSED&lt;/code&gt; when the player presses the Escape key. We'll also reuse the &lt;code&gt;startGameText&lt;/code&gt; object and set the text to "Press enter to resume the game".&lt;/p&gt;
&lt;h2&gt;
  
  
  Using the game states
&lt;/h2&gt;

&lt;p&gt;Great, now that we can toggle between &lt;code&gt;PLAYING&lt;/code&gt; and &lt;code&gt;PAUSED&lt;/code&gt; states, let's actually use these states, and have the game act accordingly.&lt;/p&gt;

&lt;p&gt;If we're not in the &lt;code&gt;PLAYING&lt;/code&gt; state, we don't want to set the playerSpeed when the player presses the left or right arrow keys. Add the following code into the KeyHandlers where we set the &lt;code&gt;playerSpeedX&lt;/code&gt; to 500 or -500 for the left and right arrow keys:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAYING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Also add the above code into the handler for the spacebar KeyHandler, so that the player can't shoot when the game is paused or over.&lt;/p&gt;

&lt;p&gt;Next, update the if statement in the spawnEnemy function to look like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasFocus&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAYING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And finally, the whole game loop doesn't need to fire if we're paused, add the following code right at the beginning of the game loop:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAYING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Game Over
&lt;/h2&gt;

&lt;p&gt;Now that we have a way to start and pause the game, let's add a game over screen.&lt;/p&gt;

&lt;p&gt;Where now we have a &lt;code&gt;console.log("Game Over")&lt;/code&gt;, we want to set the game state to &lt;code&gt;GAME_OVER&lt;/code&gt; and show a game over text. Replace the &lt;code&gt;console.log&lt;/code&gt; with the following code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;gameState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameStates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GAME_OVER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;startGameText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Press enter to restart the game&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;scoreText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Score: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;scoreText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;scoreText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameOverText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;togglePauseText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scoreText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code is using two more text objects that we haven't created that yet, lets do that.&lt;/p&gt;

&lt;p&gt;Right after where we created the &lt;code&gt;startGameText&lt;/code&gt; object, add the following code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gameOverText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GAME OVER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;textsStyle&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;gameOverText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;gameOverText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;gameOverText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;scoreText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Score: 0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;textsStyle&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;scoreText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now, we should be able to play the game, pause it, and restart it when we lose.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And that's it! You can now play the game, pause it, and restart it when you lose.&lt;/p&gt;

&lt;p&gt;I am aware that this last part might have been a bit overwhelming, but I hope you managed to follow along and understand everything, don't forget you can always check out the &lt;a href="https://github.com/MrLinxed/pixi-space-defender-game" rel="noopener noreferrer"&gt;full source code&lt;/a&gt;. If you have any questions or feedback, feel free to reach out to me on &lt;a href="https://x.com/MrLinxed" rel="noopener noreferrer"&gt;X&lt;/a&gt; or leave a comment below&lt;/p&gt;



&lt;p&gt;And this is the final part of this small series, I hope you enjoyed it and learned something new. A small thing I'd like to point out while leaving you with this, is that this is a very basic game, and there are many ways to improve it. You could add more enemies, power-ups, different levels, and so on. I encourage you to experiment and try new things, that's how you learn and grow as a developer.&lt;/p&gt;

&lt;p&gt;Also, the way this game is structured is not the best way to structure a game, but for the purpose of this tutorial, I wanted to keep it simple and in one file. In a future tutorial, I might show you how to structure a game in a more scalable way.&lt;/p&gt;

&lt;p&gt;Thank you for reading all the way through this tutorial!&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up to my newsletter&lt;/a&gt; to be the first to know about tutorials similar to these.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Space Defender - part 4 - Adding a HUD</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Jul 2024 14:20:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/space-defender-part-4-adding-a-hud-300c</link>
      <guid>https://dev.to/mrlinxed/space-defender-part-4-adding-a-hud-300c</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/mrlinxed/space-defender-part-3-the-enemies-11o3"&gt;the previous part&lt;/a&gt; we created the enemies and shot them down. In this part we'll add a HUD (Heads Up Display) to show the player's lives, level, and score.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a HUD
&lt;/h2&gt;

&lt;p&gt;We're going to add a HUD to the game. This will show the player's lives, level, and score. We'll use a simple HTML structure for this, and some CSS to make it look nice.&lt;br&gt;
In bigger games the HUD is usually part of the game canvas, but for this tutorial we'll keep it separate to keep things simple.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://dev.to/mrlinxed/space-defender-part-1-setting-up-the-project-3hfk"&gt;part 1&lt;/a&gt; we already added all the HTML and CSS. So we don't need to do that again. Now we'll just need to update the values in the HUD.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the update function
&lt;/h2&gt;

&lt;p&gt;To do this we'll create a new helper function that we'll use to write out values to the HUD. Add the following code to the bottom of your &lt;code&gt;main.ts&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This function takes two arguments, the id of the element we want to update and the value we want to set it to. It then finds the element by id and sets the inner text to the value.&lt;/p&gt;
&lt;h2&gt;
  
  
  Starting values
&lt;/h2&gt;

&lt;p&gt;We also need to set the starting values for the player's lives, level, and score. Add the following code right after where you defined the &lt;code&gt;bullets&lt;/code&gt; array:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lives&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLives&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lives&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLevel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameScore&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code sets the starting values for the player's lives, level, and score. It then updates the HUD with these values.&lt;/p&gt;
&lt;h2&gt;
  
  
  Updating our lives
&lt;/h2&gt;

&lt;p&gt;Now we'll update the lives value when the player fails to shoot down the enemy and the enemy reaches the bottom of the screen.&lt;br&gt;
In our gameloop, where we check if the enemy is off the screen, update the code to look like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// New code&lt;/span&gt;
    &lt;span class="nx"&gt;lives&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLives&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lives&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// End new code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And at the end of the gameloop we'll add this piece of code as a placeholder for when we have a proper game over state&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lives&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Game Over&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Right now the game doesn't actually end when we run out of lives, but we'll fix that in the next part.&lt;/p&gt;
&lt;h2&gt;
  
  
  Updating the score
&lt;/h2&gt;

&lt;p&gt;We're going to give the player 100 points for every enemy they shoot down. In the part where we check if a bullet hits an enemy, update the code to look like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// New code&lt;/span&gt;
    &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Starts at 100&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameScore&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// End new code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code will give the player 100 points for every enemy they shoot down. The score is then updated and the HUD is updated with the new score.&lt;br&gt;
This also includes a bit of logic that when the level goes up, the player gets more points for shooting down an enemy.&lt;/p&gt;
&lt;h2&gt;
  
  
  Updating the level
&lt;/h2&gt;

&lt;p&gt;The level goes up every time the player reaches a certain score. The level is also what makes the game harder over time. Add the following code to the end of the gameloop:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// The score requirement gets higher every level&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setHudValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gameLevel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setEnemySpawnInterval&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The first level requires 1000 points to reach. Every level after that requires 100 more points than the previous level.&lt;br&gt;
To make the game actually harder as the levels go up, we'll also call a method called &lt;code&gt;setEnemySpawnInterval&lt;/code&gt; that we'll create in a bit.&lt;/p&gt;

&lt;p&gt;Find the follow line of code: &lt;code&gt;setInterval(spawnEnemy, enemySpawnInterval);&lt;/code&gt;&lt;br&gt;
And replace it with this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setEnemySpawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;spawnInterval&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;spawnInterval&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Starts at 1 enemy every 2.5 seconds&lt;/span&gt;
    &lt;span class="nx"&gt;spawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;spawnEnemy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;enemySpawnInterval&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;setEnemySpawnInterval&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code will clear the current interval and set a new one with a shorter interval every time the level goes up. This will make the game harder over time.&lt;br&gt;
Because of this the game will be impossible at a certain point as enemies will spawn too fast. But that's okay for this game.&lt;/p&gt;

&lt;p&gt;And that's it! You now have a game where you can move left and right, shoot bullets, and shoot down enemies. And you have a HUD that shows the player's lives, level, and score. &lt;/p&gt;

&lt;p&gt;In &lt;a href="https://dev.to/mrlinxed/space-defender-part-5-game-states-404c"&gt;the next part&lt;/a&gt; we're going to add some state to the game and make it so that the game actually ends when the player runs out of lives.&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up to my newsletter&lt;/a&gt; to be the first to know about tutorials similar to these.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Space Defender - part 3 - the enemies</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Jul 2024 14:15:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/space-defender-part-3-the-enemies-11o3</link>
      <guid>https://dev.to/mrlinxed/space-defender-part-3-the-enemies-11o3</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/mrlinxed/space-defender-part-2-the-player-13e6"&gt;the last part&lt;/a&gt; we created the player's ship and made it move. In this part we'll create the enemies and make them move. And then we'll shoot them down!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the enemies
&lt;/h2&gt;

&lt;p&gt;We're going to do something similar as when we created the bullets. We're going to create a template enemy that we'll clone every time we want to create a new enemy. We also need to keep track of the enemies via an array because there can be more than one at the same time.&lt;/p&gt;

&lt;p&gt;But first, we'll create the method that creates the enemy. Add the following code after the &lt;code&gt;createBullet&lt;/code&gt; method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;enemyTemplate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createEnemy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;enemyTemplate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;enemyTemplate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;enemyTemplate&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;poly&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
                &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xFF6666&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enemyTemplate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;480&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;As you can see, it's pretty similar to the &lt;code&gt;createBullet&lt;/code&gt; method. We create a template enemy that we clone every time we want to create a new enemy. We then position the enemy at a random x position at the top of the screen. The enemy has the same shape as the player's ship, but it's red and upside down.&lt;/p&gt;

&lt;p&gt;We specify the spawn location of the enemy by setting the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; properties. The &lt;code&gt;x&lt;/code&gt; property is set to a random value between 25 and 480 - 50, so that the enemy is always within the game screen. The &lt;code&gt;y&lt;/code&gt; property is set to -50, so that the enemy is just outside the screen, and will move into it.&lt;/p&gt;

&lt;p&gt;Next up, we need to call this method to create a new enemy every few seconds.&lt;/p&gt;
&lt;h2&gt;
  
  
  Spawning enemies
&lt;/h2&gt;

&lt;p&gt;We'll use the &lt;code&gt;setInterval&lt;/code&gt; method for this. Add the following code right after where we defined the &lt;code&gt;bullets&lt;/code&gt; array:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemySpawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;spawnEnemy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasFocus&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createEnemy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;spawnEnemy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;enemySpawnInterval&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;spawnEnemy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We create a new array called &lt;code&gt;enemies&lt;/code&gt; to keep track of all the enemies. We then create a new variable called &lt;code&gt;enemySpawnInterval&lt;/code&gt; that specifies how often we want to spawn a new enemy. We then create a new method called &lt;code&gt;spawnEnemy&lt;/code&gt; that creates a new enemy and adds it to the &lt;code&gt;enemies&lt;/code&gt; array and the stage. We then call this method every &lt;code&gt;enemySpawnInterval&lt;/code&gt; milliseconds using the &lt;code&gt;setInterval&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Cool, now we have enemies spawning at the top of the screen every 2.5 seconds. But they're not moving yet, and we don't see them because they're out of the screen. Let's fix that.&lt;/p&gt;
&lt;h2&gt;
  
  
  Moving the enemies
&lt;/h2&gt;

&lt;p&gt;We need to update the enemies' position in the game loop. Add the following code to your game loop, right under where we update the bullets' position:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This part of the code will loop over all the enemies, update their position by moving them down 2.5 pixels and check if they are out of bounds. If they are, we remove them from the stage and the enemies array.&lt;/p&gt;

&lt;p&gt;Nice! if you run your game now you'll see enemies spawning at the top of the screen and moving down.&lt;/p&gt;

&lt;p&gt;Now it's time to shoot them down!&lt;/p&gt;
&lt;h2&gt;
  
  
  Shooting the enemies
&lt;/h2&gt;

&lt;p&gt;Add the following code to your game loop, right under where we update the enemies position:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bullet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;enemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This part of the code will loop over all the bullets and all the enemies and check if a bullet hits an enemy. If it does, we remove both the bullet and the enemy from the stage and their respective arrays.&lt;/p&gt;

&lt;p&gt;You could optimize this code by breaking out of the inner loop when a bullet hits an enemy, but for now, this is fine. You could also combine the bullet position update loop with the bullet hit check loop, but I like to keep them separate for clarity of this tutorial.&lt;/p&gt;

&lt;p&gt;And that's it! You now have a game where you can move left and right, shoot bullets, and shoot down enemies. In &lt;a href="https://dev.to/mrlinxed/space-defender-part-4-adding-a-hud-300c"&gt;the next part&lt;/a&gt;, we're going to add some HUD elements to the game and keep track of the player's score, level and lives.&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up to my newsletter&lt;/a&gt; to be the first to know about tutorials similar to these.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Space Defender - part 2 - the player</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Jul 2024 14:10:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/space-defender-part-2-the-player-13e6</link>
      <guid>https://dev.to/mrlinxed/space-defender-part-2-the-player-13e6</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/mrlinxed/space-defender-part-1-setting-up-the-project-3hfk"&gt;previous part&lt;/a&gt; we created the basic structure for our game. In this part we'll start creating the player's ship and make it move and shoot.&lt;/p&gt;

&lt;p&gt;The final source code can be found in &lt;a href="https://github.com/MrLinxed/pixi-space-defender-game" rel="noopener noreferrer"&gt;my GitHub repository&lt;/a&gt;&lt;br&gt;
And if you want to play the game, you can find it &lt;a href="https://mrlinxed.com/project/pixi-space-defender-game" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up the keyboard
&lt;/h2&gt;

&lt;p&gt;Before we start setting up our player, we need a way to handle keyboard events. For this I've used the keyboard controller found on a PixiJS tutorial from &lt;a href="https://github.com/kittykatattack/learningPixi?tab=readme-ov-file#keyboard-movement" rel="noopener noreferrer"&gt;kittykatattack&lt;/a&gt; and adapted it to TypeScript.&lt;br&gt;
You can find it on &lt;a href="https://github.com/MrLinxed/pixi-space-defender-game/commit/e5110326eb89d687d250ef14d5e66ac8f2b0cdce" rel="noopener noreferrer"&gt;my GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We won't go in-depth into how it works, because that is out of the scope of this project, but what it does is listen for keydown and keyup events and sets a boolean value for each key that is pressed or released. This way we can check in our game loop if a key is pressed or let go, and update our players behavior accordingly.&lt;/p&gt;

&lt;p&gt;To use the keyboard controller, download the &lt;code&gt;keyboard.ts&lt;/code&gt; file from the commit above and place it in the &lt;code&gt;src/helpers&lt;/code&gt; folder of your project.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the player
&lt;/h2&gt;

&lt;p&gt;Now that we have a way to handle keyboard events, we can start creating our player. In a future tutorial we'll make a more complex game and split up our project in multiple files. For now, we'll stick to one file.&lt;/p&gt;

&lt;p&gt;Right after where you've initialized your PixiJS application &lt;code&gt;await app.init({&lt;/code&gt; in the &lt;code&gt;main.ts&lt;/code&gt; file, add the following code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Player&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;Player&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;poly&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
        &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x66CCFF&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;What this will do is create a new Graphics object, draw a triangle with the &lt;code&gt;poly&lt;/code&gt; method, fill it with a light blue color and position it at the bottom of the screen.&lt;/p&gt;

&lt;p&gt;If you start your game now you'll see a small triangle at the bottom of the screen. But we want to be able to move it around. To do this we need to update the player's position based on the keyboard input.&lt;/p&gt;
&lt;h2&gt;
  
  
  Moving the player
&lt;/h2&gt;

&lt;p&gt;First we'll need to capture the keyboard input. Add the following code right after where we created our player:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowLeftHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ArrowLeft&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// To prevent player from stopping moving if the other arrow key is pressed&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;arrowRightHandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowRightHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ArrowRight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// To prevent player from stopping moving if the other arrow key is pressed&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;arrowLeftHandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;What this code does is create two KeyHandlers, one for the left arrow key and one for the right arrow key. When the key is pressed, the player's speed on the x-axis is set to -500 or 500. When the key is released, the player's speed is set to 0. This way we can move the player left and right.&lt;/p&gt;

&lt;p&gt;This on it's own wont move the player, we need to update the player's position in the game loop. Replace the &lt;code&gt;app.ticker.add&lt;/code&gt; call with the following code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;delta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ticker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deltaTime&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;playerSpeedX&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you didn't have the &lt;code&gt;app.ticker.add&lt;/code&gt; call in your code, you can just add it right after where you defined the KeyHandlers.&lt;/p&gt;

&lt;p&gt;Now if you start your game you'll be able to move the player left and right. Great! Let's make it shoot.&lt;/p&gt;
&lt;h2&gt;
  
  
  Shooting
&lt;/h2&gt;

&lt;p&gt;There are three things we need to think about when we want to make the player shoot:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the player presses the spacebar, we want to create a new bullet.&lt;/li&gt;
&lt;li&gt;We want to update the bullet's position in the game loop.&lt;/li&gt;
&lt;li&gt;We want to remove the bullet when it goes out of bounds.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So we need a method that creates a bullet, add it to an array of bullets, updates the bullets position via the game loop and then remove it if it's out of bounds.&lt;/p&gt;

&lt;p&gt;Let's start with a method that creates the bullet, add the following code at the bottom of your &lt;code&gt;main.ts&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;bulletTemplate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createBullet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;bulletTemplate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;bulletTemplate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;bulletTemplate&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xFFCC66&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bullet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bulletTemplate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Creating a new Graphics object every time we want to create a bullet is expensive, so we create a template bullet that we clone every time we want to create a new bullet. Cloning is cheaper than creating a new object every time.&lt;/p&gt;

&lt;p&gt;We then use the source (who shot the bullet) to position the bullet at the right place, and then return the graphics object.&lt;/p&gt;

&lt;p&gt;Okay, so currently, this method isn't being used and nothing is being drawn to the screen. Let's fix that.&lt;/p&gt;

&lt;p&gt;We're going to make it so that the player can shoot by pressing space bar, we'll use the KeyHandler for this again. To tell the KeyHandler to use the spacebar, we'll have to give it &lt;code&gt;" "&lt;/code&gt; as the key.&lt;/p&gt;

&lt;p&gt;Add the following code right after where we defined the KeyHandlers for the left and right arrow keys:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nc"&gt;KeyHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bullet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBullet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Player&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code will create a new bullet when the spacebar is pressed, add it to an array of bullets and add it to the stage, so that we'll see it.&lt;/p&gt;

&lt;p&gt;We didn't have the &lt;code&gt;bullets&lt;/code&gt; array yet, so let's add that right after where we defined the &lt;code&gt;Player&lt;/code&gt; object:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now if you start your game you'll be able to move the player left and right and shoot bullets. But the bullets will stay on the screen forever. Let's fix that.&lt;br&gt;
In the gameloop we'll update the bullets position and remove them if they go out of bounds. Add the following code to your game loop, right under where we update the player's position:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bullet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;bullets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This part of the code will loop over all the bullets, update their position by moving them up 10 pixels and check if they are out of bounds. If they are, we remove them from the stage and the bullets array.&lt;/p&gt;

&lt;p&gt;And that's it! You now have a player that can move left and right and shoot bullets. In &lt;a href="https://dev.to/mrlinxed/space-defender-part-3-the-enemies-11o3"&gt;the next part&lt;/a&gt; we'll create enemies and shoot them down!&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up to my newsletter&lt;/a&gt; to be the first to know about tutorials similar to these.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Space Defender - part 1 - setting up the project</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Jul 2024 14:05:00 +0000</pubDate>
      <link>https://dev.to/mrlinxed/space-defender-part-1-setting-up-the-project-3hfk</link>
      <guid>https://dev.to/mrlinxed/space-defender-part-1-setting-up-the-project-3hfk</guid>
      <description>&lt;p&gt;In a &lt;a href="https://dev.to/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l"&gt;previous post&lt;/a&gt; I showed you how to set up a PixiJS project with Vite and TypeScript. In this post, we will create a simple space defender game building on top of that setup.&lt;/p&gt;

&lt;p&gt;For this project I assume you have a basic knowledge of how to program in TypeScript/JavaScript. And because we're focusing on PixiJS I won't focus too much on the HTML/CSS side of things.&lt;/p&gt;

&lt;p&gt;The final source code can be found in &lt;a href="https://github.com/MrLinxed/pixi-space-defender-game" rel="noopener noreferrer"&gt;my GitHub repository&lt;/a&gt; and if you want to play the game, you can find it &lt;a href="https://mrlinxed.com/project/pixi-space-defender-game" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the project
&lt;/h2&gt;

&lt;p&gt;If you haven't set up a PixiJS project with Vite and TypeScript yet, I recommend you to read my &lt;a href="https://dev.to/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l"&gt;previous post&lt;/a&gt; first in which I explain how to set it up and get it to run.&lt;/p&gt;

&lt;p&gt;Let's quickly setup the &lt;code&gt;index.html&lt;/code&gt; file with the content that we need for this project. Replace the content of the &lt;code&gt;&amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; element with the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"gameHud"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            Lives: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"gameLives"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            Level: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"gameLevel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            Score: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"gameScore"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"game"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This will be the structure of our game, we have a HUD (Heads Up Display) that will show the player's lives, level, and score. And a game container where we will render the game. In &lt;a href="https://dev.to/mrlinxed/space-defender-part-4-adding-a-hud-300c"&gt;part 4&lt;/a&gt; we'll start making use of this.&lt;/p&gt;

&lt;p&gt;Next up, we need to apply some CSS to this so that it's nicely displayed on the screen. Navigation to the stylesheet called &lt;code&gt;styles.css&lt;/code&gt; in the &lt;code&gt;src&lt;/code&gt; folder and add the following content:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;darkgrey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#app&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;480px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#gameHud&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;div&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Preparing the game screen
&lt;/h2&gt;

&lt;p&gt;Great! Now that we have the basic structure in place, let's start by creating the game screen. We need to have a variable that holds the game container element so that the game knows where to insert the game canvas into the DOM.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;


&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gameContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// ....&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After that we need to update our app size to match the game size we want, in our case we want a game that is 480 wide and 720 high. So we need to update the &lt;code&gt;app.init&lt;/code&gt; call to match that size.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;480&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;720&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And then replace&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;gameContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We now have a game screen that is 480x720 pixels in size and is displayed in the center of the screen.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/mrlinxed/space-defender-part-2-the-player-13e6"&gt;next part&lt;/a&gt; we'll start creating the player's ship and make it move and shoot.&lt;/p&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;PixiJS Setup with Vite and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Apr 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;Don't forget to &lt;a href="https://mrlinxed.com/newsletter" rel="noopener noreferrer"&gt;sign up to my newsletter&lt;/a&gt; to be the first to know about tutorials similar to these.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>PixiJS Setup with Vite and TypeScript</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sat, 20 Apr 2024 18:53:34 +0000</pubDate>
      <link>https://dev.to/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l</link>
      <guid>https://dev.to/mrlinxed/pixijs-setup-with-vite-and-typescript-m6l</guid>
      <description>&lt;p&gt;While trying to get started with PixiJS I noticed there was no great guide to setup PixiJS with a bundler. So after a bit of fiddling, I came up with a nice setup. It uses Vite as the bundler. Let me share it with you.&lt;/p&gt;

&lt;p&gt;Quick note: This is just a bare minimum basic setup, and might not be the best fit for your project. But I still think it will provide a good starting point for your next PixiJS project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Vite
&lt;/h2&gt;

&lt;p&gt;You might know Vite as the bundler for Vue, but that's not the only thing you can use it for. In this case, we'll use it with PixiJS. &lt;/p&gt;

&lt;p&gt;Run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm create vite@latest


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you've never run it before it will prompt you if you want to install Vite, say yes. Then you pick the following options&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; project name: &amp;lt;your-project-name&amp;gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Framework: Vanilla
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Variant: TypeScript &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;you want typescript&lt;span class="o"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can also do all of this in one command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm create vite@latest &amp;lt;your-project-name&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--template&lt;/span&gt; vanilla-ts


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After which you can run the following two commands to install the required packages and start the dev server&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm run dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After this, you can go to &lt;code&gt;http://localhost:5173/&lt;/code&gt; to see your Vite project running.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up PixiJS
&lt;/h2&gt;

&lt;p&gt;Now that Vite is up and running it's time to get PixiJS running.&lt;/p&gt;

&lt;p&gt;First, we'll install PixiJS with npm:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm &lt;span class="nb"&gt;install &lt;/span&gt;pixi.js


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Navigate to &lt;code&gt;src/main.ts&lt;/code&gt; and replace the contents with the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pixi.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PIXI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;640&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you have your dev server still running it should automatically reload your app, otherwise restart the server with &lt;code&gt;npm run dev&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In the browser, you'll see a white page with a black rectangle. This black rectangle is a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; element that PixiJS created for you.&lt;/p&gt;

&lt;p&gt;You are now ready to develop your PixiJS app! Good luck.&lt;/p&gt;



&lt;p&gt;If you're running into issues, drop a comment down below. Alternatively, you can also look at &lt;a href="https://github.com/MrLinxed/vite-ts-pixi-starter-template" rel="noopener noreferrer"&gt;my repository on GitHub&lt;/a&gt; that has this code (plus a bit more) to get you started.&lt;/p&gt;

&lt;p&gt;That's it for now, have a lovely day!&lt;/p&gt;



&lt;p&gt;if you're looking for a way to host your PixiJS app for free, check out my article about hosting web apps on Cloudflare for free.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/host-your-web-app-for-free-on-cloudflare-pages-15en" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Host your web app for free on Cloudflare Pages&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 9&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Code for Change: How Your Coding Skills Can Make a Real Difference in the World</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sun, 03 Mar 2024 10:51:32 +0000</pubDate>
      <link>https://dev.to/mrlinxed/code-for-change-how-your-coding-skills-can-make-a-real-difference-in-the-world-4hoi</link>
      <guid>https://dev.to/mrlinxed/code-for-change-how-your-coding-skills-can-make-a-real-difference-in-the-world-4hoi</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Learning to code is useful no matter what your career ambitions are." - Arianna Huffington&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No matter what age you are, or how you identify as, you should learn to code. If you're unsure why you should learn to code, or if you're already into coding but need some new motivation, read on!&lt;/p&gt;

&lt;h2&gt;
  
  
  A creative outlet
&lt;/h2&gt;

&lt;p&gt;One of the biggest things it can do for you is to be a creative outlet. You might think, how can staring at a screen typing strange-looking documents can be a creative outlet? And that'd be a valid question, it's not the same as drawing or painting. But writing code requires a lot of creativity and problem-solving skills. &lt;/p&gt;

&lt;p&gt;Coding is a way of expressing yourself, it's an art. As an experienced coder, I can tell you that it's a pleasure to look at well-written and well-functioning code. It takes serious creative effort to do this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Become a better thinker
&lt;/h2&gt;

&lt;p&gt;If something takes effort you'll automatically become a better person. As with everything, the more you do it, the better you get at it. Coding is incredible at tickling your brain and making it work a bit harder. This in turn has the added benefit of making you a better thinker. &lt;/p&gt;

&lt;p&gt;First of all, you'll become an expert at solving problems. The way you have to use your brain to tackle certain coding problems can also be applied to solving other real-world problems. &lt;/p&gt;

&lt;p&gt;Second, since writing code is all about logic your logical thinking and reasoning will improve massively. You'll start seeing life in a bunch of "if else's".&lt;/p&gt;

&lt;p&gt;Last but not least, your critical thinking will improve. &lt;/p&gt;

&lt;h2&gt;
  
  
  Understand the world around you a bit better
&lt;/h2&gt;

&lt;p&gt;Becoming a better thinker will help you understand the world around you better. You'll start asking more questions about why things are the way they are. Because you're so used to thinking deeper than just the surface level. &lt;/p&gt;

&lt;p&gt;But even if we just think about the technology in this world. Learning how to code will help you understand technology better. If you're coding a website, you'll learn how the internet works, you might learn how websites are tracking you, and you can learn how to protect yourself and the people around you from it. If you're developing a game, you'll gain some new respect for the games out there right now, the tech behind it, and the people who made it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change the world
&lt;/h2&gt;

&lt;p&gt;You have likely had dreams and goals related to changing the world. With coding, you can make a lasting impact on other people's lives even from the comfort of your own home. Maybe you develop a small tool that someone needs. Maybe you'll develop a fun little game that brightens someone's day. Or maybe you'll work on something bigger, like the next breakthrough in artificial intelligence usage for detecting early stages of cancer development. You could save someone's life. &lt;/p&gt;

&lt;p&gt;No matter how big or small your projects are, they can and will help someone out eventually.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrade your career
&lt;/h2&gt;

&lt;p&gt;It doesn't matter what career you are in, learning how to code has enormous effects on it because it changes the way you think. You might be able to utilize your new coding skills to automate certain processes, leaving you time to do other things. Either more free time for yourself or more free time to work on other things and make you a better employee. This could lead to bigger pay or a new promotion. Or if you want, switch jobs together in the world of tech.&lt;/p&gt;




&lt;p&gt;Overall, you'll find that learning to code will have enormous effects on your life and everything you do. It doesn't matter what you do, where you're from or what you look like, if you can find a bit of time every day or every other day to learn to code you'll find that it will benefit you in the long term.&lt;/p&gt;

&lt;p&gt;I hope this post has inspired you to pick up coding as a hobby, or if you're already into coding to double down on it. &lt;/p&gt;

&lt;p&gt;That's it now, have a lovely day!&lt;/p&gt;





&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/a-guide-to-writing-clean-and-readable-code-ah3" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to write better code and become a teamplayer&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 23&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>wecoded</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>How to write better code and become a teamplayer</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Fri, 23 Feb 2024 11:45:40 +0000</pubDate>
      <link>https://dev.to/mrlinxed/a-guide-to-writing-clean-and-readable-code-ah3</link>
      <guid>https://dev.to/mrlinxed/a-guide-to-writing-clean-and-readable-code-ah3</guid>
      <description>&lt;p&gt;A bit of a pet peeve I have is code that is just written to "impress", but what it just does is confuse the person trying to understand what the code does. Believe it or not, this person is most of the time yourself, but a month later.&lt;/p&gt;

&lt;p&gt;So, have your future self thank you and let's learn what it takes to write readable code. It's really not that hard. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making code readable
&lt;/h2&gt;

&lt;p&gt;If you can understand what a piece of code does with just a glance, you got it. If you have to ask yourself, is this readable? you don't got it.&lt;/p&gt;

&lt;p&gt;Some simple ideas you can implement:&lt;/p&gt;

&lt;h3&gt;
  
  
  Descriptive variable names
&lt;/h3&gt;

&lt;p&gt;Make sure identifiers are descriptive enough so that you immediately understand what they are and do.&lt;/p&gt;

&lt;p&gt;I am sure you agree with me that &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;calculateTotalPrice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;itemPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;discountPercentage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Is much better than if we used&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;cTP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dP&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;On a similar note, you should hint in a variable name what kind of type it is. Especially in languages where you don't need to specify types. A boolean should be &lt;code&gt;isOpen&lt;/code&gt; or &lt;code&gt;hasItem&lt;/code&gt; and not &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;item&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Format your code the same way as the rest of the file
&lt;/h3&gt;

&lt;p&gt;If you work alone you won't run into this problem as much since you probably have developed your own programming style.&lt;/p&gt;

&lt;p&gt;But if you're working in a team you should make sure your code looks the same as the rest of the file/project, this makes it for everyone much easier to understand what's going on. If code is suddenly formatted differently, you have to do some context switching in your brain, this could throw you out of your train of thought.&lt;/p&gt;
&lt;h3&gt;
  
  
  Use the proper amount of comments
&lt;/h3&gt;

&lt;p&gt;I am sure you have seen this one around plenty of times. Use comments! But it's not just that you need to use comments, it's that you need to use the appropriate amount of comments.&lt;/p&gt;

&lt;p&gt;This is a useless comment:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// Check if the number is negative&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Good comments explain complex pieces of code that are not immediately clear. Which will still happen sometimes.&lt;/p&gt;

&lt;p&gt;But the best comments are for when you (for example) experience a weird edge case bug in production and you need to implement an extra if statement in which it's not obvious why you added this piece of code.&lt;/p&gt;
&lt;h2&gt;
  
  
  The benefits of readable code
&lt;/h2&gt;

&lt;p&gt;Okay, so now that we've looked at some simple examples of what makes for good code, let's see why we should write good code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Maintainability
&lt;/h3&gt;

&lt;p&gt;This is probably the biggest reason. Code that's easy to read is easy to maintain and improve upon. What a waste of time it is to spend 2 hours trying to figure out how a piece of code works before you're able to implement a new feature or fix a bug that would've only taken you 15 minutes otherwise.&lt;/p&gt;
&lt;h3&gt;
  
  
  Cooperation
&lt;/h3&gt;

&lt;p&gt;If you're working in a team, it's important that the team works together well. When everyone in your team writes readable code it doesn't matter who's working on what part of the system. They understand what's going on.&lt;/p&gt;

&lt;p&gt;Luckily, in a lot of bigger teams, there are guidelines for how they write code in their company. And you might not even get your pull requests accepted if you fail to follow them.&lt;/p&gt;
&lt;h3&gt;
  
  
  Growing your company
&lt;/h3&gt;

&lt;p&gt;You might be working alone or for a small company right now. But eventually, you might hire someone or your company will grow. These new developers need to get up to speed as fast as possible, clean and readable code helps with that a lot. &lt;/p&gt;

&lt;p&gt;If the new guy understands your code and can provide value right away, you've done a good job.&lt;/p&gt;
&lt;h2&gt;
  
  
  The exceptions
&lt;/h2&gt;

&lt;p&gt;And I can hear you say, "&lt;em&gt;But Mr Linxed, in the real world it isn't as easy as you make it sound like here in this article&lt;/em&gt;", and you're right. Let's look at some exceptions.&lt;/p&gt;
&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;p&gt;If you're working on a critical piece of software you might need to put performance over anything else. And that's all right because let's face it, readable and clean code is not always the fastest code out there. &lt;/p&gt;

&lt;p&gt;But most of the time, the differences are so small that you'll never notice that you've used an extra variable in your code. &lt;/p&gt;

&lt;p&gt;If you're worried about the bundle size of your code because of the larger file size due to longer variable names and more code. Utilize minifiers in your build process. They'll probably do a better job at minifying your code than you'd be able to do manually.&lt;/p&gt;
&lt;h3&gt;
  
  
  Legacy code
&lt;/h3&gt;

&lt;p&gt;I am sorry to hear that you're working with legacy code. Especially if it's badly maintained and not written in a clean and readable way. But here is the thing, you don't have to fix it. But you should always make sure that what you add or edit is up to standards.&lt;/p&gt;

&lt;p&gt;Here is some wisdom I try to apply to all the areas in my life: Leave a place a bit better than you found it.&lt;/p&gt;

&lt;p&gt;This can also apply to your legacy code base.&lt;/p&gt;
&lt;h2&gt;
  
  
  Other tips on increasing the readability of your code
&lt;/h2&gt;

&lt;p&gt;Of course, you don't always want to manually fix all the issues in your code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Automate it
&lt;/h3&gt;

&lt;p&gt;This is the obvious one. There are plenty of tools out there that will automatically fix some of the formatting. Remember that these won't (not yet at least) rename your variables or add useful comments, that's still your job.&lt;/p&gt;
&lt;h3&gt;
  
  
  Code reviews
&lt;/h3&gt;

&lt;p&gt;As mentioned quickly earlier, conduct code reviews regularly and make sure the code (aside from checking if it doesn't contain malicious code or obvious bugs) is also following the correct practices when it comes to readability.&lt;/p&gt;

&lt;p&gt;If you're working alone, you might want to consider making pull requests for yourself and checking your code a day or two later with a fresh pair of eyes.&lt;/p&gt;



&lt;p&gt;I hope this article has taught you something new, or at least put you back on the right track if you were off it.&lt;/p&gt;

&lt;p&gt;Writing clean and readable code will be helpful for you and everyone around you in the long run.&lt;/p&gt;

&lt;p&gt;Your future self and your boss will thank you.&lt;/p&gt;

&lt;p&gt;That's it for now, have a lovely day!&lt;/p&gt;



&lt;p&gt;If you're looking to get more done check out my other article&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/accomplish-more-with-the-cult-of-done-1p93" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Accomplish more with the "Cult of Done"&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discuss&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#motivation&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Or if you're looking for a way to host your site for free, check out my article on that&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/host-your-web-app-for-free-on-cloudflare-pages-15en" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Host your web app for free on Cloudflare Pages&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 9&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>programming</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Accomplish more with the "Cult of Done"</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Sun, 18 Feb 2024 10:28:01 +0000</pubDate>
      <link>https://dev.to/mrlinxed/accomplish-more-with-the-cult-of-done-1p93</link>
      <guid>https://dev.to/mrlinxed/accomplish-more-with-the-cult-of-done-1p93</guid>
      <description>&lt;p&gt;Not so long ago I ran into a &lt;a href="https://www.youtube.com/watch?v=bJQj1uKtnus" rel="noopener noreferrer"&gt;video about the "cult of done"&lt;/a&gt; and it helped me a lot with actually getting things done and stopping procrastinating my work.&lt;/p&gt;

&lt;p&gt;In this post, I'd like to unpack the manifesto and see how this can apply to our work as software developers. Keep in mind that these points can also apply to other fields in your life. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Cult of Done Manifesto?
&lt;/h2&gt;

&lt;p&gt;Created by Bre Pettis &amp;amp; Kio Stark back in 2009. So it has been going around for quite a while. And to quote Bre Pettis:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Cult of Done Manifesto is a special document. Written from bed with Kio Stark in our first few months of dating. It was one of those magic writing moments where I had the laptop open and our ideas flew onto the page. For me, it is a map of my 2009 heart. Getting it on paper was a cathartic documentation of my life, my soul, and my passion for unbridled creativity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The manifesto
&lt;/h2&gt;

&lt;p&gt;All right, let's dive right into unpacking this manifesto and my interpretation of each item.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. There are three states of being. Not knowing, action and completion.
&lt;/h3&gt;

&lt;p&gt;Ever tried the learn something new and felt completely overwhelmed and unsure where to start? This is the &lt;em&gt;not knowing&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So what do we do? We take action. We dive deep into the problem and just try things. There doesn't need to be an end goal. Just doing. And after 30 minutes you're done. You're complete. You've learned something, you've become more wise than 30 minutes ago. And then repeat this cycle.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Accept that everything is a draft. It helps to get it done.
&lt;/h3&gt;

&lt;p&gt;Oh, did I mention that this article is a draft, it's been typed up within 30 minutes, with minimal editing (to get the obvious errors out) and published for you to read. &lt;/p&gt;

&lt;p&gt;Does this mean you should be sloppy? No not at all, you should give it your best. But accept that it isn't perfect. Because honestly, after this article I can write another article that'll be a bit better. Remember this, prototypes end up in production all the time.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Pretending you know what you’re doing is almost the same as knowing what you are doing, so just accept that you know what you’re doing even if you don’t and do it.
&lt;/h3&gt;

&lt;p&gt;Basically "fake it till you make it". All though I am not fully a fan of this attitude it can help you in certain situations. Like when your client asks you to solve a tricky bug in a piece of software you've never lied your eyes on. You have no clue what's going on, but the client doesn't need to know this. You'll figure it out, I know you will.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Banish procrastination. If you wait more than a week to get an idea done, abandon it.
&lt;/h3&gt;

&lt;p&gt;Got this awesome project idea you want to create, but you just can't get yourself to start? Put it away, don't bother. Do something else. The point is to get something done. If you don't start you will never get something done. Your brain is probably full of ideas, so you can work on something else. Maybe you'll visit this project again in the future, but for now, put it away. You have better things to do than to waste your time procrastinating.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. The point of being done is not the finish but to get other things done.
&lt;/h3&gt;

&lt;p&gt;Admit it, you'll never finish your website. And that's okay. But finishing is not the same as being done. Your website can be done without actually being finished. A website can be a collection of smaller parts that you've done. Over time you'll create a fully-fledged website. One that's never finished, because you'll think of new things to add to it.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Once you're done you can throw it away.
&lt;/h3&gt;

&lt;p&gt;Yes, when you've done something, you can put it aside, throw it away, or forget about it. No need to keep coming back to the same project. You've done it. Now go do something else. Either something new or a better iteration.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Laugh at perfection. It’s boring and keeps you from being done.
&lt;/h3&gt;

&lt;p&gt;You'll never be done if you keep trying to make it better. At some point, it's good enough and you should probably call it done. It doesn't help if you burn yourself out on the same boring task. Because you won't get it done, and it doesn't help you on your future projects because you're burned out.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. People without dirty hands are wrong. Doing something makes you right.
&lt;/h3&gt;

&lt;p&gt;If the people criticising your work aren't doing the same or similar work, their criticism is null and void. Don't listen or laugh it off.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Failure counts as done. So do mistakes.
&lt;/h3&gt;

&lt;p&gt;Sometimes you fail. Sometimes you make mistakes. And that's all right. Because you've done something. You've learned and grown. Consider your task done. Even if the result wasn't what you've aimed at. Next time you'll do better with your new knowledge.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Destruction is a variant of done.
&lt;/h3&gt;

&lt;p&gt;Crazy to think about. How can destroying something mean you're done? Sometimes it's as easy as deleting all your old code because either you found a better way to do it. Or found a library that could do it better. Either way, the code you wrote is done.&lt;/p&gt;

&lt;h3&gt;
  
  
  11. If you have an idea and publish it on the internet, that counts as a ghost of done.
&lt;/h3&gt;

&lt;p&gt;Ever had a good idea and for whatever reason you can't or won't execute this idea? Why not share it on the internet? Maybe someone out there will work on it. And if it's something you want to use yourself too, you help yourself as well. Consider it done.  You could combine this with point 4, if you're procrastinating the idea maybe let someone else do it.&lt;/p&gt;

&lt;h3&gt;
  
  
  12. Done is the engine of more.
&lt;/h3&gt;

&lt;p&gt;Ever wondered why some people seem to be so productive? Because they get things done. It creates momentum. One done thing leads to two done things. It's addictive. &lt;/p&gt;




&lt;p&gt;And that's it. What do you think? Do you think this manifesto might help you accomplish more? Remember that not everything needs to be followed to the tee, you can adapt things so that they will fit your life better.&lt;/p&gt;

&lt;p&gt;Now, go work on that project and get it done.&lt;/p&gt;

&lt;p&gt;That's it for now, have a lovely day!&lt;/p&gt;





&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/host-your-web-app-for-free-on-cloudflare-pages-15en" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Host your web app for free on Cloudflare Pages&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 9&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>productivity</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Host your web app for free on Cloudflare Pages</title>
      <dc:creator>Mr. Linxed</dc:creator>
      <pubDate>Fri, 09 Feb 2024 12:26:18 +0000</pubDate>
      <link>https://dev.to/mrlinxed/host-your-web-app-for-free-on-cloudflare-pages-15en</link>
      <guid>https://dev.to/mrlinxed/host-your-web-app-for-free-on-cloudflare-pages-15en</guid>
      <description>&lt;p&gt;If you have a Vue / React / Angular or even a simple site that's just an index.html like &lt;a href="https://mrlinxed.com/" rel="noopener noreferrer"&gt;mine&lt;/a&gt;, you can host it using Cloudflare pages, absolutely free.&lt;/p&gt;

&lt;p&gt;Let me show you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using GitHub / GitLab
&lt;/h2&gt;

&lt;p&gt;A nice feature of Cloudflare pages is that you can deploy your site using GitHub or GitLab. This way, every time you push to your production branch your site will automatically be updated.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Create an application&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After signing up and logging in to Cloudflare, navigate to &lt;em&gt;workers &amp;amp; Pages&lt;/em&gt; using the sidebar and click on _Create application&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%2Fvkqlvs19wap0my6xmhnb.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%2Fvkqlvs19wap0my6xmhnb.png" alt="Arrows pointing at where you click"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Navigate to pages&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Cloudflare seems to hide this feature a bit, so once you've reached the page you see on the image below, you have to click on the tab &lt;em&gt;Pages&lt;/em&gt; which is located next to the tab &lt;em&gt;Workers&lt;/em&gt;&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%2Fevar7kxpqd1xkqe7poce.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%2Fevar7kxpqd1xkqe7poce.png" alt="Arrow pointing at the location of the pages tab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Pick how you want to deploy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, you'll see a screen that gives you 2 options for deploying your application, one via GitHub / GitLab and the other via direct file upload. We'll handle file upload later in this post. So press on &lt;em&gt;Connect to Git&lt;/em&gt;&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%2Flslytl3oostvhzwj3ip9.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%2Flslytl3oostvhzwj3ip9.png" alt="Showing the options"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Connect your account and select your repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Depending on if you want to use GitHub or GitLab, you'll have to select the correct tab. We're using GitHub. If you haven't connected your GitHub account, do this here as well. Afterwards, you can select the repository you want to be deploying to Cloudflare Pages&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%2Fmkxcmo85x6ekqtbug7v0.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%2Fmkxcmo85x6ekqtbug7v0.png" alt="Connect your GitHub or GitLab pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Save &amp;amp; deploy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After you select the correct repository, you'll have some options. And depending on what kind of projects you use you have different configurations here. Make sure you select the correct production branch, which is probably &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you're using NPM or Yarn you may want to add a build command. But you can leave this empty.&lt;/p&gt;

&lt;p&gt;Once you're done, you click on &lt;em&gt;save &amp;amp; deploy&lt;/em&gt;. You're page will be up in just a few seconds.&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%2Fdcdof88noblt1ry9264j.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%2Fdcdof88noblt1ry9264j.png" alt="Final settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the direct upload method
&lt;/h2&gt;

&lt;p&gt;Direct upload is also very easy, all you have to do is fill in a project name &amp;amp; upload the files you need. &lt;/p&gt;

&lt;p&gt;The downside is of course, that if you want to update your site, you'll have to do this manually every time.&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%2F6tbicol69znw6shzwvsk.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%2F6tbicol69znw6shzwvsk.png" alt="Direct upload form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;It's good to keep in mind that the free plan has a daily limit of 100.000 requests. But that should be plenty if you're just starting or hosting a portfolio site that doesn't get many hits. For more information look at &lt;a href="https://www.cloudflare.com/en-gb/plans/developer-platform/" rel="noopener noreferrer"&gt;the pricing page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you currently don't have a site yet and want to get something up fast. Check out the &lt;a href="https://shop.mrlinxed.com/l/simple-landing-page" rel="noopener noreferrer"&gt;template I've made&lt;/a&gt; which I also use on my site.&lt;/p&gt;

&lt;p&gt;I've written about my site in another post:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/mrlinxed" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F919635%2F2af00dc5-689d-4658-9d68-bcfe89e9f149.png" alt="mrlinxed"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrlinxed/finally-got-around-to-making-a-website-for-myself-1o08" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Finally got around to making a website for myself&lt;/h2&gt;
      &lt;h3&gt;Mr. Linxed ・ Feb 6&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#showdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#html&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#css&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;That's it for now, have a lovely day!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
