Почему игрок не падает все же правильно написал:
<!DOCTYPE html>
<html>
<head>
<title>Game</title>
</head>
<body>
<canvas id = "canvas" width = "320" height="480"></canvas>
<style type="text/css">#canvas{border:1px solid black;}</style>
<script type="text/javascript">
document.getElementById("canvas");
var ctx = canvas.getContext("2d");
x = 0;
y = 0;
jc = 15;
j = 0;
left = 0;
right = 0;
onground = 0;
map = [0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,0,0];
maps = [];
for(i = 0;i < map.length;i++){
if(map[i] == 1){
maps.push({x:x,y:y});
}
x+=32;
if(x >= 320){
y+=32;
x=0;
}
}
x = 0;
y = 416;
document.addEventListener("keydown",function(e){
if(e.keyCode == 87 && onground == 1){
j = 1;
}
if(e.keyCode == 65){
left = 1;
}
if(e.keyCode == 68){
right = 1;
}
});
document.addEventListener("keyup",function(e){
if(e.keyCode == 65){
left = 0;
}
if(e.keyCode == 68){
right = 0;
}
});
function draw(){
ctx.clearRect(0,0,320,480);
ctx.fillStyle = "red";
ctx.fillRect(x,y,32,32);
if(left == 1){
x-=4;
}
if(right == 1){
x+=4;
}
if(j == 1){
if(jc >= -15){
y-=jc;
jc-=1;
}else{
jc = 15;
j = 0;
}
}
ctx.fillStyle = "black";
for(i in maps){
ctx.fillRect(maps[i].x,maps[i].y,64,32);
if(y + 32 < maps[i].y && x >= maps[i].x && x + 32 <= maps[i].x + 64){
if(j == 0){
y+=1;
}
onground = 0;
}else{
onground = 1;
}
}
}
setInterval(draw,20);
</script>
</body>
</html>