暂停状态修改,及死亡动画添加
This commit is contained in:
parent
e3c2d5c269
commit
7941696e44
18
game.js
18
game.js
@ -30,7 +30,7 @@ function Game(id,options){
|
|||||||
height:20, //高
|
height:20, //高
|
||||||
type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象
|
type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象
|
||||||
color:'#F00', //标识颜色
|
color:'#F00', //标识颜色
|
||||||
status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停
|
status:1, //对象状态,0表示隐藏,1表示正常,2表示暂停
|
||||||
orientation:0, //当前定位方向,0表示右,1表示下,2表示左,3表示上
|
orientation:0, //当前定位方向,0表示右,1表示下,2表示左,3表示上
|
||||||
speed:0, //移动速度
|
speed:0, //移动速度
|
||||||
//地图相关
|
//地图相关
|
||||||
@ -42,7 +42,8 @@ function Game(id,options){
|
|||||||
stage:null, //绑定对象与所属布景绑定
|
stage:null, //绑定对象与所属布景绑定
|
||||||
index:0, //对象索引
|
index:0, //对象索引
|
||||||
frames:1, //速度等级,内部计算器times多少帧变化一次
|
frames:1, //速度等级,内部计算器times多少帧变化一次
|
||||||
times:0, //计数
|
times:0, //刷新画布计数(用于循环动画状态判断)
|
||||||
|
timeout:0, //倒计时(用于过程动画状态判断)
|
||||||
control:{}, //控制缓存,到达定位点时处理
|
control:{}, //控制缓存,到达定位点时处理
|
||||||
update:function(){}, //更新参数信息
|
update:function(){}, //更新参数信息
|
||||||
draw:function(){} //绘制
|
draw:function(){} //绘制
|
||||||
@ -184,7 +185,7 @@ function Game(id,options){
|
|||||||
var Stage = function(options){
|
var Stage = function(options){
|
||||||
options = options||{};
|
options = options||{};
|
||||||
var settings = {
|
var settings = {
|
||||||
status:1, //布景状态,1表示正常,0表示非活动
|
status:1, //布景状态,0表示未激活,1表示正常,2表示暂停,3表示结束
|
||||||
maps:[], //地图队列
|
maps:[], //地图队列
|
||||||
audio:[], //音频资源
|
audio:[], //音频资源
|
||||||
images:[], //图片资源
|
images:[], //图片资源
|
||||||
@ -211,11 +212,14 @@ function Game(id,options){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(stage.items.length){
|
if(stage.items.length){
|
||||||
stage.items.forEach(function(item,index){
|
stage.items.forEach(function(item,index){
|
||||||
if(stage.status!=2&&item.status!=2){ //对象及布景状态不为暂停
|
if(!(f%item.frames)){
|
||||||
if(!(f%item.frames)){
|
item.times = f/item.frames; //计数器
|
||||||
item.times = f/item.frames; //计数器
|
if(item.timeout){
|
||||||
|
item.timeout--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(stage.status==1&&item.status==1){ //对象及布景状态都处于正常状态下
|
||||||
if(item.location){
|
if(item.location){
|
||||||
item.coord = item.location.position2coord(item.x,item.y);
|
item.coord = item.location.position2coord(item.x,item.y);
|
||||||
}
|
}
|
||||||
|
35
index.js
35
index.js
@ -105,15 +105,20 @@
|
|||||||
var stage = game.createStage({
|
var stage = game.createStage({
|
||||||
update:function(){
|
update:function(){
|
||||||
var stage = this;
|
var stage = this;
|
||||||
var player = this.getItemsByType(1)[0];
|
if(stage.status==1){
|
||||||
var items = this.getItemsByType(2);
|
var player = stage.getItemsByType(1)[0];
|
||||||
items.forEach(function(item){
|
var items = stage.getItemsByType(2);
|
||||||
var dx = item.x-player.x;
|
items.forEach(function(item){
|
||||||
var dy = item.y-player.y;
|
var dx = item.x-player.x;
|
||||||
if(dx*dx+dy*dy<750){
|
var dy = item.y-player.y;
|
||||||
stage.status = 2;
|
if(dx*dx+dy*dy<750){
|
||||||
}
|
stage.status = 2;
|
||||||
});
|
player.status = 3;
|
||||||
|
player.frames = 1;
|
||||||
|
player.timeout = 50;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//绘制地图
|
//绘制地图
|
||||||
@ -249,10 +254,16 @@
|
|||||||
draw:function(context){
|
draw:function(context){
|
||||||
context.fillStyle = '#FC3';
|
context.fillStyle = '#FC3';
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
if(this.times%2){
|
if(this.status<3){
|
||||||
context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.20)*Math.PI,(.5*this.orientation-.20)*Math.PI,false);
|
if(this.times%2){
|
||||||
|
context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.20)*Math.PI,(.5*this.orientation-.20)*Math.PI,false);
|
||||||
|
}else{
|
||||||
|
context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false);
|
if(this.timeout) {
|
||||||
|
context.arc(this.x,this.y,this.width/2,(.5*this.orientation+1-.02*this.timeout)*Math.PI,(.5*this.orientation-1+.02*this.timeout)*Math.PI,false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.lineTo(this.x,this.y);
|
context.lineTo(this.x,this.y);
|
||||||
context.closePath();
|
context.closePath();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user