Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Bombuzal game, Flash, Game development and Users contributions.

One of the biggest problems of step 3 was Bombuzal waled sooo slowly.

So I added a variable called walk_speed where I assign the walking speed in pixels per frame.

Then, in the original game you have to think fast. You can’t stay on the same tile for more than about 5 secods, or the tile where you are over will turn in a spinning tile that will spin Bombuzal in a random direction everytime it walks on it.

But it’s not over: if Bombuzal stays on a tile with a bomb for more than 5 seconds, the tile won’t become a spinning tile but the bomb will explode, killing Bombuzal.

If Bombuzal stays on a disappearing tile for more than 5 seconds, the disappearing tile will… disappear, making Bombuzal fall down.

A lot of exceptions for an old C64 game!

At the moment, I won’t make any tile change, but I will move Bombuzal in a random direction if it stays more than 5 seconds on the same tile.

I am creating a counter called does_not_move that will count all frames passed since the last time Bombuzal moved. If the counter reaches 150, then I’ll randomly move Bombuzal

//create an invisible movie clip across the entire stage using API
_root.createEmptyMovieClip("base", 1);
with (base) {
	lineStyle(2, 0x0000000, 0);
	beginFill(0x00000000, 0);
	lineTo(Stage.width, 0);
	lineTo(Stage.width, Stage.height);
	lineTo(0, Stage.height);
	lineTo(0, 0);
}
//whether to pan or not
level_pan = false;
//tile size
tile_size = 50;
// pan variables
pan_dist = 50;
pan_speed = 5;
// tiles array generation
tiles = [[0, 1, 0, 0], [1, 1, 2, 1], [1, 2, 1, 2], [0, 0, 1, 0]];
// bombs array generation
bombs = [[0, 1, 0, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 1, 0]];
// main sprite
// xpos: bombuzal x position
// ypos: y position
// moving: bombuzal is moving or not
// facing: the side bombuzal is facing on
bombuzal_obj = {xpos:0, ypos:1, moving:false, facing:"right"};
// bombuzal walk speed, in pixels/frame
walk_speed = 5;
// time passed since bombuzal last move
does_not_move = 0;
// creating the level movieclip
_root.createEmptyMovieClip("level", _root.getNextHighestDepth());
// placing tiles
for (x=0; x=Stage.height-level._height) {
			level._y = Stage.height-level._height;
		}
		//too far to the left                                    
		if (level._x<=0) {
			level._x = 0;
		}
		//too far to the right                                    
		if (level._x>=Stage.width-level._width) {
			level._x = Stage.width-level._width;
		}
		// panning level                                    
		// pan right
		if (_root._xmouseStage.width-pan_dist) {
			level._x -= pan_speed;
		}
		// pan down                                    
		if (_root._ymouseStage.height-pan_dist) {
			level._y -= pan_speed;
		}
	}
};
//when mouse is on stage pan
base.onRollOver = function() {
	level_pan = true;
};
//when mouse leaves stage stop panning
base.onRollOut = function() {
	level_pan = false;
};
// update bombuzal position
function update_bombuzal_position() {
	// if bombuzal falls off the stage...
	if ((tiles[bombuzal_obj.ypos][bombuzal_obj.xpos] == undefined) or (tiles[bombuzal_obj.ypos][bombuzal_obj.xpos]<1)) {
		// reset bombuzal to its starting position
		bombuzal_obj.xpos = 0;
		bombuzal_obj.ypos = 1;
		level.bombuzal._x = bombuzal_obj.xpos*tile_size;
		level.bombuzal._y = bombuzal_obj.ypos*tile_size;
		update_bombuzal_position();
	}
}

Now I want "broken" tiles to disappear after Bombuzal passed over them. To do it, when Bombuzal stops after walking for an entire tile, I check if the tile it just left is a broken tile.

In this case, I remove the tile movieclip and update the tiles array...

//create an invisible movie clip across the entire stage using API
_root.createEmptyMovieClip("base", 1);
with (base) {
	lineStyle(2, 0x0000000, 0);
	beginFill(0x00000000, 0);
	lineTo(Stage.width, 0);
	lineTo(Stage.width, Stage.height);
	lineTo(0, Stage.height);
	lineTo(0, 0);
}
//whether to pan or not
level_pan = false;
//tile size
tile_size = 50;
// pan variables
pan_dist = 50;
pan_speed = 5;
// tiles array generation
tiles = [[0, 1, 0, 0], [1, 1, 2, 1], [1, 2, 1, 2], [0, 0, 1, 0]];
// bombs array generation
bombs = [[0, 1, 0, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 1, 0]];
// main sprite
// xpos: bombuzal x position
// ypos: y position
// moving: bombuzal is moving or not
// facing: the side bombuzal is facing on
bombuzal_obj = {xpos:0, ypos:1, moving:false, facing:"right"};
// bombuzal walk speed, in pixels/frame
walk_speed = 5;
// time passed since bombuzal last move
does_not_move = 0;
// creating the level movieclip
_root.createEmptyMovieClip("level", _root.getNextHighestDepth());
// placing tiles
for (x=0; x=Stage.height-level._height) {
			level._y = Stage.height-level._height;
		}
		//too far to the left                                     
		if (level._x<=0) {
			level._x = 0;
		}
		//too far to the right                                     
		if (level._x>=Stage.width-level._width) {
			level._x = Stage.width-level._width;
		}
		// panning level                                     
		// pan right
		if (_root._xmouseStage.width-pan_dist) {
			level._x -= pan_speed;
		}
		// pan down                                     
		if (_root._ymouseStage.height-pan_dist) {
			level._y -= pan_speed;
		}
	}
};
//when mouse is on stage pan
base.onRollOver = function() {
	level_pan = true;
};
//when mouse leaves stage stop panning
base.onRollOut = function() {
	level_pan = false;
};
// update bombuzal position
function update_bombuzal_position() {
	// if bombuzal falls off the stage...
	if ((tiles[bombuzal_obj.ypos][bombuzal_obj.xpos] == undefined) or (tiles[bombuzal_obj.ypos][bombuzal_obj.xpos]<1)) {
		// reset bombuzal to its starting position
		bombuzal_obj.xpos = 0;
		bombuzal_obj.ypos = 1;
		level.bombuzal._x = bombuzal_obj.xpos*tile_size;
		level.bombuzal._y = bombuzal_obj.ypos*tile_size;
		update_bombuzal_position();
	}
}

Last but not least, I would like to thank Grifo, the winner of this step for his Bombuzal character

Next thing I need... when Bombuzal is on a tile with a bomb on it, if SPACEBAR is pressed then Bombuzal takes/drops the bomb.

If SPACEBAR is hold for more than 2 seconds, then the bomb detonates.

Win a tutorial step to have your name/site in final game credits... and maybe something more... here they are the source files...

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.