Thunderjack! HTML5 Game Update: Card Dealing

Hey guys.

Welcome back to Gameplay Coder. Quite a bit of progress has been made on the HTML5 version of Thunderjack! using Phaser and the Phaser Editor. I’m getting the hang of basic usage of the editor. And it’s great to have a visual editor at your disposal – so you don’t have to place sprites using hard-coded x/y coordinates via trial and error, or reply on some external graphics tool then have to copy/paste those coordinates.

Updates to this game include:

  1. Being able to place bets.
  2. Dealing the cards to the players and dealer.
  3. Updating points for the players.

Hit functionality is currently in the works, as is determining when a player or dealer has a blackjack, and when a player has a Thunderjack.

Use of Fonts

One issue I encountered is with using fonts. In the browser, they don’t appear exactly as the do in the editor. Some features such as stroke, aren’t rendered. So I’ll likely end up using Phaser bitmap fonts instead of fonts, which, on my machine, is a small set of Windows fonts that the editor has access to. Furthermore, there is no guarantee that the fonts used in the project will be installed on the machine of someone playing the game.

There is an online Flash tool (at the time of this post), called Littera. This can be used to create bitmap fonts from fonts installed on your machine. What’s also cool about it is, Phaser supports the format, as shown in this example.

Prototypal Inheritance

While I’m no stranger to OOP (object-oriented programming) and classical inheritance in languages like ActionScript 3, C# or Java, I’m fairly new as to prototypal inheritance in JavaScript, so I’m giving it a try in this project. Hell yeah! 💪🏾

I’m using prototypal inheritance with the data that stores the player hands and the dealer hand. There is a ‘base class’ called HandData, whose function constructor looks like this:

HandData class
HandData = function(s_handId) {
  this.cards = [];
  this.handId = s_handId;
  this.score = 0;
  this.hasBlackjack = false;
  this.isBust = false;
};

This is basic data that both types of hands, player and dealer, will contain.

However, player hands will need to store additional data, such as the bet amount, and can perform other moves such as split, double, and surrender. Players can also win via Blitz (6-card Charlie in this game). The dealer does not use any of these functions, and thus doesn’t need access to them.

The player hand data, PlayerHandData, will inherit from the HandData, and looks like this:

PlayerHandData class
PlayerHandData = function(s_handId) {
  HandData.call(this, s_handId);
  this.betValue = 0;
  this.hasThunderjack = false;
  this.isPush = false;
  this.hasBlitz = false;
  this.hasDoubled = false;
  this.hasSurrendered = false;
};

That call() function is like calling the constructor of the parent class. In this case, it sends the parameters that were sent when it was created onto its parent constructor. Also, the this keyword is supplied first, so that the context in which the parent constructor function is being called is set to the inheriting function constructor.

However, PlayerHandData still needs to have its constructor inherit the methods of the parent prototype. This creates a new object based on the parent prototype:

PlayerHandData.prototype = Object.create(HandData.prototype);

And finally, the constructor of our new PlayerHandData prototype needs to point to PlayerHandData instead of HandData. That can be fixed with this line:
PlayerHandData.prototype.constructor = PlayerHandData;

Now when we create data for each the dealer hand, we can write:
var dealerHand = new HandData(s_dealerId);

And for each of the six player hands, we can write something like:
var somePlayerHand = new PlayerHandData(s_playerId);

The player hand will have all the properties of the dealer hand, plus the extras that are required to support the additional game play available to the players.

So when inheriting one “class” from another (I put “class” in quotes because, JavaScript doesn’t have classes. They can be simulated using prototypes.), it’s basically three steps:

1). Within the inheriting function constructor, call the parent constructor function using the call(). Be sure to set this as the first parameter, succeeded by any function constructor parameters.
2). Create a copy of the parent function’s prototype, and assign it to the inheriting constructor function’s prototype.
3). Assign the constructor of the inheriting prototype to the inheriting constructor function itself.

This can be a little confusing, but typing this out can help reinforce learning (though writing it out is better, studies have shown, but I digress (:

But doing is the best way to learn, in my opinion, of course. So, I’ll definitely take more opportunities to apply this so it becomes easier.

Whew!

Well!… Lemme get a sippa water…
* Ahhhhh! *

Moving on, here is a short video of what I have so far. It’s what was mentioned in the updates mentioned near the start of this article.

It’s not much, but under the hood, a lot has been accomplished, and with most of the lower-level code now out of the way, I can start getting into the fun stuff!

Thanks for stick with me guys, and stay tuned for more.

– C. out.

Thunderjack! (HTML5 Version) and Phaser Editor

Hey there.

In addition to the Android version of Thunderjack! that I’m working on, I’ve also started a browser version, using HTML5. Flash is reaching its end-of-life, but browser games are still a thing. So, HTML5 is the next step for me, and I’ve been improving my skills to produce web-based games that do not use a plugin.

I found Phaser, an HTML5 game development library, and started learning it. This library is incredible! I’ve used it to create my first HTML5 game, Brickout.

Sure, I’m not the biggest fan of JavaScript (I took this course to get some quick JavaScript training), but that’s a relatively small hurdle to overcome – especially if you were like me – ego and attitude was keeping you from learning JavaScript.

I also wanted some sort of WYSIWYG IDE for designing the visual aspects of HTML5 games, similar to Adobe Flash/Animate. Eventually, I found the Phaser Editor.

Giving this software a try, I’m really liking most of what I’m finding with this editor. When you add visual objects the canvas scene, Phaser Editor generates the JavaScript code that creates those Phaser objects. No more having to hard-code things like the x/y positions of objects and line up your objects using trial and error.

You can even create custom, re-useable objects (known as prefabs in Phaser Editor), which can really facilitate the building process.

While the learning curve isn’t too steep, though I would have liked to see a tutorial that creates a game using the editor from scratch, rather than a pre-made game.

This editor also comes with its own JavaScript coding editor, with many of the standard features you’d expect from an editor, such as auto-completions, listing of JavaScript and Phaser API methods, code refactoring, and more.

Phaser Editor comes in two flavors: free and paid. The free version has some limitations, but not enough to stop you unless you’re building a massive game.

Overall, this is a very handy tool, and I’m excited about integrating it into my workflow as I add HTML5 game coding to my list of services.

More updates on Thunderjack! will be in the coming weeks. Stay tuned.

Talk to you soon.
– C. out.

Brickout Is Ready!

Hey!

Brickout is finally ready for first release! Yeah!!

Only thing is… I need to figure out how to add a portfolio that my current theme can use!! Or, maybe switch themes. Welp, let me figure that part out.

In the meantime, here is a video play through, although I didn’t get very far, haha!

On to the next game project! Thanks for staying with me!

Of course, I can make games like this for you too. If you’re interested, please get in touch with me by clicking here or e-mailing me directly at:
cartrell@gameplaycoder.com.

Thanks,

– C. out.

Added Ball and Paddle

Hey.

Just a quick update on this Memorial Day weekend.

Made some more progress and got the ball colliding with the walls and the payer’s paddle. Added a repeating background as well.

Next will be the bricks collision. For now, it’s pulling those multi-colored bricks from a tiles layer in the map, but I’ll be converting those to sprites and just using what’s in the map as placeholders.

I noticed there is an example for this type of game in the Phaser 2 Examples. Considering how I’ve already gotten this far on my own, I’d rather keep my own pace with it. Besides, this engine will go beyond the example in terms of function, visuals, feedback, and polish.

More to come later!

– C. out.

Tools I Use

Hey.

I want to fill you in on the tools and resources I use when I’m coding games. This is not an exhaustive list.

Coding Editors/IDEs

  • FlashDevelop
    My current go-to IDE for all things ActionScript 3. I also like how it can download and configure updates of the Adobe AIR and Flex SDKs.
  • Adobe Flash CS/Animate
    I don’t use this for coding, but for managing assets. While I’m not an artist, graphic designer, game designer, I find its visual editor very easy to use and mostly intuitive.
  • Brackets
    Been using this free editor for a little while. I use it for JavaScript when coding HTML5 games using Phaser.

Programming Languages/Engines/SDKs/Runtimes

  • Adobe AIR
    Despite Flash being retired soon, Adobe AIR is still at large. AIR is not the same thing as Flash – they both happen to use ActionScript 3 and many of the same APIs (with AIR having access to many more of them, partly due to it being able to target desktops). Plus, Adobe AIR can be used to target mobile (Android and IOs) from the same code with minor changes.
  • Adobe Flash
    Yes, I know Flash will no longer be updated or distributed by end of 2020, but until then, hey, it’s still being used.
  • Phaser
    I only care enough about HTML5 and JavaScript because of Phaser and it’s capabilities for game making. I don’t give a damn about web development.
  • Unity
    While I haven’t used Unity to make any games yet, I found a good course on Udemy for it.

Graphics

  • Paint.NET
    I use this for editing of bitmap files. Another simple and intuitive tool to use.

Project Management

  • Trello
    A free online tool for keeping track of my progress, especially when working on larger projects. I use it in a Kanban style, and I’ll have three major categories for tasks: Backlog; Work In Progress; and Ready for Testing. Once the client has tested the latest updates and all’s well, I will archive all the tasks in the Ready for Testing category, and start anew.

Source Control

  • GitHub
    Using Git as the version control system.
    You can find me here, hint, hint.
  • Bitbucket
    I also use Git here, but have tried Mercurial.

Audio

  • Wavosaur
    Simple tool for editing audio files.
  • Audacity
    Not as easy to use as Wavosaur, but it has more functions, particularly in terms of effects you can apple to sounds.

Music

 

So, that’s pretty much the jist of what I use. If you have any questions about anything here, let me know in the comments!

– C. out.