Talking about Iromeku game, Game development, HTML5, Javascript and Phaser.
A couple of years ago I showed you an AS3 prototype of the Iromeku game engine.
In the original game you have a game panel of a few colored squares and, using color affecting tiles, your objective is to change your panel to match that of the target.
The whole development theory and process is explained in the original post, so let’s jump straight to the point and see what you are going to do using Phaser framework in less than 50 lines of code:
Dragging tiles you will change tile values, according to this rule: tile value is given by its initial value plus the sum of all tiles above it. Playing with overlaps you can get some interesting cascade sequence of numbers.
Here is the script:
window.onload = function() { var game = new Phaser.Game(640, 480); var tileSize = 80; var gameTiles = 10; var tilesArray = []; var tileGroup; var playGame = function(game){} playGame.prototype = { preload: function(){ game.load.image("tile","tile.png"); }, create: function(){ tileGroup = game.add.group(); for(var i=0;i=0; i--){ for(var j=i-1;j>=0;j--){ if(tileGroup.getAt(i).overlap(tileGroup.getAt(j))){ tileGroup.getAt(j).currentValue += tileGroup.getAt(i).currentValue; tileGroup.getAt(j).getChildAt(0).text = tileGroup.getAt(j).currentValue; } } } } } game.state.add("PlayGame",playGame); game.state.start("PlayGame"); }
It could be optmized above all in update function since it constantly updates tile values even when there’s no user input. Working on drag events you can update tile values only when a tile is actually moved.
I should have done it but I wanted to keep the code under 50 lines to show you how easy is to do this kind of stuff with Phaser.
Download the source code and if you optimize it in any way, send me your work and I’ll be happy to publish in the blog.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.