Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Blockage game, Actionscript 3, Flash and Game development.

This is one of those days when you want to make a thing work that way FULLSTOP.

And that’s it… this is the typical Blockage movement:

I wanted to do it without any timeline tween or tricks to change registration point on the fly, just using localToGlobal method. If you aren’t familiar with this method, read understanding AS3 localToGlobal method first.

So here it is the uncommented and unoptimized prototype. While comments and tutorial will come when I’ll integrate it into the making of the game, I think this can be useful to someone of you to have a sneak peak of what’s going on.

This is the main class:

package {
	import flash.display.Sprite;
	public class blkg extends Sprite {
		private var block:block_mc=new block_mc();
		public function blkg() {
			block.x=0;
			block.y=50;
			addChild(block);
		}
	}
}

and this is block_mc class:

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	public class block_mc extends Sprite {
		public var point:Point=new Point(50,50);
		public var defpoint:Point=new Point(50,100);
		public var rotation_dir=5;
		public var steps:uint=0;
		public function block_mc() {
			addEventListener(Event.ENTER_FRAME,on_enter_frame);
		}
		private function on_enter_frame(e:Event) {
			rotation+=rotation_dir;
			if (rotation%90==0) {
				rotation=0;
				steps++;
				if (steps==9) {
					steps=0;
					rotation_dir*=-1;
					if (rotation_dir>0) {
						point=new Point(50,50);
					} else {
						point=new Point(0,50);
					}
				} else {
					if (rotation_dir>0) {
						defpoint=new Point(50,0).add(defpoint);
					} else {
						defpoint=new Point(-50,0).add(defpoint);
					}
				}
			}
			var tmp_point:Point=localToGlobal(point);
			tmp_point=defpoint.subtract(tmp_point);
			x+=tmp_point.x;
			y+=tmp_point.y;
		}
	}
}

Just remember I am using a 50 pixel sided square with origin at 0,0 and that steps==9 at line 18 is used only to make the square go back and forth.

Download the source code and solve the mystery… or wait for next step.

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