*伪3D空间射击游戏
*swf演示上传至http://www.swfcabin.com/
演示:http://www.swfcabin.com/open/1314079090
更新记录
v0.1 20110823
#上个月为了推广游戏花2天半搞的一个,算是第一次接触伪3D,自己想的公式,所以玩起来还会有些奇怪现象(有些敌机越追越近,有些则越远)。当时只用过一次就不用了,现在觉得扔了浪费,就先上传当一个小项目,不知未来能进化到什么程度…其实是想做成伪3D空间引擎,并不是away3d那样,而是更倾向于易用和展现。
#上传 & 共享。
待处理
@优化代码,模块化。
@容易找不到最后一架敌机。
@相对移动速度有错误。
@敌机坐标可显示(雷达)
@攻击时射击轨迹计算(远近规律、移动中抛物线规律)
@副武器可用。
@敌人会进行攻击。
@空间角度及距离计算要精确。
@使用AS3编写,学习Point3D类。
@流畅度优先
@游戏基本说明
@生命槽,不知道怎么死
@鼠标的上移和你的飞行速度挂钩
@连击系统,你在一定时间内 连续的击破敌机可以获得比单独击破一架获得更高的分数
@积分系统,用这些积分 还可以变成游戏中的金钱 购买和升级武器,飞机的生命槽 推进器 武器威力 装填时间 冷却时间,都会消耗大量的积分.
@购买武器
源代码
_root
//允许跨域调用,重要 System.security.allowDomain("*"); var stageWidth = Stage.width; var stageHeight = Stage.height; //战机初始 aircraft._x = stageWidth/2; aircraft._y = stageHeight-stageHeight/5; //战机Y坐标 var aircraftY = aircraft._y; var aircraftX = aircraft._x; crosshair.crosshairHold._alpha=0;//光标锁定隐藏 //图表初始 enemyNum=8;//敌机数 youKilled = enemyNum; youRoute = 0; youSpeed = 0; var taskStatus=false;//任务状态 var taskStatusHold=true;//状态锁定 var quickOpen =false; //深度 aircraft.swapDepths(999); faceShell.swapDepths(1000); crosshair.swapDepths(998); var firstWeaponPowerRun=30;//能量消耗量 //副武器图标 for (var j = 0; j<6; j++) { weaponIcon.duplicateMovieClip("weaponIcon_s"+j, j*10+1); var weaponIcon_s:MovieClip = eval("weaponIcon_s"+j); weaponIcon_s._x = j*15+695; weaponIcon_s._y = 470; } //敌机图标 for (var i = 1; i<enemyNum; i++) { enemy_s0.duplicateMovieClip("enemy_s"+i,enemy_s0.getDepth()-i); var enemy_s:MovieClip = eval("enemy_s"+i); enemy_s._x = random(1000); enemy_s._y = random(560); } this.onEnterFrame = function() { //准心 crosshair._x = _xmouse; crosshair._y = _ymouse; //准心反应效果 //战机角度&喷射 if (_xmouse>stageWidth/2+50) { aircraft._rotation = (_xmouse-stageWidth/2)/10; } else { aircraft._rotation = -(stageWidth/2-_xmouse)/10; } aircraft.rightPower._alpha = 110-_xmouse/10; aircraft.leftPower._alpha = _xmouse/10+20; if (_ymouse>stageHeight/2) { aircraft._y = aircraftY+(_ymouse-stageHeight/2)/10; } else { aircraft._y = aircraftY-(stageHeight/2-_ymouse)/10; } aircraft.MidPower._alpha = 56-_ymouse/10; aircraft._height = _xmouse/200+200; //攻击线效果 //主武器能量恢复 if (taskStatusHold){ if(faceShell.firstWeaponPower._width<150){ faceShell.firstWeaponPower._width+=1; } if (faceShell.firstWeaponPower._width<=firstWeaponPowerRun){ faceShell.firstWeaponPower._alpha=50; }else{ faceShell.firstWeaponPower._alpha=100; } } }; //背景反方向移动 bg.onEnterFrame = function() { speedX = 0; speedY = 0; if (_xmouse>=0 && _xmouse<500) { speedX = -(_xmouse-500)/30; bg._x = bg._x+speedX; if (this._x>0) { this._x = -1000; } } if (_xmouse>500 && _xmouse<1000) { speedX = -(_xmouse-500)/30; bg._x = bg._x+speedX; if (this._x<-1000) { this._x = 0; //右侧超出部分 } } if (_ymouse>=0 && _ymouse<400) { speedY = -(_ymouse-400)/30; bg._y = bg._y+speedY; if (this._y>0) { this._y = -560; } } //追赶enemy enemyAction(enemy_s0, speedX, speedY); enemyAction(enemy_s1, speedX, speedY); enemyAction(enemy_s2, speedX, speedY); //图标 if (speedX<0) { speedX = speedX*-1; } youRoute = youRoute+Math.round(speedX+speedY); youSpeed = Math.round(speedX+speedY); }; //星球反方向移动 star1.onEnterFrame = function() { if (_xmouse>=0 && _xmouse<500) { speedX = -(_xmouse-500)/30; star1._x = star1._x+speedX; if (this._x>1312) { this._x = -312; } } if (_xmouse>500 && _xmouse<1000) { speedX = -(_xmouse-500)/30; star1._x = star1._x+speedX; if (this._x<-312) { this._x = 1312; //右侧超出部分 } } if (_ymouse>=0 && _ymouse<400) { speedY = -(_ymouse-400)/30; star1._y = star1._y+speedY; if (this._y>560+298) { this._y = -1000; } } }; function enemyAction(funcName, speedX, speedY) { funcName._x += speedX; if (funcName._x>1100) { funcName._x = -500; } funcName._y += speedY; if (funcName._y>660) { funcName._y = -500; } }
bg 背景
on(release){ _parent.taskStatusHold = false; _parent.quickOpen=true; }
bgUnit 背景单元
//背景复制2x4 for (var i = 0; i<2; i++) {//y for (var j = 0; j<4; j++) {//x bgUnit.duplicateMovieClip("bgUnit_"+i+"_"+j,i*1+j*2); var bgUnit_:MovieClip= eval("bgUnit_"+i+"_"+j); bgUnit_._x=j*500; bgUnit_._y=i*560; } }
enemy_s0 敌机
on (rollOver) { _parent.crosshair.crosshairNum = this._name+"\n x:"+this._x+" y:"+this._y; _parent.crosshair.crosshairHold._alpha = 100; if (_parent.faceShell.firstWeaponPower._width<_parent.firstWeaponPowerRun && _parent.taskStatusHold == true) { _parent.taskStatus = false; _parent.taskStatusHold = false; _parent.taskBody.gotoAndPlay(2); } else { if (_parent.taskStatusHold){ _parent.faceShell.firstWeaponPower._width -= _parent.firstWeaponPowerRun; this.gotoAndPlay(2); _parent.youKilled -= 1; } //this._alpha = 0; //完成 if (_parent.youKilled<=_parent.enemyNum-8 && _parent.taskStatusHold == true) { _parent.taskStatus = true; _parent.taskStatusHold = false; _parent.taskBody.gotoAndPlay(2); } } } on (rollOut) { _parent.crosshair.crosshairNum = ""; _parent.crosshair.crosshairHold._alpha = 0; } on (release) { _parent.taskStatusHold = false; _parent.quickOpen=true; } onClipEvent (load) { cNum = 1; //越高越抖 s =10; //速度 } onClipEvent (enterFrame) { my_x = _x; my_y = _y; my_theta = _rotation; delta_dir = random(2); if (delta_dir == 0) { delta_dir = -1; } delta = cNum*delta_dir; my_theta = my_theta+delta; my_theta_rad = my_theta*3.141593/180; new_x = my_x+s*Math.cos(my_theta_rad); new_y = my_y+s*Math.sin(my_theta_rad); _rotation = my_theta; if (new_x>-100 && new_x<1100) { _x = new_x; } else { my_theta = 180-my_theta; } if (new_y>-100 && new_y<660) { _y = new_y; } else { my_theta = -my_theta; } _rotation = my_theta; }