Showing posts with label Crafty. Show all posts
Showing posts with label Crafty. Show all posts

Monday, July 22, 2013

Diamond Reaction: An HTML5 Chain Reaction Game using Crafty JS

I've been away from blogging for a long time. Maybe because I've not been learning code-detailed topics. I've been more like learning the basics in topics I've never tries before (like PHP) and learning some theoretical topics.

Anyways, this time I'm trying a new approach to gain more experience. This was I can gain experience from anything I want to learn. So here is my almost-full game implementation of an HTML5 chain reaction game called: Diamond Reaction.

Play Diamond Reaction now



Let's talk a bit about it:

Idea:
I wanted to make a game for fun, with the focus on game mechanics. So I started thinking of some ideas that can be fun for a 'mario-lover' like me. Whenever I think of an idea, I search about it and see how frequent I find the same mechanics on the web. Till I arrived at this concept that did not have a big hit before: chain reaction games.

Theme:
If you look at a game like Angry Birds, you can find the game mechanics are not that hard or new. But the theme is what made it a big hit. I'm doing my game for fun and experience and I'm not a graphic designer, so I started searching for the common simple themes for the popular games these days, especially on Facebook. The most noticed theme was the cartoonish diamonds theme (plus bubbles and animals). So I picked this theme because It will not need much effort to make, plus it actually makes the game more fun to play (you can search for chain reaction games and see how boring their graphics are).

Implementation:
Since the concept of chain reaction game is not that hard to implement, and I already know how to use Crafty JS framework, the game did not take much time to get to the first demo.

Gamification:
I thought about adding a small feature to add more fun and challenge to the game: highscore and leaderoard. but I did not to keep user data on my small server. So I decided to add an optional Facebook login button to login with Facebook credentials so that I can use the Scores API the Facebook has.

Balance:
These kinds of small games can get boring if I did not find the right balance for the game. Since it was a very small game with no big details, fine-tuning was made easily by playing and -trial-and-error.

Missing features:
- No sound was added, maybe I can add it later.
- I'm not satisfied with the current balancing.
- Add more items and surprises to the game to make it more fun and engaging.

Play Diamond Reaction now




Sunday, June 30, 2013

Crafty JS Tutorial (DX Ball / Breakout)



Introduction:

This Crafty JS tutorial is part of Alkottab Studio's internship program, to take developers with no previous game development experience in the quickest way to production phase.

Prerequisites:
  • Previous development experience.
  • The very basics of HTML/CSS/Javascript.
  • Finishing the first part of the Crafty tutorial on its website. [ How Crafty worksDownload and Setup ]

Section 1: Game description:


  • A ball continuously moving and hitting walls and bricks.
  • Bricks are destroyed and points are collected when hit by the ball.
  • User controls a bat and moves it right and left to prevent the ball from hitting the ground.
  • If the ball hits the ground, a life is lost.

Section 2: File Structure:

Before starting the tutorial, it is better to explain how the files are arranged:
  • index file : links to JS files, game div, some simple CSS.
  • js directory: Crafty file and game file.
  • assets directory: images and spritesheets used.

Section 3: Coding considerations:
  • For a cleaner code, some complex game items will be separated as Crafty components to be used later in game scenes.
  • To handle game constants, variables and cross-component calls (like an object wanting to affect the score bar), I will make a simple game manager to contain values and functions connecting between components.

Section 4: Scenes:
  • Loading: A scene only for loading game assets and giving the user a progress indication.
  • Home: Main Menu screen of the game. For now, it will contain only a start button, but it can have more buttons and some graphics representing the game.
  • Game: the scene with the actual play.
  • Total Score: When a user wins or loses, this scene will show the total score.


For the complete tutorial, view the PDF file online (link) or download the PDF + code (link)

Monday, July 16, 2012

Full HTML5 Game Example with Crafty JS

A couple of days ago, I participated in a game jam called "Game Zanga". It was a three-day contest for game development with some conditions: in Arabic, related to a topic announced at the start of the three days (it was "Freedom"), and browser-based.

So it was a nice chance to test my knowledge and experience in game development (which is a new thing to me) and I decided to use Crafty (or maybe some call it CraftyJS). Crafty is a JavaScript game library using HTML5. One great power in Crafty is that it can use Canvas or DOM. Plus the concept of Components and Entities that allow you to develop the game in a OO style.

So, I thought I can post my code for anyone to learn from. Although it is not perfect code and it neads more refactoring and fine-tuning, it is still a good example of how a game can look like in Crafty. I almost did not need anything other than the API documentation on Crafty website (plus the tutorial if you are to start from the very beginning). So with decollapsing the code you'll immediately have a general overview of how the game code looks like, then collapsing the code can do the job to get to the details.

One important note, this game was intended to be an Arabic game, so here are some guidelines:
- The first icon in the home screen is the "Start" button.
- Once the game starts, you have two blue cannons on the left. Click any of them to use it.
- Your abjective is to let the blue soldiers pass ("unrwa" in code) and kill the green ones ("soldier" in code).
- Life points decrease if any green soldier passes.
- Your weapon is upgraded while playing.


Finally, you'll notice some faults in collision detection and a lot of other things in the code, but remember that it was made in only two days by me (a newbie) using Crafty which lacks the variety of full examples to learn from. Anyways, you'll get the idea of a full game in less than 1000 lines and then you can make your own best seller.

Here are some screenshots, followed by a download link.





Download game code here.