⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hero.as

📁 小鱼历险记游戏
💻 AS
字号:
import mx.transitions.Tween;
import mx.transitions.easing.*;
import mx.events.EventDispatcher;
class game.Hero {
	//主角
	private var _hero:MovieClip;
	private var _life:Number;
	private var _score:Number;
	//运动的时间,越大越慢
	public var _speed = 2;
	//是否隐身
	public var _hide:Boolean = true;
	private var _mouse:Object;
	//使用Tween来制作动画
	private var _myTween1:Tween;
	private var _myTween2:Tween;
	private var scene_width:Number = Stage.width;
	private var scene_height:Number = Stage.height;
	public var addEventListener:Function;
	public var removeEventListener:Function;
	public var dispatchEvent:Function;
	function Hero() {
		_mouse = new Object();
		EventDispatcher.initialize(this);
		init();
	}
	//初始速度、分数等设置
	function init() {
		_speed = 2;
		_score = 0;
		_life = 100;
	}
	//返回实例
	function getHero():MovieClip {
		return _hero;
	}
	//重新设置位置
	function reset() {
		_hero._x = 200;
		_hero._y = 150;
	}
	//设置生命
	function setLife(n) {
		_life += n;
		if (_life<=0) {
			_life = 0;
		} else if (_life>=100) {
			_life = 100;
		}
		dispatchEvent({type:"onLife", target:this, value:_life});
	}
	//设置分数
	function setScore(n) {
		_score += n;
		if (_score<=0) {
			_score = 0;
		}
		dispatchEvent({type:"onScore", target:this, value:_score});
	}
	//小鱼死亡
	function die() {
		_hero.removeMovieClip();
		//出现死鱼的动作
	}
	//碰到敌人时的动作,有待改进
	function touch(dirx, diry) {
		_myTween1.stop();
		_myTween2.stop();
		_hero._x += dirx*10;
		_hero._y += diry*10;
	}
	//道具:加生命,加大分数,变小,变大,全食,加速,减速
	//得到道具以后出现的动作
	function action1() {
		//先移除侦听器,等动作完成后再添加佔听器
	}
	//从库中创建小鱼
	function create(path:MovieClip, name:String, depth:Number):Void {
		_hero = path.attachMovie(name, "hero", depth);
		reset();
		move();
	}
	//小鱼的移动
	function move() {
		var ins = this;
		_mouse.onMouseDown = function() {
			var obj:MovieClip = ins._hero;
			var h = obj._height/2;
			if (_ymouse>50+h && _ymouse<350-h) {
				var f:Function = Regular.easeOut;
				obj._xscale = (_xmouse>=obj._x) ? 100 : -100;
				ins._myTween1 = new Tween(obj, "_x", f, obj._x, _xmouse, ins._speed, true);
				ins._myTween2 = new Tween(obj, "_y", f, obj._y, _ymouse, ins._speed, true);
			}
		};
		Mouse.addListener(_mouse);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -