Title: Barcode Wars: Small Javascript game
Slug: barcode-wars-small-javascript-game
Date: 2012-10-03 07:40:15
Author: Kartones
Lang: en
Tags: Development, Game Dev, Javascript, HTML, Videogames
Description: Created a simple game inspired by the Barcode Battler system, using Javascript and HTML 5 to generate characters and enemies from barcodes.

<p>When I was young, handhelds were pretty basic LCD clumbersome machines and computers were still primitive, I had a very special present: A <a href="http://en.wikipedia.org/wiki/Barcode_Battler">Barcode Battler</a>.</p> <p><img alt="Machine photo" src="https://images.kartones.net/posts/kartonesblog/barcode_battler.jpg"></p> <p>I won't enter into details and refer you to the above link, but as a quick summary it is a Pokemon ancestor which used barcodes to create game characters, enemies or objects, then made some randomized simple fights.</p> <p>I have been lately wanting to do small games, and a clone of this system was both appealing and easy to achieve. The added fun of using barcodes was also nice, today being so easy to use as data, so I decided to went for a small version of the game:</p> <ul> <li>Using Javascript &amp; HTML 5, so I can finally toy with the &lt;canvas&gt; a bit</li> <li>Player vs CPU</li> <li>Read barcodes somehow, MD5 hash the code (so allows for theorically many attributes) and create the enemy randomizing user's stats + threshold</li> <li>"Some" design, retro look (design people don't kill me, I'm terrible with CSS and design)</li></ul> <p>Initially I wanted to do a webapp for mobile phones, but as HTML file input is still quite limited on some mobile operating systems I decided to go for a single-screen desktop version. Also, <a href="https://gist.github.com/421369">barcode reading via Javascript</a> relies mostly on image processing (put image in a canvas and read the lines), so it is better to use <a href="http://www.barcode-generator.org/">an online barcode generator</a> to get clean and sharp images).</p> <p>The game uses <a href="http://en.wikipedia.org/wiki/Universal_Product_Code">UPC-A</a> format for the barcodes:</p> <p><img alt="UPC-A barcode sample" src="https://images.kartones.net/posts/kartonesblog/barcodde_sample_12345.png"></p> <p>The code is hacked in a few hours spread along three or four nights invlufing being ill last one, so don't expect much comments, a clean game loop or an amazing architecture. It works, can be easily understood, modified and extended and it's been a long time since I've been able to code from start to finish a small project not related to work, so I don't want this to stay in the "almost finished" limbo for too long. If I'm free in the future I could improve everything a bit, but no guarantees.</p> <p>Most importantly, it allowed me to see that I want to do more things with the &lt;canvas&gt; HTML 5 element. It allows pure low-level pixel manipulation like <a href="http://en.wikipedia.org/wiki/Mode_13h">back in the old days</a> and reminded me of the Demoscene (<a href="http://pouet.net/prodlist.php?platform[]=JavaScript&amp;order=&amp;x=26&amp;y=10&amp;page=1&amp;order=">now in Javascript</a>). I just did a simple pixel coloring (sprites are grey, player gets color from barcode data and enemy is random each time) and now I want to learn more about the canvas and do more, maybe port old C graphics programs and simple demos...</p> <p> </p> <p>The game logic is dumb-simple: Attack (str - def doing at least 1 point), Super attack (str x3 - def but attacker losses str points of vitality), Heal (+def vitality points)</p> <p>I have just tested a few barcodes so the algorithm that creates player stats + randomization might spawn unbalanced players and/or monsters.</p> <p> </p> <p>Anyway, you can play the game from here: <a title="https://kartones.net/demos/017/" href="https://kartones.net/demos/017/">https://kartones.net/demos/017/</a></p> <p>And of course view the source code and associated JS file (not minimized on purpose) to see how it works.</p> <p>Just so that you don't expect anything amazing here is a screenshot of how it looks:</p> <p><img alt="Game screenshot" src="https://images.kartones.net/posts/kartonesblog/barcode_wars.jpg"></p> <p><strong>Note</strong>: Internet Explorer not supported, tested with Chrome and Firefox.</p> <p> </p> <p><u>Additional Resources</u></p> <p>Sprites grabbed from <a href="http://spritedatabase.net/file/2219">Sprite Database</a></p> <p>Nice and easy to follow <a href="http://www.html5canvastutorials.com/">HTML5 Canvas tutorials</a></p>
