canvas控制小球跳跃不要掉进坑里小游戏代码
代码语言:html
所属分类:游戏
代码描述:canvas控制小球跳跃不要掉进坑里小游戏代码,键盘方向键控制:右-加速,左侧-制动器,向上 - 跳跃、向下 (跳跃或下降时) - 交换轨迹 1 - 禁用向前移动 2 - 启用向前移动
代码标签: canvas 控制 小球 跳跃 掉进 坑里 小游戏
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
background: #242424;
color: #666;
font-size: 8pt;
font-family: sans-serif;
padding: 0;
margin: 0;
}
</style>
</head>
<body><canvas width="860" height="480" id="canvas"></canvas>
<ul>
<li>右-加速</li>
<li>左侧-制动器</li>
<li>向上 - 跳跃</li>
<li>向下 (跳跃或下降时) - 交换轨迹</li>
<li>1 - 禁用向前移动</li>
<li>2 - 启用向前移动</li>
</ul>
<script>
var _debug = {
lockPlayerMovement: false,
showPlayerInfo: false
};
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var Shape = {};
Shape.line = function() {
this.x1 = 0;
this.y1 = 0;
this.x2 = 0;
this.y2 = 0;
this.lineWidth = 2;
this.strokeStyle = "#000000";
this.draw = function() {
context.beginPath();
context.moveTo(this.x1, this.y1);
context.lineTo(this.x2, this.y2);
context.lineWidth = this.lineWidth;
context.strokeStyle = this.strokeStyle;
context.stroke();
};
};
Shape.circle = function() {
this.x = 0;
this.y = 0;
this.radius = 0;
this.lineWidth = 2;
this.strokeStyle = "#000000";
this.fillStyle = "transparent";
this.draw = function() {
context.beginPath();
context.arc(this.x, this.y, this.radius, 0, 2 * Math.PI, false);
context.fillStyle = this.fillStyle;
context.fill();
context.lineWidth = this.lineWidth;
context.strokeStyle = this.strokeStyle;
context.stroke();
};
};
Shape.text = function() {
this.x = 0;
this.y = 0;
this.font = "10pt sans-serif";
this.textAlign = "center";
this.textBaseline = "middle";
this.fillStyle = "black";
this.fillText = "";
this.draw = function() {
context.font = this.font;
context.textAlign = this.center;
context.textBaseline = this.textBaseline;
context.fillStyle = this.fillStyle;
con.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0