Talking about Talesworth Adventure game, Actionscript 3, Flash and Game development.
One of the main features of Talesworth is the hero keeps running according to his rules until he spots a loot. Then he changes its way to grab the loot. In part 1 I showed you how to make the hero walk like in the original game, and in part 2 I introduced the line of sight.
Now it’s time to place the loot and make the hero change his way. Greedy.
First, I have to say the movement routine I showed in step 1 is buggy. Not that buggy, it’s just in some circumstances the hero does not behave like in the original game.
So I changed the script. Now it works this way:
* The hero walk straight until he finds a wall
* He tries to turn right
* If he can’t turn right, he tries to turn left
* If he can’t turn left, he returns back
As for the loot, I scan in the four directions as showed in step 2, then if I find a loot in one direction, I simply set the hero direction according to loot position.
In this new script I simply created a new movieclip called loot_mc
and made it work this way:
* You can only place the loot on a walkable tile (marked with 2
)
* You can only place ONE loot
* Once you placed a lot, you can’t move it until the hero sees it
* When the hero sees the loot, he changes his direction
A bit different from the original game at the moment, but at this time I just want to create the loot engine. And it works… in real time… here it is the script:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
public class talesworth5 extends Sprite {
public var map: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 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;
// the loot movieclip
public var loot:loot_mc = new loot_mc();
// variable to determine whether the loot is placed on the map or not
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]];
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:
Play placing the loot with the mouse clicking on a tile in hero's line of sight, and see how he changes direction. Then place the loot again.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.