{"id":485,"date":"2009-08-25T19:55:35","date_gmt":"2009-08-25T23:55:35","guid":{"rendered":"http:\/\/patorjk.com\/blog\/?p=485"},"modified":"2014-01-25T17:54:24","modified_gmt":"2014-01-25T21:54:24","slug":"creating-a-javascript-space-ship-game","status":"publish","type":"post","link":"https:\/\/patorjk.com\/blog\/2009\/08\/25\/creating-a-javascript-space-ship-game\/","title":{"rendered":"Creating a JavaScript Space Ship Game"},"content":{"rendered":"<p>&#8220;What would be something neat to do in JavaScript?&#8221; &#8211; I kept asking myself that on Saturday. My fiance was away for the weekend and I was just kind of hanging out at home with the dog. Eventually I ended up thinking about possibly trying to do a side scroller game, like Mario Bros or Commander Keen, but since I had never written one before, I wasn&#8217;t sure. Finally, I came to the conclusion that it might be wiser to go for something a little easier first, and decided it might be cool to port my old &#8220;Intergalactic Odyssey&#8221; space ship game to JavaScript.<\/p>\n<p><figure style=\"width: 200px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" alt=\"Old Intergalactic Oddyssey Game\" src=\"http:\/\/patorjk.com\/images\/blog-2009\/igo-ep1.jpg\" title=\"Intergalactic Oddyssey\" width=\"200\" height=\"159\" \/><figcaption class=\"wp-caption-text\">Old Intergalactic Oddyssey Game<\/figcaption><\/figure>My goals here were to just see how feasible it would be to create an action game with moving sprites. I didn&#8217;t get very far, but I was able to create a <a href=\"http:\/\/www.patorjk.com\/games\/intergalactic-oddyssey\/demo\/\">space ship that could fly around and shoot lasers<\/a>. I was able to get the graphics by decompiling my old SWF Flash file (I&#8217;ve long lost the source to the game). Also, the space ship artwork was done by <a href=\"http:\/\/fitz.jsr.com\/\">fitz<\/a>. I originally found the space ship via Google Images, though I did ask before I used it.<\/p>\n<p>So far the main issue I&#8217;ve run into is that IE and FireFox aren&#8217;t reliable for smooth game play. The demo works best in Google&#8217;s Chrome and Opera&#8217;s Opera web browser. Though at this point I haven&#8217;t added any collision detection in, or any bad guys in, so there&#8217;s still a ways to go before I know if I&#8217;ll have a playable game.<\/p>\n<p>One thing I didn&#8217;t realize when I started was that I could rotate images. I googled for a little bit and didn&#8217;t come up with anything, so I wound up creating images for each of the different rotations of the space ship. Though now that I&#8217;ve read up on it a little more, image rotation can apparently be done with the Canvas object in FF, Opera and Chrome, and with filters in IE. I suppose I&#8217;ll find out later which method is faster.<\/p>\n<p>Lastly, the key capturing events are a little frustrating, since JavaScript doesn&#8217;t appear to remember when someone is holding the Up-arrow down if another key is pressed while its down. I&#8217;m still trying to figure out if there&#8217;s a way to get around this.<\/p>\n<p>If you have any tips\/suggestions, feel free to let me know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;What would be something neat to do in JavaScript?&#8221; &#8211; I kept asking myself that on Saturday. My fiance was away for the weekend and I was just kind of hanging out at home with the dog. Eventually I ended up thinking about possibly trying to do a side scroller game, like Mario Bros or &hellip; <a href=\"https:\/\/patorjk.com\/blog\/2009\/08\/25\/creating-a-javascript-space-ship-game\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Creating a JavaScript Space Ship Game<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,26],"tags":[],"class_list":["post-485","post","type-post","status-publish","format-standard","hentry","category-javascript","category-web-apps"],"_links":{"self":[{"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":12,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":497,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/posts\/485\/revisions\/497"}],"wp:attachment":[{"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/patorjk.com\/blog\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}