哈喽🧐
我又来啦😄
这次来发一个游戏大厅
一共有十几款游戏
全部源码在文末
主要用的html+js+css☀️
部分源码展示💡
因为码量实在是太多了,少说也得有一万五千来行💻
我放上几个游戏、游戏大厅和登录界面的源码😄
冒险岛
<!doctype html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #f2f2f2;
}
canvas {
display:block;
margin: 40px auto 20px;
border: 1px solid #333;
box-shadow: 0 0 16px 2px rgba(0,0,0,0.8);
}
p, a {
font-family: Helvetica, Arial, sans-serif;
font-size: 19px;
color: #777;
display: block;
width: 400px;
margin: 0 auto;
text-align: center;
text-decoration:none;
}
.info {
margin:14px auto;
text-align: justify;
font-size: 18px;
color: #999;
}
a {
color:#3377ee;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
/*
Copyright (c) 2013 dissimulate at codepen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Customisable map data */
var map = {
tile_size: 16,
/*
Key vairables:
id [required] - an integer that corresponds with a tile in the data array.
colour [required] - any javascript compatible colour variable.
solid [optional] - whether the tile is solid or not, defaults to false.
bounce [optional] - how much velocity is preserved upon hitting the tile, 0.5 is half.
jump [optional] - whether the player can jump while over the tile, defaults to false.
friction [optional] - friction of the tile, must have X and Y values (e.g {x:0.5, y:0.5}).
gravity [optional] - gravity of the tile, must have X and Y values (e.g {x:0.5, y:0.5}).
fore [optional] - whether the tile is drawn in front of the player, defaults to false.
script [optional] - refers to a script in the scripts section, executed if it is touched.
*/
keys: [
{id: 0, colour: '#333', solid: 0},
{id: 1, colour: '#888', solid: 0},
{id: 2,colour: '#555',solid: 1,bounce: 0.35},
{id: 3,colour: 'rgba(121, 220, 242, 0.4)',friction: {x: 0.9,y: 0.9},gravity: {x: 0,y: 0.1},jump: 1,fore: 1},
{id: 4,colour: '#777',jump: 1},
{id: 5,colour: '#E373FA',solid: 1,bounce: 1.1},
{id: 6,colour: '#666',solid: 1,bounce: 0},
{id: 7,colour: '#73C6FA',solid: 0,script: 'change_colour'},
{id: 8,colour: '#FADF73',solid: 0,script: 'next_level'},
{id: 9,colour: '#C93232',solid: 0,script: 'death'},
{id: 10,colour: '#555',solid: 1},
{id: 11,colour: '#0FF',solid: 0,script: 'unlock'}
],
/* An array representing the map tiles. Each number corresponds to a key */
data: [
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0,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movement speed when the key is pressed */
movement_speed: {
jump: 6,
left: 0.3,
right: 0.3
},
/* The coordinates at which the player spawns and the colour of the player */
player: {
x: 2,
y: 2,
colour: '#FF9900'
},
/* scripts refered to by the "script" variable in the tile keys */
scripts: {
/* you can just use "this" instead of your engine variable ("game"), but Codepen doesn't like it */
change_colour: 'game.player.colour = "#"+(Math.random()*0xFFFFFF<<0).toString(16);',
/* you could load a new map variable here */
next_level: 'alert("Yay! You won! Reloading map.");game.load_map(map);',
death: 'alert("You died!");game.load_map(map);',
unlock: 'game.current_map.keys[10].solid = 0;game.current_map.keys[10].colour = "#888";'
}
};
/* Clarity engine */
var Clarity = function () {
this.alert_errors = false;
this.log_info = true;
this.tile_size = 16;
this.limit_viewport = false;
this.jump_switch = 0;
this.viewport = {
x: 200,
y: 200
};
this.camera = {
x: 0,
y: 0
};
this.key = {
left: false,
right: false,
up: false
};
this.player = {
loc: {
x: 0,
y: 0
},
vel: {
x: 0,
y: 0
},
can_jump: true
};
window.onkeydown = this.keydown.bind(this);
window.onkeyup = this.keyup.bind(this);
};
Clarity.prototype.error = function (message) {
if (this.alert_errors) alert(message);
if (this.log_info) console.log(message);
};
Clarity.prototype.log = function (message) {
if (this.log_info) console.log(message);
};
Clarity.prototype.set_viewport = function (x, y) {
this.viewport.x = x;
this.viewport.y = y;
};
Clarity.prototype.keydown = function (e) {
var _this = this;
switch (e.keyCode) {
case 37:
_this.key.left = true;
break;
case 38:
_this.key.up = true;
break;
case 39:
_this.key.right = true;
break;
}
};
Clarity.prototype.keyup = function (e) {
var _this = this;
switch (e.keyCode) {
case 37:
_this.key.left = false;
break;
case 38:
_this.key.up = false;
break;
case 39:
_this.key.right = false;
break;
}
};
Clarity.prototype.load_map = function (map) {
if (typeof map === 'undefined'
|| typeof map.data === 'undefined'
|| typeof map.keys === 'undefined') {
this.error('Error: Invalid map data!');
return false;
}
this.current_map = map;
this.current_map.background = map.background || '#333';
this.current_map.gravity = map.gravity || {x: 0, y: 0.3};
this.tile_size = map.tile_size || 16;
var _this = this;
this.current_map.width = 0;
this.current_map.height = 0;
map.keys.forEach(function (key) {
map.data.forEach(function (row, y) {
_this.current_map.height = Math.max(_this.current_map.height, y);
row.forEach(function (tile, x) {
_this.current_map.width = Math.max(_this.current_map.width, x);
if (tile == key.id)
_this.current_map.data[y][x] = key;
});
});
});
this.current_map.width_p = this.current_map.width * this.tile_size;
this.current_map.height_p = this.current_map.height * this.tile_size;
this.player.loc.x = map.player.x * this.tile_size || 0;
this.player.loc.y = map.player.y * this.tile_size || 0;
this.player.colour = map.player.colour || '#000';
this.key.left = false;
this.key.up = false;
this.key.right = false;
this.camera = {
x: 0,
y: 0
};
this.player.vel = {
x: 0,
y: 0
};
this.log('Successfully loaded map data.');
return true;
};
Clarity.prototype.get_tile = function (x, y) {
return (this.current_map.data[y] && this.current_map.data[y][x]) ? this.current_map.data[y][x] : 0;
};
Clarity.prototype.draw_tile = function (x, y, tile, context) {
if (!tile || !tile.colour) return;
context.fillStyle = tile.colour;
context.fillRect(
x,
y,
this.tile_size,
this.tile_size
);
};
Clarity.prototype.draw_map = function (context, fore) {
for (var y = 0; y < this.current_map.data.length; y++) {
for (var x = 0; x < this.current_map.data[y].length; x++) {
if ((!fore && !this.current_map.data[y][x].fore) || (fore && this.current_map.data[y][x].fore)) {
var t_x = (x * this.tile_size) - this.camera.x;
var t_y = (y * this.tile_size) - this.camera.y;
if(t_x < -this.tile_size
|| t_y < -this.tile_size
|| t_x > this.viewport.x
|| t_y > this.viewport.y) continue;
this.draw_tile(
t_x,
t_y,
this.current_map.data[y][x],
context
);
}
}
}
if (!fore) this.draw_map(context, true);
};
Clarity.prototype.move_player = function () {
var tX = this.player.loc.x + this.player.vel.x;
var tY = this.player.loc.y + this.player.vel.y;
var offset = Math.round((this.tile_size / 2) - 1);
var tile = this.get_tile(
Math.round(this.player.loc.x / this.tile_size),
Math.round(this.player.loc.y / this.tile_size)
);
if(tile.gravity) {
this.player.vel.x += tile.gravity.x;
this.player.vel.y += tile.gravity.y;
} else {
this.player.vel.x += this.current_map.gravity.x;
this.player.vel.y += this.current_map.gravity.y;
}
if (tile.friction) {
this.player.vel.x *= tile.friction.x;
this.player.vel.y *= tile.friction.y;
}
var t_y_up = Math.floor(tY / this.tile_size);
var t_y_down = Math.ceil(tY / this.tile_size);
var y_near1 = Math.round((this.player.loc.y - offset) / this.tile_size);
var y_near2 = Math.round((this.player.loc.y + offset) / this.tile_size);
var t_x_left = Math.floor(tX / this.tile_size);
var t_x_right = Math.ceil(tX / this.tile_size);
var x_near1 = Math.round((this.player.loc.x - offset) / this.tile_size);
var x_near2 = Math.round((this.player.loc.x + offset) / this.tile_size);
var top1 = this.get_tile(x_near1, t_y_up);
var top2 = this.get_tile(x_near2, t_y_up);
var bottom1 = this.get_tile(x_near1, t_y_down);
var bottom2 = this.get_tile(x_near2, t_y_down);
var left1 = this.get_tile(t_x_left, y_near1);
var left2 = this.get_tile(t_x_left, y_near2);
var right1 = this.get_tile(t_x_right, y_near1);
var right2 = this.get_tile(t_x_right, y_near2);
if (tile.jump && this.jump_switch > 15) {
this.player.can_jump = true;
this.jump_switch = 0;
} else this.jump_switch++;
this.player.vel.x = Math.min(Math.max(this.player.vel.x, -this.current_map.vel_limit.x), this.current_map.vel_limit.x);
this.player.vel.y = Math.min(Math.max(this.player.vel.y, -this.current_map.vel_limit.y), this.current_map.vel_limit.y);
this.player.loc.x += this.player.vel.x;
this.player.loc.y += this.player.vel.y;
this.player.vel.x *= .9;
if (left1.solid || left2.solid || right1.solid || right2.solid) {
/* fix overlap */
while (this.get_tile(Math.floor(this.player.loc.x / this.tile_size), y_near1).solid
|| this.get_tile(Math.floor(this.player.loc.x / this.tile_size), y_near2).solid)
this.player.loc.x += 0.1;
while (this.get_tile(Math.ceil(this.player.loc.x / this.tile_size), y_near1).solid
|| this.get_tile(Math.ceil(this.player.loc.x / this.tile_size), y_near2).solid)
this.player.loc.x -= 0.1;
/* tile bounce */
var bounce = 0;
if (left1.solid && left1.bounce > bounce) bounce = left1.bounce;
if (left2.solid && left2.bounce > bounce) bounce = left2.bounce;
if (right1.solid && right1.bounce > bounce) bounce = right1.bounce;
if (right2.solid && right2.bounce > bounce) bounce = right2.bounce;
this.player.vel.x *= -bounce || 0;
}
if (top1.solid || top2.solid || bottom1.solid || bottom2.solid) {
/* fix overlap */
while (this.get_tile(x_near1, Math.floor(this.player.loc.y / this.tile_size)).solid
|| this.get_tile(x_near2, Math.floor(this.player.loc.y / this.tile_size)).solid)
this.player.loc.y += 0.1;
while (this.get_tile(x_near1, Math.ceil(this.player.loc.y / this.tile_size)).solid
|| this.get_tile(x_near2, Math.ceil(this.player.loc.y / this.tile_size)).solid)
this.player.loc.y -= 0.1;
/* tile bounce */
var bounce = 0;
if (top1.solid && top1.bounce > bounce) bounce = top1.bounce;
if (top2.solid && top2.bounce > bounce) bounce = top2.bounce;
if (bottom1.solid && bottom1.bounce > bounce) bounce = bottom1.bounce;
if (bottom2.solid && bottom2.bounce > bounce) bounce = bottom2.bounce;
this.player.vel.y *= -bounce || 0;
if ((bottom1.solid || bottom2.solid) && !tile.jump) {
this.player.on_floor = true;
this.player.can_jump = true;
}
}
// adjust camera
var c_x = Math.round(this.player.loc.x - this.viewport.x/2);
var c_y = Math.round(this.player.loc.y - this.viewport.y/2);
var x_dif = Math.abs(c_x - this.camera.x);
var y_dif = Math.abs(c_y - this.camera.y);
if(x_dif > 5) {
var mag = Math.round(Math.max(1, x_dif * 0.1));
if(c_x != this.camera.x) {
this.camera.x += c_x > this.camera.x ? mag : -mag;
if(this.limit_viewport) {
this.camera.x =
Math.min(
this.current_map.width_p - this.viewport.x + this.tile_size,
this.camera.x
);
this.camera.x =
Math.max(
0,
this.camera.x
);
}
}
}
if(y_dif > 5) {
var mag = Math.round(Math.max(1, y_dif * 0.1));
if(c_y != this.camera.y) {
this.camera.y += c_y > this.camera.y ? mag : -mag;
if(this.limit_viewport) {
this.camera.y =
Math.min(
this.current_map.height_p - this.viewport.y + this.tile_size,
this.camera.y
);
this.camera.y =
Math.max(
0,
this.camera.y
);
}
}
}
if(this.last_tile != tile.id && tile.script) {
eval(this.current_map.scripts[tile.script]);
}
this.last_tile = tile.id;
};
Clarity.prototype.update_player = function () {
if (this.key.left) {
if (this.player.vel.x > -this.current_map.vel_limit.x)
this.player.vel.x -= this.current_map.movement_speed.left;
}
if (this.key.up) {
if (this.player.can_jump && this.player.vel.y > -this.current_map.vel_limit.y) {
this.player.vel.y -= this.current_map.movement_speed.jump;
this.player.can_jump = false;
}
}
if (this.key.right) {
if (this.player.vel.x < this.current_map.vel_limit.x)
this.player.vel.x += this.current_map.movement_speed.left;
}
this.move_player();
};
Clarity.prototype.draw_player = function (context) {
context.fillStyle = this.player.colour;
context.beginPath();
context.arc(
this.player.loc.x + this.tile_size / 2 - this.camera.x,
this.player.loc.y + this.tile_size / 2 - this.camera.y,
this.tile_size / 2 - 1,
0,
Math.PI * 2
);
context.fill();
};
Clarity.prototype.update = function () {
this.update_player();
};
Clarity.prototype.draw = function (context) {
this.draw_map(context, false);
this.draw_player(context);
};
/* Setup of the engine */
window.requestAnimFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
return window.setTimeout(callback, 1000 / 60);
};
var canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
canvas.width = 400;
canvas.height = 400;
var game = new Clarity();
game.set_viewport(canvas.width, canvas.height);
game.load_map(map);
/* Limit the viewport to the confines of the map */
game.limit_viewport = true;
var Loop = function() {
ctx.fillStyle = '#333';
ctx.fillRect(0, 0, canvas.width, canvas.height);
game.update();
game.draw(ctx);
window.requestAnimFrame(Loop);
};
Loop();
</script>
</body>
</html>
赛车
<!doctype html>
<html>
<head>
<title></title>
<meta charset='utf-8'>
<style>
body {
background-color: #F8F3A9;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
canvas {
border-radius: .4em;
}
</style>
</head>
<body>
<canvas height="450" width="750"></canvas>
<script>
var $ = {
canvas: null,
ctx: null,
canvas2: null,
ctx2: null,
colors: {
sky: "#D4F5FE",
mountains: "#83CACE",
ground: "#8FC04C",
groundDark: "#73B043",
road: "#606a7c",
roadLine: "#FFF",
hud: "#FFF"
},
settings: {
fps: 60,
skySize: 120,
ground: {
size: 350,
min: 4,
max: 120
},
road: {
min: 76,
max: 700,
}
},
state: {
bgpos: 0,
offset: 0,
startDark: true,
curve: 0,
currentCurve: 0,
turn: 1,
speed: 27,
xpos: 0,
section: 50,
car: {
maxSpeed: 50,
friction: 0.4,
acc: 0.85,
deAcc: 0.5
},
keypress: {
up: false,
left: false,
right: false,
down: false
}
},
storage: {
bg: null
}
};
$.canvas = document.getElementsByTagName('canvas')[0];
$.ctx = $.canvas.getContext('2d');
$.canvas2 = document.createElement('canvas');
$.canvas2.width = $.canvas.width;
$.canvas2.height = $.canvas.height;
$.ctx2 = $.canvas2.getContext('2d');
window.addEventListener("keydown", keyDown, false);
window.addEventListener("keyup", keyUp, false);
drawBg();
draw();
function draw() {
setTimeout(function() {
calcMovement();
//if($.state.speed > 0) {
$.state.bgpos += ($.state.currentCurve * 0.02) * ($.state.speed * 0.2);
$.state.bgpos = $.state.bgpos % $.canvas.width;
$.ctx.putImageData($.storage.bg, $.state.bgpos, 5);
$.ctx.putImageData($.storage.bg, $.state.bgpos > 0 ? $.state.bgpos - $.canvas.width : $.state.bgpos + $.canvas.width, 5);
//}
$.state.offset += $.state.speed * 0.05;
if($.state.offset > $.settings.ground.min) {
$.state.offset = $.settings.ground.min - $.state.offset;
$.state.startDark = !$.state.startDark;
}
drawGround($.ctx, $.state.offset, $.colors.ground, $.colors.groundDark, $.canvas.width);
drawRoad($.settings.road.min + 6, $.settings.road.max + 36, 10, $.colors.roadLine);
drawGround($.ctx2, $.state.offset, $.colors.roadLine, $.colors.road, $.canvas.width);
drawRoad($.settings.road.min, $.settings.road.max, 10, $.colors.road);
drawRoad(3, 24, 0, $.ctx.createPattern($.canvas2, 'repeat'));
drawCar();
drawHUD($.ctx, 630, 340, $.colors.hud);
requestAnimationFrame(draw);
}, 1000 / $.settings.fps);
}
function drawHUD(ctx, centerX, centerY, color) {
var radius = 50, tigs = [0, 90, 135, 180, 225, 270, 315],
angle = 90;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ctx.lineWidth = 7;
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.fill();
ctx.strokeStyle = color;
ctx.stroke();
for (var i = 0; i < tigs.length; i++) {
drawTig(ctx, centerX, centerY, radius, tigs[i], 7);
}
// draw pointer
angle = map($.state.speed, 0, $.state.car.maxSpeed, 90, 360);
drawPointer(ctx, color, 50, centerX, centerY, angle);
}
function drawPointer(ctx, color, radius, centerX, centerY, angle) {
var point = getCirclePoint(centerX, centerY, radius - 20, angle),
point2 = getCirclePoint(centerX, centerY, 2, angle + 90),
point3 = getCirclePoint(centerX, centerY, 2, angle - 90);
ctx.beginPath();
ctx.strokeStyle = "#FF9166";
ctx.lineCap = 'round';
ctx.lineWidth = 4;
ctx.moveTo(point2.x, point2.y);
ctx.lineTo(point.x, point.y);
ctx.lineTo(point3.x, point3.y);
ctx.stroke();
ctx.beginPath();
ctx.arc(centerX, centerY, 9, 0, 2 * Math.PI, false);
ctx.fillStyle = color;
ctx.fill();
}
function drawTig(ctx, x, y, radius, angle, size) {
var startPoint = getCirclePoint(x, y, radius - 4, angle),
endPoint = getCirclePoint(x, y, radius - size, angle)
ctx.beginPath();
ctx.lineCap = 'round';
ctx.moveTo(startPoint.x, startPoint.y);
ctx.lineTo(endPoint.x, endPoint.y);
ctx.stroke();
}
function getCirclePoint(x, y, radius, angle) {
var radian = (angle / 180) * Math.PI;
return {
x: x + radius * Math.cos(radian),
y: y + radius * Math.sin(radian)
}
}
function calcMovement() {
var move = $.state.speed * 0.01,
newCurve = 0;
if($.state.keypress.up) {
$.state.speed += $.state.car.acc - ($.state.speed * 0.015);
} else if ($.state.speed > 0) {
$.state.speed -= $.state.car.friction;
}
if($.state.keypress.down && $.state.speed > 0) {
$.state.speed -= 1;
}
// Left and right
$.state.xpos -= ($.state.currentCurve * $.state.speed) * 0.005;
if($.state.speed) {
if($.state.keypress.left) {
$.state.xpos += (Math.abs($.state.turn) + 7 + ($.state.speed > $.state.car.maxSpeed / 4 ? ($.state.car.maxSpeed - ($.state.speed / 2)) : $.state.speed)) * 0.2;
$.state.turn -= 1;
}
if($.state.keypress.right) {
$.state.xpos -= (Math.abs($.state.turn) + 7 + ($.state.speed > $.state.car.maxSpeed / 4 ? ($.state.car.maxSpeed - ($.state.speed / 2)) : $.state.speed)) * 0.2;
$.state.turn += 1;
}
if($.state.turn !== 0 && !$.state.keypress.left && !$.state.keypress.right) {
$.state.turn += $.state.turn > 0 ? -0.25 : 0.25;
}
}
$.state.turn = clamp($.state.turn, -5, 5);
$.state.speed = clamp($.state.speed, 0, $.state.car.maxSpeed);
// section
$.state.section -= $.state.speed;
if($.state.section < 0) {
$.state.section = randomRange(1000, 9000);
newCurve = randomRange(-50, 50);
if(Math.abs($.state.curve - newCurve) < 20) {
newCurve = randomRange(-50, 50);
}
$.state.curve = newCurve;
}
if($.state.currentCurve < $.state.curve && move < Math.abs($.state.currentCurve - $.state.curve)) {
$.state.currentCurve += move;
} else if($.state.currentCurve > $.state.curve && move < Math.abs($.state.currentCurve - $.state.curve)) {
$.state.currentCurve -= move;
}
if(Math.abs($.state.xpos) > 550) {
$.state.speed *= 0.96;
}
$.state.xpos = clamp($.state.xpos, -650, 650);
}
function keyUp(e) {
move(e, false);
}
function keyDown(e) {
move(e, true);
}
function move(e, isKeyDown) {
if(e.keyCode >= 37 && e.keyCode <= 40) {
e.preventDefault();
}
if(e.keyCode === 37) {
$.state.keypress.left = isKeyDown;
}
if(e.keyCode === 38) {
$.state.keypress.up = isKeyDown;
}
if(e.keyCode === 39) {
$.state.keypress.right = isKeyDown;
}
if(e.keyCode === 40) {
$.state.keypress.down = isKeyDown;
}
}
function randomRange(min, max) {
return min + Math.random() * (max - min);
}
function norm(value, min, max) {
return (value - min) / (max - min);
}
function lerp(norm, min, max) {
return (max - min) * norm + min;
}
function map(value, sourceMin, sourceMax, destMin, destMax) {
return lerp(norm(value, sourceMin, sourceMax), destMin, destMax);
}
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
function drawBg() {
$.ctx.fillStyle = $.colors.sky;
$.ctx.fillRect(0, 0, $.canvas.width, $.settings.skySize);
drawMountain(0, 60, 200);
drawMountain(280, 40, 200);
drawMountain(400, 80, 200);
drawMountain(550, 60, 200);
$.storage.bg = $.ctx.getImageData(0, 0, $.canvas.width, $.canvas.height);
}
function drawMountain(pos, height, width) {
$.ctx.fillStyle = $.colors.mountains;
$.ctx.strokeStyle = $.colors.mountains;
$.ctx.lineJoin = "round";
$.ctx.lineWidth = 20;
$.ctx.beginPath();
$.ctx.moveTo(pos, $.settings.skySize);
$.ctx.lineTo(pos + (width / 2), $.settings.skySize - height);
$.ctx.lineTo(pos + width, $.settings.skySize);
$.ctx.closePath();
$.ctx.stroke();
$.ctx.fill();
}
function drawSky() {
$.ctx.fillStyle = $.colors.sky;
$.ctx.fillRect(0, 0, $.canvas.width, $.settings.skySize);
}
function drawRoad(min, max, squishFactor, color) {
var basePos = $.canvas.width + $.state.xpos;
$.ctx.fillStyle = color;
$.ctx.beginPath();
$.ctx.moveTo(((basePos + min) / 2) - ($.state.currentCurve * 3), $.settings.skySize);
$.ctx.quadraticCurveTo((((basePos / 2) + min)) + ($.state.currentCurve / 3) + squishFactor, $.settings.skySize + 52, (basePos + max) / 2, $.canvas.height);
$.ctx.lineTo((basePos - max) / 2, $.canvas.height);
$.ctx.quadraticCurveTo((((basePos / 2) - min)) + ($.state.currentCurve / 3) - squishFactor, $.settings.skySize + 52, ((basePos - min) / 2) - ($.state.currentCurve * 3), $.settings.skySize);
$.ctx.closePath();
$.ctx.fill();
}
function drawCar() {
var carWidth = 160,
carHeight = 50,
carX = ($.canvas.width / 2) - (carWidth / 2),
carY = 320;
// shadow
roundedRect($.ctx, "rgba(0, 0, 0, 0.35)", carX - 1 + $.state.turn, carY + (carHeight - 35), carWidth + 10, carHeight, 9);
// tires
roundedRect($.ctx, "#111", carX, carY + (carHeight - 30), 30, 40, 6);
roundedRect($.ctx, "#111", (carX - 22) + carWidth, carY + (carHeight - 30), 30, 40, 6);
drawCarBody($.ctx);
}
function drawCarBody(ctx) {
var startX = 299, startY = 311,
lights = [10, 26, 134, 152],
lightsY = 0;
/* Front */
roundedRect($.ctx, "#C2C2C2", startX + 6 + ($.state.turn * 1.1), startY - 18, 146, 40, 18);
ctx.beginPath();
ctx.lineWidth="12";
ctx.fillStyle="#FFFFFF";
ctx.strokeStyle="#FFFFFF";
ctx.moveTo(startX + 30, startY);
ctx.lineTo(startX + 46 + $.state.turn, startY - 25);
ctx.lineTo(startX + 114 + $.state.turn, startY - 25);
ctx.lineTo(startX + 130, startY);
ctx.fill();
ctx.stroke();
/* END: Front */
ctx.lineWidth="12";
ctx.lineCap = 'round';
ctx.beginPath();
ctx.fillStyle="#DEE0E2";
ctx.strokeStyle="#DEE0E2";
ctx.moveTo(startX + 2, startY + 12 + ($.state.turn * 0.2));
ctx.lineTo(startX + 159, startY + 12 + ($.state.turn * 0.2));
ctx.quadraticCurveTo(startX + 166, startY + 35, startX + 159, startY + 55 + ($.state.turn * 0.2));
ctx.lineTo(startX + 2, startY + 55 - ($.state.turn * 0.2));
ctx.quadraticCurveTo(startX - 5, startY + 32, startX + 2, startY + 12 - ($.state.turn * 0.2));
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.lineWidth="12";
ctx.fillStyle="#DEE0E2";
ctx.strokeStyle="#DEE0E2";
ctx.moveTo(startX + 30, startY);
ctx.lineTo(startX + 40 + ($.state.turn * 0.7), startY - 15);
ctx.lineTo(startX + 120 + ($.state.turn * 0.7), startY - 15);
ctx.lineTo(startX + 130, startY);
ctx.fill();
ctx.stroke();
roundedRect(ctx, "#474747", startX - 4, startY, 169, 10, 3, true, 0.2);
roundedRect(ctx, "#474747", startX + 40, startY + 5, 80, 10, 5, true, 0.1);
ctx.fillStyle = "#FF9166";
lights.forEach(function(xPos) {
ctx.beginPath();
ctx.arc(startX + xPos, startY + 20 + lightsY, 6, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
lightsY += $.state.turn * 0.05;
});
ctx.lineWidth="9";
ctx.fillStyle="#222222";
ctx.strokeStyle="#444";
roundedRect($.ctx, "#FFF", startX + 60, startY + 25, 40, 18, 3, true, 0.05);
}
function roundedRect(ctx, color, x, y, width, height, radius, turn, turneffect) {
var skew = turn === true ? $.state.turn * turneffect : 0;
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo(x + radius, y - skew);
// top right
ctx.lineTo(x + width - radius, y + skew);
ctx.arcTo(x + width, y + skew, x + width, y + radius + skew, radius);
ctx.lineTo(x + width, y + radius + skew);
// down right
ctx.lineTo(x + width, (y + height + skew) - radius);
ctx.arcTo(x + width, y + height + skew, (x + width) - radius, y + height + skew, radius);
ctx.lineTo((x + width) - radius, y + height + skew);
// down left
ctx.lineTo(x + radius, y + height - skew);
ctx.arcTo(x, y + height - skew, x, (y + height - skew) - radius, radius);
ctx.lineTo(x, (y + height - skew) - radius);
// top left
ctx.lineTo(x, y + radius - skew);
ctx.arcTo(x, y - skew, x + radius, y - skew, radius);
ctx.lineTo(x + radius, y - skew);
ctx.fill();
}
function drawGround(ctx, offset, lightColor, darkColor, width) {
var pos = ($.settings.skySize - $.settings.ground.min) + offset, stepSize = 1, drawDark = $.state.startDark, firstRow = true;
ctx.fillStyle = lightColor;
ctx.fillRect(0, $.settings.skySize, width, $.settings.ground.size);
ctx.fillStyle = darkColor;
while(pos <= $.canvas.height) {
stepSize = norm(pos, $.settings.skySize, $.canvas.height) * $.settings.ground.max;
if(stepSize < $.settings.ground.min) {
stepSize = $.settings.ground.min;
}
if(drawDark) {
if(firstRow) {
ctx.fillRect(0, $.settings.skySize, width, stepSize - (offset > $.settings.ground.min ? $.settings.ground.min : $.settings.ground.min - offset));
} else {
ctx.fillRect(0, pos < $.settings.skySize ? $.settings.skySize : pos, width, stepSize);
}
}
firstRow = false;
pos += stepSize;
drawDark = !drawDark;
}
}
</script>
</body>
</html>
登录界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录</title>
<style>
body {
background: url('https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_1280.jpg') no-repeat;
background-size: 100% 130%;
}
#login_box {
width: 20%;
height: 400px;
background-color: #00000060;
margin: auto;
margin-top: 10%;
text-align: center;
border-radius: 10px;
padding: 50px 50px;
}
h2 {
color: #ffffff90;
margin-top: 5%;
}
#input-box {
margin-top: 5%;
}
span {
color: #fff;
}
input {
border: 0;
width: 60%;
font-size: 15px;
color: #fff;
background: transparent;
border-bottom: 2px solid #fff;
padding: 5px 10px;
outline: none;
margin-top: 10px;
}
button {
margin-top: 50px;
width: 60%;
height: 30px;
border-radius: 10px;
border: 0;
color: #fff;
text-align: center;
line-height: 30px;
font-size: 15px;
background-image: linear-gradient(to right, #30cfd0, #330867);
}
#sign_up {
margin-top: 45%;
margin-left: 60%;
}
a {
color: #b94648;
}
</style>
</head>
<body>
<div id="login_box">
<h2>LOGIN</h2>
<div id="input_box">
<input type="text" placeholder="请输入用户名">
</div>
<div class="input_box">
<input type="password" placeholder="请输入密码">
</div>
<button onclick="window.location.href='yx.html'" type="button" id="add">登录</button><br>
</div>
</body>
</html>
下载完整源码👇
链接:百度网盘地址
提取码:92px
拜拜
对了,那个源码下载下来是很多html文件
如果想看源码 就把文件后缀html改成txt打开
或者把文件复制到html编辑器里
可以自己完善一下
如果有问题私信我💡
百度网盘下载有问题的
评论里回复你的邮箱,我发一份给你😄