html5 phaser,html5 – 如何在没有窗口的情况下运行Phaser引擎?

我目前正在使用

HTML5框架Phaser创建一个多人游戏.

这是一个僵尸在地图上产生的游戏,玩家必须射杀它们才能杀死它们.僵尸瞄准最接近他们的玩家.

目前,我的设计策略存在问题.由于运动跟踪,我不确定Phaser是否可以使用这种类型的游戏.

目前,客户端正在处理所有玩家移动,因此每当玩家移动时,它会将其广播到服务器,然后服务器将其发送给所有其他客户端.

但是,我想让僵尸和子弹完全由服务器控制.然后,服务器使用每个僵尸的速度及其当前位置更新每个客户端.我的理由是,任何非玩家输入的内容都应由服务器计算.这将防止诸如两个客户说不同时间僵尸死亡然后试图彼此通信,同时在不同位置有子弹,或者在客户之间的不同时间产生僵尸的问题.

这是一个僵尸类的例子:

function Zombie(game,data){

this.game = game;

this.id = data.id;

Phaser.Sprite.call(this,this.game,data.x,data.y,'zombie');

this.anchor.setTo(0.5,0.5);

this.animations.add('right',[0,1,2,3],7,true);

this.animations.add('left',[4,5,6,7],true);

this.game.physics.arcade.enable(this);

this.body.collideWorldBounds = true;

this.health = data.health;

this.maxHealth = data.maxHealth;

this.speed = data.speed;

this.target = this.game.player;

this.waiting = 100;

this.name = "zombie";

this.healthBary = 20;

this.healthBar = this.game.add.sprite(this.x,this.y + this.healthBary,'player_health');

this.healthBar.anchor.setTo(0.5,0.5);

CollisionManager.addObjectToGroup(this,'baddies');

this.game.add.existing(this);

}

Zombie.prototype = Object.create( Phaser.Sprite.prototype );

Zombie.prototype.constructor = Zombie;

Zombie.prototype.update = function(){

this.updateHealthBar();

this.moveTowards(this.target);

Zombie.prototype.uTarget = function(target) {

this.target = target;

};

Zombie.prototype.moveTowards = function(target){

var x = target.x - this.x;

var y = target.y - this.y;

var mag = Math.sqrt((x * x) + (y * y));

var nx = x / mag;

var ny = y / mag;

this.body.velocity.x = nx * this.speed;

this.body.velocity.y = ny * this.speed;

if(this.body.velocity.x >= 0){

this.animations.play('right');

}

else if(this.body.velocity.x < 0){

this.animations.play('left')

}

}

Zombie.prototype.updateHealthBar = function(){

this.healthBar.x = this.x;

this.healthBar.y = this.y + this.healthBary;

var p = (this.health / this.maxHealth);

p = parseFloat(p.toFixed(1));

this.healthBar.frame = 10 - (p * 10);

}

Zombie.prototype._damage = function(amount){

this.health -= amount;

if(this.health <= 0){

this.kill;

this.die(true);

}

}

Zombie.prototype.die = function(points){

if(this.game){

//this.game.baddie_die_sfx.play();

}

WaveManager.onMap--;

CollisionManager.removeObjectFromGroup(this,"baddies");

if(this.healthBar){

this.healthBar.destroy();

}

socket.emit("kill zombie",{id: this.id});

this.kill();

this.destroy();

}@H_301_13@

问题是我无法在服务器上创建Phaser游戏对象(因为它在Linux服务器上运行),因为没有可以使用的窗口.为了碰撞检测,子弹和僵尸需要是Phaser对象,但我不能在服务器上这样做.

我知道我可以创建一个僵尸和子弹服务器端的向量,它可以在任何给定时间获得每个项目符号/僵尸位置的信息,然后更新客户端,但之后我将无法在Phaser中使用CollisionManager .

现在,似乎我唯一的解决方案是创建我自己的碰撞检测系统.还有其他想法吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值