野狼2

/* 
* 文件名: Main文件
* 创建人:  陈泽丹
* 创建时间: 20120313
* 文件描述: 
*/


package Src
{
	import flash.display.Sprite;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.display.Scene;
	import Src.Scene.SceneState;
	public class Main extends Sprite
	{
		private var m_RefreshTimer:Timer = null;
		private var m_MainScene:Sprite = null;
		private var m_SceneState:SceneState = null;
		private function Create()
		{
			m_RefreshTimer = new Timer(100,0);
			m_MainScene = new Sprite();
			m_SceneState = new SceneState();
		}
		private function Delete()
		{
			m_RefreshTimer.removeEventListener(TimerEvent.TIMER, onDrawTime);
			m_RefreshTimer = null;
			m_MainScene = null;
			m_SceneState = null;
		}
		public function Main()
		{
			// constructor code
			Create();
			this.graphics.clear();
			this.addChild(m_MainScene);
			m_RefreshTimer.addEventListener(TimerEvent.TIMER, onDrawTime);
			m_RefreshTimer.start();
		}
		private function onDrawTime(evt:TimerEvent)
		{
			m_SceneState.DrawScene(m_MainScene);
		}
	}
}


 

/* 
* 文件名: Scene文件
* 创建人:  陈泽丹
* 创建时间: 20120313
* 文件描述: 场景类接口
*/

package Src.Interface
{
	import flash.display.Sprite;
	public interface Entity
	{
		// Interface methods:
		function Create();
		function Delete();
		function DrawScene(_HDC:Sprite);
	}
}
 
package Src.Tool
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	public class Imger
	{
		private var m_Loader:Loader = null;
		private var m_szUrl:String = null;
		private var m_Img:Bitmap = null;
		public function Imger(_szUrl:String = null)
		{
			// constructor code
			m_szUrl = _szUrl;
			m_Loader = new Loader();
			m_Loader.load(new URLRequest(m_szUrl));
			m_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
		}
		private function onComplete(_evt:Event):void
		{
			m_Img = Bitmap(_evt.target.content);
			if (null == m_Img)
			{
				trace("下载" + m_szUrl + "文件失败!");
			}
			m_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
			m_Loader = null;
		}
		public function DrawImg(_destImg:BitmapData, _destPos:Point, _srcRect:Rectangle = null)
		{
			if (null != m_Img)
			{
				if (null == _srcRect)
				{
					_srcRect = new Rectangle(0,0,m_Img.bitmapData.width,m_Img.bitmapData.height);
				}
				_destImg.copyPixels(m_Img.bitmapData, _srcRect, _destPos);
			}
		}
	}
}
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	public class API_LIB
	{
		public function API_LIB()
		{
			// constructor code
		}
		static public function CreateBmp(_W:int, _H:int):Bitmap
		{
			var pBD:BitmapData = new BitmapData(_W,_H,true,0x000000);	//需0x000000,否则不支持透明图
			return new Bitmap(pBD);
		}
	}
}

/* 
* 文件名: Scene文件
* 创建人:  陈泽丹
* 创建时间: 20120313
* 文件描述: 场景状态
*/

package Src.Scene
{
	import Src.Interface.Entity;
	import flash.display.Sprite;
	public class SceneState implements Entity
	{
		private var m_States:Object = null;
		private var m_CurState:Object = null;
		public const NULL_SCENE:String = "NullScene";
		public function Create()
		{
			m_States = new Object();
			m_States[NULL_SCENE] = new NullScene();
		}
		public function Delete()
		{
			for (var i in m_States)
			{
				m_States[i].Delete();
			}
			m_States = null;
			m_CurState = null;
		}
		public function SceneState()
		{
			// constructor code
			Create();
			SelectScene(NULL_SCENE);
		}
		public function SelectScene(_szSelect:String)
		{
			m_CurState = m_States[_szSelect];
		}
		public function DrawScene(_HDC:Sprite)
		{
			if (null != m_CurState)
			{
				m_CurState.DrawScene(_HDC);
			}
			else
			{
				trace("null == m_CurState");
			}
		}
	}
}


import flash.system.System;
import flash.display.Sprite;
import Src.Interface.Entity;
import Src.Scene.NPC.BaseNPC;
class NullScene implements Entity
{
	private var m_Boss:BaseNPC = null;
	public function Create()
	{
		m_Boss = new BaseNPC();
	}
	public function Delete()
	{
		m_Boss = null;
	}
	public function NullScene()
	{
		// constructor code
		Create();
	}
	public function DrawScene(_HDC:Sprite)
	{
		_HDC.graphics.beginFill(0x0000ff);
		const x:int = flash.system.Capabilities.screenResolutionX;
		const y:int = flash.system.Capabilities.screenResolutionY;
		_HDC.graphics.drawRect(0, 0, x, y);
		_HDC.graphics.endFill();
		m_Boss.DrawScene(_HDC);
	}
}



   

你可能感兴趣的:(野狼2)