我称它为:偷火种的普罗米修斯

纯代码不含图片,复制粘贴即可使用
新手请点击下方链接,包教包会
一次就能学废



<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Canvas激流勇进</title><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><p>使用键盘方向键(上、左、右)控制移动</p><script>
/* Customisable map data */var map = {tile_size: 16,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'}],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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2],[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2],[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2],[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]],gravity: {x: 0,y: 0.3},vel_limit: {x: 2,y: 16},movement_speed: {jump: 6,left: 0.3,right: 0.3},player: {x: 2,y: 2,colour: '#FF9900'},scripts: {change_colour: 'game.player.colour = "#"+(Math.random()*0xFFFFFF<<0).toString(16);',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";'}
};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 cameravar 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);
};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);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>

地图可略做修改,请大胆尝试,尝试前,请备份源文件。



  好消息!好消息!我的晚年巨作:激流勇进 V3.0 上线了,点击获取,附地图详解及详细玩法、教程。

推荐阅读:

激流勇进 V3.0

诺基亚贪吃蛇

阿波罗的轻语

游动的花花肠子

JS--你没玩过的激流勇进相关推荐

  1. 好久没玩laravel了,5.6玩下(三)

    好久没玩laravel了,5.6玩下(三) 好了,基础的测试通了,咱们开始增删改了 思路整理 先创建项目功能控制器 然后设置路由访问规则 然后开发项目的增删改功能 1 先创建项目的控制器 php ar ...

  2. 杀疯了!通过游戏“元宇宙”,Deepmind让AI学会玩各种没玩过的游戏,骚操作不断...

    来源:大数据文摘本文约1800字,建议阅读7分钟 面对任务一看就会的AI,离我们心里的通用人工智能还有多远呢? 对于AI来说,完成一个单一任务或许相对简单,但是涉及到合作和博弈时,AI往往显得有些愚蠢 ...

  3. 7月31日云栖精选夜读 | 在浏览器上也能训练神经网络?TensorFlow.js带你玩游戏~...

    无论你是刚开始深度学习,亦或是个老练的老手,建立一个神经网络的训练环境有时都会很痛苦.让神经网络的训练像加载一个网页,然后点击几下,然后你就准备好马上进行推理,会不会是件很棒的事呢?(那必须棒) 在本 ...

  4. 00后没玩过的电脑编程游戏

    今天老袁给90后的同胞们带来一段小时候的回忆,要是你没玩过就证明你是00后,反正我不承我玩过,我就是个00后.游戏名字叫滑雪者,不知道大家有没有玩过这个游戏哈,我也是小时候玩过.废话不多说了直接上代码 ...

  5. 计算机里没有四款小游戏,90后最爱玩的4款“4399”小游戏,一个都没玩过的太可怜!...

    原标题:90后最爱玩的4款"4399"小游戏,一个都没玩过的太可怜! 对于90后的小伙伴们来说,现在的很多东西都属于童年的回忆了,而在我们那个年代,电脑游戏还不是非常的盛行.正式流 ...

  6. 你没玩过的全新版本!Win10这些骚操作你知多少

    你没玩过的全新版本!Win10这些骚操作你知多少 [PConline技巧]不知不觉,Win10与我们相伴已经整整四个年头了,从最开始的组团抗拒到现在的默默接受,个中滋味相信谁心里都有个数.近日微软开始 ...

  7. 用手机UC浏览器页面打开vue项目,图片,css,js都没加载

    用手机UC浏览器页面打开vue项目,图片,css,js都没加载 用HBuilder X创建了一个普通的vue项目,在电脑上使用浏览器看没有什么问题,然后提交到了公司的服务器上,发现用手机,除了火狐,谷 ...

  8. 计算机课上玩的打字游戏,上电脑课时偷偷玩的3个游戏,这些都没玩过,别说自己玩过游戏!...

    原标题:上电脑课时偷偷玩的3个游戏,这些都没玩过,别说自己玩过游戏! 大家好啊,小编又和大家见面了,想必大家都知道,电脑在被发明出来以后,游戏也是随之而然的被加入到了电脑中,而在一开始的时候电脑的游戏 ...

  9. 微型计算机能不能玩lol,微机课才能玩的3款“单机游戏”,CS上榜,没玩过的别说有童年...

    原标题:微机课才能玩的3款"单机游戏",CS上榜,没玩过的别说有童年 如果要说我们上中学时候最喜欢上的课是什么,相信很多小伙伴都会异口同声的说道是微机课,因为我们在上微机课的时候不 ...

最新文章

  1. 剑指offer_第1题_二维数组中的查找
  2. lex/flex 笔记
  3. nrf52840 gpiote如何配置中断输入_51单片机外部中断点亮LED
  4. ISCSI 1-由零开始
  5. Thinkphp5内核大型程序员交流博客系统源码
  6. React-Native学习指南 1
  7. CCF201712-1 最小差值(100分)【序列处理】
  8. 搭建你的Spring.Net+Nhibernate+Asp.Net Mvc 框架 (三)实现数据库接口层和业务逻辑层(转)...
  9. 双系统下Ubuntu完整卸载
  10. Ubuntu自己动手本地模拟搭建git服务器
  11. c中宏定义的特殊符号
  12. 基于51单片机十字路口交通灯_5s黄灯闪烁
  13. 基于logistics回归的评分卡模型【相关理论】
  14. 跟我一起来学弹性云服务器ECS【华为云至简致远】
  15. 关于pytorch配置中遇到的问题1(YOLOV5)
  16. allowMultiQueries 设置为true不生效问题
  17. 未能找到引用的组件“Microsoft.Office.Core”
  18. 深度学习笔记其七:计算机视觉和PYTORCH
  19. 科技云报道:5G商用倒计时,你关心的都在这儿
  20. 前端工程师必须知道的网络知识(一)

热门文章

  1. 自学软件测试,该读些什么书籍?
  2. 中关村GHOST XP SP3纯净装机自选CD版2011V3(NTFS)
  3. 蠕虫病毒html,HTML 感染 DropFileName = “svchost.exe” Ramnit 蠕虫病毒 查杀解决办法
  4. 企业网站搭建的流程及方法
  5. 小程序 绑定监听函数addEvent和通知函数callEvent
  6. phpddos应对 最近新起一种udp flood的攻击形式
  7. 【C语言】之实现多达50位数相乘的运算
  8. SpaceX火箭发射成功,一文了解所用的软件技术栈
  9. 网页播放视频解决代码(来自百度知道)
  10. 防火墙开放了端口,但无法talent到端口