# egret-stg-demo
练习做的白鹭引擎小型飞机射击游戏
运行 `egret start server -a`
并不是常见的弹幕射击类游戏懒得设计杂兵排队出场的形式,敌人只有一台机体但是会回避、主动追上玩家并射击这种行为来制造难度。
难民版Ace Combat
主舞台StageScene侦听ENTER_FRAME事件刷新飞机子弹的位置并进行各种判断
```
private refreshStage(e:any){
//自机操作的刷新
this._playerController.btnTrigger()
this.refreshAllPosition();
if(this._collisionCheckInterval!=3){
//每3帧进行一次碰撞检测
this._collisionCheckInterval++
return;
}
this._collisionCheckInterval=0;
//自机和敌机的碰撞
if(!this._player.isInvinsible()){...}
//自机子弹的碰撞检测
for(let b of Bullet.allArr){...}
//敌机子弹的碰撞检测
if(!this._player.isInvinsible()){...}
//拾取漂流物判断
if(this._drift && this._drift.buff){...}
}
```
Controller类记录按键按下的状态刷新飞机的操作
```
public btnTrigger(e:any=null){
if(this._directX!=0 || this._directY!=0){
this._controllee.move(this._directX, this._directY);
}
if(this._shotTriggered){
this._controllee.shot();
}
}
```
飞机的移动简单地使用Timer改变坐标,冲刺则是Tween,做成了有限次数且随时间回复的形式,冲刺期间全程无敌,正常做法是冲刺开始后几帧无敌这样子,这次没有做那么细。其实我蛮讨厌捉无敌帧的
```
this.dashGaugeTimer.addEventListener(egret.TimerEvent.TIMER, this.onDashRecover, this);
public dash(dx:number, dy:number){
if(this.dashing){
return;
}
if(this.curDashGauge == 0){
return;
}
if(!this.dashGaugeTimer.running){
this.dashGaugeTimer.start();
}
this.curDashGauge --;
this.dashing = true;
...
}
protected onDashRecover(e:any){
if(this.curDashGauge < this.maxDashGauge){
this.curDashGauge ++;
}
if(this.curDashGauge == this.maxDashGauge){
this.dashGaugeTimer.reset();
}
}
public isInvinsible():boolean{
return this.dashing || this.buffManager.invinsibleBuff!=null;
}
```
射击则是从子弹池中获取Bullet实例,有一个子弹方向数组的属性,可以设置多方向射击
```
public shot(){
if(this.shotTimer.running){
return;
}
for(let i=0; i<this.bulletDirections.length; i++){
let b = this.bulletGenerator.getOne()
b.x = this.x;
b.y = this.y - this.pHeight - 50;
let d = this.bulletDirections[i];
b.setDirection(d[0], d[1])
this.parent.addChild(b);
b.shoot()
}
this.shotTimer.start()
}
//Bullet类
public static pool:Pool<Bullet> = new Pool<Bullet>(()=>{
let b = new Bullet()
Bullet.allArr.push(b);
return b;
})
//Pool类
public getOne():T{
let ret:T = null;
for(let obj of this._arr){
if(!obj.activate){
ret = obj;
break;
}
}
if(!ret){
ret = this._func();
this._arr.push(ret);
}
ret.activate = true;
return ret;
}
```
拾取道具出现的Buff,做了无敌、子弹方向+2(最多5方向发射)、子弹变大(中弹判定点从1个变3个)、得到僚机这几种,其实比起怎么做,更多考虑了平衡性比如速度、持续时间这种数值问题,毕竟只要能打出弹幕extreme难度也能乱杀==并且敌机也能拾取Buff。
```
//僚机Buff
public startEffect(owner:egret.Sprite){
super.startEffect(owner);
this.owner = owner;
let mainP:BasePlane = owner as BasePlane
this._subA = new SubPlane(mainP, "LEFT");
this._subB = new SubPlane(mainP, "RIGHT");
}
public delBuff(e:any=null){
this._subA.dispose();
this._subB.dispose();
super.delBuff(e);
}
//无敌Buff,用Tween做了闪烁的效果
public startEffect(owner:egret.Sprite){
this.owner = owner;
this._invisibleTween = egret.Tween.get(this.owner,{loop:true}).set({ alpha: 0}).wait(100).set({ alpha: 1}).wait(100)
if(this.timer){
this.timer.start();
}
}
public delBuff(e:any=null){
this._invisibleTween.pause().set({alpha:1})
super.delBuff(e)
}
```
虽然可以通过子弹上限、射击间隔参数等进一步限制玩家的强度,但就不做那么严格了,仍然可以通过左右移动射出弹幕轻松击中敌机。相对地设计了3种难度:normal,elite(数值比normal高并会持续射击),extreme(数值更高,并在追及玩家时会左右移动制造弹幕)。但是ai行为设计得不太满意,造成了一些不自然的表现:
现在的做法,通过全局的ENTER_FRAME时间控制移动,导致速度值设置得较高的extreme难度敌机仿佛瞬间移动一样,之后再改成单独处理。此外速度值高于玩家飞机就可以在x轴上轻松追上玩家,如果玩家不进行射击迫使敌机在x轴上移动的话,就变得好像双方操作同步了一样,敌机总是在x轴上同步移动紧跟着玩家,看上去很怪异==
AI行为,是根据飞机、子弹的位置确定下一个行为是攻击还是躲避并确定移动点。实际效果微妙,不能说聪明但也算能作出合理的行动,偶尔回避时往另一侧子弹上撞的问题再优化。这种AI设计我个人缺乏经验和好想法。
```
//躲避时会获取四象限方向中子弹数最少的方向
if(bp.x < this.x && bp.y < this.y - this.pHeight){
this._bulletDistribute[0] ++;
//不考虑机位后方的子弹
return;
}else if(bp.x > this.x && bp.y < this.y - this.pHeight){
this._bulletDistribute[1] ++;
//不考虑机位后方的子弹
return;
}else if(bp.x < this.x && bp.y > this.y){
this._bulletDistribute[2] ++;
}else if(bp.x > this.x && bp.y > this.y){
this._bulletDistribute[3] ++;
}
...
//根据子弹距离决定躲多远、是否使用冲刺。
if(!sameXArea && num > 1){
//子弹距离大于1机位时不改变行为
return;
}
if(!sameXArea && num < 1){
//x轴不同但位置接近,远离0.5-1机位
this.setCurPattern(AIActType.SLIGHT_AVOID);
return;
}
if(sameXArea && num < 2 && this.curDashGauge == 0){
//不能冲刺时,x轴相同但位置较远,远离1-2机位
this.setCurPattern(AIActType.AVOID);
this._movePoint = null;
return;
}
if(sameXArea && num < 1){
//x轴相同且位置接近,冲刺远离
this.setCurPattern(AIActType.DASH_AVOID);
this._movePoint = null;
return;
}
//extreme才有的制造弹幕的行为
//x轴上穿过玩家两侧射击后正对着玩家射击
if(this._playerPosition){
if(this._playerPosition.x < this.x - this.width){
this._movePoint = new egret.Point(this._playerPosition.x - this.width, this.y);
}else if(this._playerPosition.x > this.x + this.width){
this._movePoint = new egret.Point(this._playerPosition.x + this.width, this.y);
}else{
this._curPattern = AIActType.TRACE;
this._movePoint = new egret.Point(this._playerPosition.x, this.y);
}
}
```
这个demo唯一的优点就是BGM了吧,不愧是名曲,还能剪成4段来用
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaScript实现的白鹭引擎飞机射击小游戏【100012541】
共207个文件
ts:81个
png:37个
js:27个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 158 浏览量
2023-05-31
14:14:42
上传
评论
收藏 3.33MB ZIP 举报
温馨提示
使用JavaScript实现的白鹭引擎飞机射击小游戏。本项目并不是常见的弹幕射击类游戏,而是敌人只有一台机体但是会回避、主动追上玩家并射击。主舞台StageScene侦听ENTER_FRAME事件刷新飞机子弹的位置并进行各种判断;飞机的移动简单地使用Timer改变坐标;射击则是从子弹池中获取Bullet实例,有一个子弹方向数组的属性,可以设置多方向射击。
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaScript实现的白鹭引擎飞机射击小游戏【100012541】 (207个子文件)
.DS_Store 8KB
.DS_Store 6KB
index.ejs 2KB
Description.exml 1KB
RadioButtonSkin.exml 863B
CheckBoxSkin.exml 851B
GameResult.exml 789B
TextInputSkin.exml 746B
BtnJet.exml 665B
PanelSkin.exml 645B
ControlPanel.exml 615B
ToggleSwitchSkin.exml 595B
ButtonSkin.exml 582B
ItemRendererSkin.exml 550B
BtnBullet.exml 500B
ProgressBarSkin.exml 499B
HSliderSkin.exml 335B
VSliderSkin.exml 325B
ScrollerSkin.exml 283B
VScrollBarSkin.exml 263B
HScrollBarSkin.exml 261B
.gitattributes 66B
index.html 3KB
index.html 3KB
favicon.ico 4KB
p1.jpg 18KB
p2.jpg 12KB
egret.js 1.12MB
eui.js 1009KB
egret.web.js 462KB
eui.min.js 207KB
egret.min.js 204KB
game.js 186KB
egret.web.min.js 138KB
assetsmanager.js 119KB
tween.js 69KB
game.min.js 40KB
sbcs-data-generated.js 31KB
assetsmanager.min.js 28KB
promise.js 28KB
dbcs-codec.js 21KB
tween.min.js 12KB
utf7.js 9KB
extend-node.js 8KB
dbcs-data.js 8KB
promise.min.js 6KB
internal.js 6KB
utf16.js 5KB
index.js 5KB
sbcs-data.js 4KB
streams.js 3KB
sbcs-codec.js 2KB
bom-handling.js 1KB
index.js 710B
cp936.json 46KB
cp950.json 41KB
eucjp.json 40KB
cp949.json 37KB
shiftjis.json 23KB
big5-added.json 17KB
default.res.json 5KB
tsconfig.json 4KB
package.json 4KB
gb18030-ranges.json 2KB
default.thm.json 2KB
gbk-added.json 1KB
tasks.json 749B
launch.json 593B
egretProperties.json 421B
launch.json 327B
tsconfig.json 299B
manifest.json 295B
package.json 271B
description.json 231B
tasks.json 207B
wingProperties.json 159B
settings.json 76B
exml.json 61B
LICENSE 1KB
LICENSE 1KB
README.md 7KB
README.md 7KB
Changelog.md 3KB
elite.mp3 786KB
extreme.mp3 735KB
normal.mp3 526KB
title.mp3 177KB
.npmignore 44B
plane3.png 14KB
plane4.png 14KB
plane1.png 10KB
egret_icon.png 7KB
bullet.png 6KB
plane2.png 6KB
bg.png 4KB
buff.png 2KB
drift.png 2KB
bg2.png 2KB
jet.png 2KB
radiobutton_select_down.png 2KB
共 207 条
- 1
- 2
- 3
资源评论
神仙别闹
- 粉丝: 2668
- 资源: 7640
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功