Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Talesworth Adventure game, Actionscript 3, Flash and Game development.

In this 4th step we’ll cover one-way doors.

One-way doors are tiles the hero can walk only once, before they become unwalkable.

First, let me show you a fix to the script shown in step 3.

In the example, the loot disappears when the hero sees it, he does not have to touch it. Since I make the loot disappear setting loot_placed variable to false, now I set it that way only when the hero is on the same cell where the loot is placed.

And now, let’s talk about one-way doors.

When you have a lot of items on your map, such as doors, keys, enemies, traps and so on, I suggest you to create various layers of the same map. This will make your life easier and will allow you to add more and more stuff on the map without rewriting that much code.

That’s why I created anoter array, of the same size as map array, called itm. A value of 1 in itm array means there is an one-way door.

When the hero walks on a tile with an one-way door, the tile is set as unwalkable setting to 1 the value in the map array.

This is the source code:

package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.Event;
	public class talesworth5 extends Sprite {
		public var map,itm:Array=new Array();
		public var hero_pos:Array= new Array();
		public var wall:wall_mc;
		public var floor:floor_mc;
		public var hero:hero_mc;
		public var oneway:oneway_mc;
		public var key_pressed:int=0;
		public var hero_is_moving:Boolean=false;
		public var hero_x_dir:int=0;
		public var hero_y_dir:int=0;
		public var steps:int=4;
		public var tile_size:int=32;
		public var walk_dir:int=2;
		public var loot:loot_mc = new loot_mc();
		public var loot_placed:Boolean=false;
		public function talesworth5():void {
			map=[[0,1,1,1,1,1,1,1,1,1,1,1],[0,1,2,2,2,2,2,2,2,1,1,1,1],[0,1,1,1,1,2,1,1,2,1,1,2,1,1],[0,0,1,1,1,2,1,1,2,1,1,2,1,1],[0,0,0,1,1,2,1,1,2,1,1,2,1,1,1],[0,0,0,1,1,2,2,2,2,2,1,2,2,2,1],[0,0,1,1,1,2,1,1,1,2,1,2,1,1,1,1],[0,0,1,1,1,2,1,1,1,1,1,2,1,1,1,1],[0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,1],[0,0,1,2,1,1,2,1,1,1,1,1,1,1,2,1],[0,0,1,2,2,2,2,1,1,1,1,1,0,1,2,1],[0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1]];
			itm=[[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
			hero_pos=[3,1];
			draw_map();
			place_hero();
			addChild(loot);
			stage.addEventListener(Event.ENTER_FRAME,on_enter_frame);
			stage.addEventListener(MouseEvent.CLICK,on_mouse_click);
		}
		public function draw_map():void {
			for (var i:int=0; i

And this is the result:

Try to place loots to make the hero walk on the pink square, and see what happens when the square turns red.

Download the source code.

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