Skip to content

Instantly share code, notes, and snippets.

@videlais

videlais/MapGroup.as

Created Oct 30, 2013
Embed
What would you like to do?
ActionScript 3 Example 8 MapGroup Version 1
package
{
/**
* ...
* @author Dan Cox
*/
import org.flixel.*;
import org.flixel.system.FlxTile;
public class MapGroup extends FlxGroup
{
private var previousPlace:FlxPoint;
private var village:AreaGroup;
private var house1:AreaGroup;
public function MapGroup()
{
village = new AreaGroup(Assets.villageTxt, Assets.villagePng, 12);
village.swapFunction = swapHouse;
var npc:NPCSprite = new NPCSprite(48, 320, Assets.NPCPng);
npc.addSpeech("Hi, player! I'm a NPC.");
village.characters.add(npc);
add(village);
house1 = new AreaGroup(Assets.house1Txt, Assets.houseTilesPng, 10);
house1.swapFunction = swapMap;
previousPlace = new FlxPoint();
}
override public function update():void
{
super.update();
FlxG.collide(Registry.player, this);
}
private function swapHouse(tile:FlxTile, player:PlayerSprite):void
{
previousPlace.x = Registry.player.x;
previousPlace.y = Registry.player.y;
Registry.player.x = house1.doorPoint.x;
Registry.player.y = house1.doorPoint.y;
remove(village);
add(house1);
}
private function swapMap(tile:FlxTile, player:PlayerSprite):void
{
Registry.player.x = previousPlace.x;
Registry.player.y = previousPlace.y;
remove(house1);
add(village);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.