[ create a new paste ] login | about

Link: http://codepad.org/o7Vg9ijH    [ raw code | fork ]

Plain Text, pasted on Nov 30:
class PlayState2 extends FlxState
{
	private var _player: Player;
	private var _spawner: Spawner;
	private var _enemy: Enemy;
	private var enemyGroup: FlxTypedGroup<Enemy>;
	private var _spawninterval: Float = 0.5;
	private var _enemiesToSpawn: Int = 3;
	private var _spawnCounter: Int = 0;
	private var _map: FlxTilemap;
	
	override public function create():Void
	{
		FlxG.worldBounds.set(0, 0, 700, 350);
		FlxG.camera.bgColor = 0xFFDDDDDD;
		_map = new FlxTilemap();
		_map.loadMapFromCSV(AssetPaths.map1__csv, AssetPaths.tiles__png, 24, 24, 0, 0, 0);
		_map.setTileProperties(0, FlxObject.ANY);
		_map.setTileProperties(1, FlxObject.NONE);
		_player = new Player(3*24, 6*24);
		_spawner = new Spawner(23 * 24, 5 * 24);
		add(_map);
		add(_player);
		add(_spawner);
		super.create();		
	}

	override public function update(elapsed:Float):Void
	{
		//if i turn this on, the map stops showing. If i try collide instead, the map dissapears once they get to the end.
		//FlxG.overlap(enemyGroup, _player, killEnemy);
		
		_spawnCounter += Std.int(FlxG.timeScale);
		if (_enemiesToSpawn > 0 && _spawnCounter > _spawninterval * FlxG.updateFramerate )
			{
				spawnEnemy();
			}
		
		super.update(elapsed);
	}
	
	private function killEnemy(enemy:Enemy, goal:Player):Void
	{
		enemy.kill();
		trace("enemy dead");
	}
	
	private function spawnEnemy(): Void
	{
		//enemy group
		var enemies = new FlxTypedGroup<Enemy>();
		_enemy = enemies.recycle(Enemy);
		_enemy.setPosition(_spawner.getPosition().x, _spawner.getPosition().y);
		
		//path
		var _path = new FlxPath();
		var points:Array<FlxPoint> = _map.findPath(_spawner.getGraphicMidpoint(), _player.getGraphicMidpoint());
		_enemy.path = _path;
		_path.start(points, 500, FlxPath.FORWARD);
		
		add(_enemy);
		_enemiesToSpawn--;
		_spawnCounter = 0;
		trace("enemy spawned");
	}}


Create a new paste based on this one


Comments: