Created
October 30, 2013 02:45
-
-
Save videlais/7226468 to your computer and use it in GitHub Desktop.
ActionScript 3 Example 8 MapGroup Version 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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