分享
 
 
 

Flash游戏--大鱼吃小鱼

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

刚刚写了一部分

importmx.transitions.easing.*;

importgame.Hero;

classgame.food.Food{

//指定路径

publicvar_path:MovieClip;

//移动速度,用时间来控制,在子类中指定

privatevar_time:Number;

//默认的运动方式

privatevar_func:Function=None.easeOut;

//游戏主角

privatevar_hero:MovieClip;

//场景的尺寸

privatevar_scenex:Number=Stage.width;

privatevar_sceney:Number=Stage.height;

publicvar_id:String;

publicvaraddEventListener:Function;

publicvarremoveEventListener:Function;

publicvardispatchEvent:Function;

//与主角保持联系

publicfunctionconnectToHero(h:Hero){

_hero=h.getHero();

}

//创建一个食物

publicfunctioncreate(id:String,name:String):Void{

vardepth=_path.getNextHighestDepth();

varf:MovieClip=_path.attachMovie(id,name+depth,depth);

f._x=(depth%3==0)?random(100)+_scenex:random(100)-100;

f._y=random(_sceney-100)+50;

move(f);

}

//运动方式,由子类实现

publicfunctionmove(obj:MovieClip):Void{

}

}

importgame.food.Food;

importmx.transitions.Tween;

importmx.events.EventDispatcher;

classgame.food.FirFoodextendsFood{

//食物在库中的链接名

publicvar_id:String="f_0_0";

//食物的新实例名

privatevar_name:String="ok";

publicfunctionFirFood(){

EventDispatcher.initialize(this);

}

functioncreate(){

super.create(_id,_name);

}

functionmove(obj){

var_time:Number=random(20)+5;

var_end:Object={x:random(_scenex),y:random(50)-50+obj._y};

obj._xscale=(_end.x>=obj._x)?100:-100;

vartween1=newTween(obj,"_x",_func,obj._x,_end.x,_time,true);

vartween2=newTween(obj,"_y",_func,obj._y,_end.y,_time,true);

varins=this;

tween1.onMotionFinished=function(){

ins.move(obj);

};

tween1.onMotionChanged=function(){

if(ins._hero.hitTest(obj)){

obj.removeMovieClip();

ins.create(_id,_name);

ins.dispatchEvent({type:"onEat",target:obj});

}

};

}

}

importgame.food.Food;

importmx.transitions.Tween;

importmx.events.EventDispatcher;

classgame.food.SecFoodextendsFood{

//食物在库中的链接名

publicvar_id:String="f_0_1";

//食物的新实例名

privatevar_name:String="ok";

publicfunctionSecFood(){

EventDispatcher.initialize(this);

}

functioncreate(){

super.create(_id,_name);

}

//本想用不同的动画效果,懒得写,从上面那个复制过来算了

functionmove(obj){

//根据不同的情况设置不同的速度,以增加难度

var_time:Number=random(10)+5;

var_end:Object={x:random(_scenex),y:random(50)-50+obj._y};

obj._xscale=(_end.x>=obj._x)?100:-100;

vartween1=newTween(obj,"_x",_func,obj._x,_end.x,_time,true);

vartween2=newTween(obj,"_y",_func,obj._y,_end.y,_time,true);

varins=this;

tween1.onMotionFinished=function(){

ins.move(obj);

};

tween1.onMotionChanged=function(){

if(ins._hero.hitTest(obj)){

ins.dispatchEvent({type:"onHit",target:obj});

}

};

}

}

classgame.Hero{

privatevar_hero:MovieClip;

privatevar_life:Number=100;

privatevar_moveID:Number;

privatevarscene_width:Number=Stage.width;

privatevarscene_height:Number=Stage.height;

functionHero(){

}

functioncreate(path:MovieClip,name:String,depth:Number):Void{

_hero=path.attachMovie(name,"hero",depth);

_moveID=setInterval(this,"move",30);

}

functionmove(){

varspeed=4

if(Key.isDown(Key.LEFT)){

_hero._x-=speed;

_hero._xscale=-100;

}

if(Key.isDown(Key.RIGHT)){

_hero._x+=speed;

_hero._xscale=100;

}

if(Key.isDown(Key.UP)){

_hero._y-=speed;

}

if(Key.isDown(Key.DOWN)){

_hero._y+=speed;

}

if(_hero._x>scene_width-_hero._width/2){

_hero._x=scene_width-_hero._width/2;

}

if(_hero._x<0+_hero._width/2){

_hero._x=_hero._width/2;

}

if(_hero._y>scene_height-_hero._height/2){

_hero._y=scene_height-_hero._height/2;

}

if(_hero._y<0+_hero._height/2){

_hero._y=_hero._height/2;

}

}

functiongetHero():MovieClip{

return_hero;

}

}

importgame.Hero;

importgame.food.*;

importmx.utils.Delegate;

classgame.Player{

//放置游戏的路径

privatevar_target:MovieClip;

//游戏难度

privatevar_level:Number;

//游戏分数

privatevar_score:Number=0;

//游戏主角

privatevar_hero:Hero;

privatevar_life=1000;

//食物

privatevar_food:FirFood;

privatevar_food_test:SecFood;

functionPlayer(tar){

_target=tar;

_food=newFirFood();

_food_test=newSecFood();

initHero();

initFood();

initFood_test();

}

//创建主角

functioninitHero(){

_hero=newHero();

//对数:路径,链接名,深度

_hero.create(_target,"hero",1000);

}

functioninitFood(){

_food._path=_target;

_food.connectToHero(_hero);

for(vari=0;i<10;i++){

_food.create();

}

_food.addEventListener("onEat",Delegate.create(this,setScore));

}

functionsetScore(){

_score+=100;

//升级测试

update();

_target._showScore.text=String(_score);

}

functioninitFood_test(){

_food_test._path=_target;

_food_test.connectToHero(_hero);

for(vari=0;i<10;i++){

_food_test.create();

}

_food_test.addEventListener("onHit",Delegate.create(this,setLife));

}

functionsetLife(){

if(_life>0){

_life-=10;

_target._showLife.text=String(_life);

}

}

functionupdate(){

if(_score==1000){

_food._id="f_0_1";

initFood();

_food_test._id="f_0_2";

initFood_test();

trace("ss");

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有