Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “意外”;“非法退货声明”;_Javascript_Html_Canvas_Game Physics - Fatal编程技术网

Javascript “意外”;“非法退货声明”;

Javascript “意外”;“非法退货声明”;,javascript,html,canvas,game-physics,Javascript,Html,Canvas,Game Physics,我这里有我的代码: var canvas=document.getElementById('c'); var ctx=c.getContext('2d'); 变量播放器={ x:0,, y:0, 宽度:20, 身高:20, 速度:3,, velX:0, 结果:0,, 跳跃:错, 接地:错, 重力:0.35, 摩擦力:0, glitchCooldown:0, 钥匙:[] }; var墙壁=[]; 推({ x:50, y:230, 宽度:20, 身高:20 }) 推({ x:150, y:230,

我这里有我的代码:

var canvas=document.getElementById('c');
var ctx=c.getContext('2d');
变量播放器={
x:0,,
y:0,
宽度:20,
身高:20,
速度:3,,
velX:0,
结果:0,,
跳跃:错,
接地:错,
重力:0.35,
摩擦力:0,
glitchCooldown:0,
钥匙:[]
};
var墙壁=[];
推({
x:50,
y:230,
宽度:20,
身高:20
})
推({
x:150,
y:230,
宽度:20,
身高:20
})
player.y=canvas.height-player.width;
document.body.addEventListener(“向下键控”,函数(e){
player.keys[e.keyCode]=true;
});
文件.正文.附录列表(“键控”,功能(e){
player.keys[e.keyCode]=false;
});
函数更新(){
如果(播放器键[68]){
如果(player.velX-player.speed){
player.velX--;
}
};
如果(播放器键[87]){
如果(!玩家跳跃){
player.jumping=true;
player.grounded=false;
player.velY=-player.speed*2;
}
};
if(player.keys[74]){
故障(“向后”);
};
如果(播放器键[75]){
故障('故障')
};
if(player.keys[76]){
故障('向前')
};
player.velY+=player.gravity;
player.velX*=player.摩擦力;
player.x+=player.velX;
player.y+=player.ly;
clearRect(0,0,canvas.width,canvas.height);
player.grounded=false;
对于(变量i=0;i0){
colDir=“l”;
shapeA.x+=oX;
}否则{
colDir=“r”;
shapeA.x-=oX;
}
}
}
返回colDir;
}
函数随机(){
var x=数学地板((数学随机()*10)+1);
返回x;
}

腐化
您的浏览器不支持画布标记。请更新您的浏览器。

这是因为您没有始终如一地设计代码的样式

该错误意味着您的左大括号和右大括号不匹配

线路

 if (Math.abs(vX) < hWidths && Math.abs(vY) < hHeights) {         // figures out on which side we are colliding (top, bottom, left, or right)         var oX = hWidths - Math.abs(vX),             oY = hHeights - Math.abs(vY);         if (oX >= oY) {
   /* DONT make comment run past right edge of screen put them in the line above */
   // figures out on which side we are colliding (top, bottom, left, or right)
   if (Math.abs(vX) < hWidths && Math.abs(vY) < hHeights) {         
       /* DONT use , to separate variable declarations */
       const oX = hWidths - Math.abs(vX); /*Use consts for vars that don't change*/
       const oY = hHeights - Math.abs(vY);         
       if (oX >= oY) {