• 激流勇进小游戏


    欢迎来到程序小院

    激流勇进

    1. 玩法:
    2. 键盘上键 ↑ 跳跃、左键 ←、右键 → 移动小球,小球闯关,遇到红色方块跳过,黄色的方块上键跳跃,快去闯关吧^^。

    开始游戏icon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/187

    html

    1. <div class="kbBox" id="kbBox"></div>
    2. <div class="startGame" id="startGame">
    3.     <a style="text-align: center;" href="javascript:void(0)" id="enterGame">进入游戏</a>
    4. </div>
    5. <div class="gameId" id="gameId" style="display: none;">
    6.     <canvas id="canvas"></canvas>
    7. </div>

    css

    1. #canvas {
    2.     display:block;
    3.     /*margin: 40px auto 20px;*/
    4.     border-left1px solid transparent;
    5.     background-clip: padding-box, border-box;
    6.     background-origin: padding-box, border-box;
    7.     background-imagelinear-gradient(to right, #fff#fff),  
    8.       linear-gradient(120deg#f7716d#60C4FD#EDC951#7ac630#f7716d
    9.         #60C4FD#EDC951#7ac630,#7ac630#f7716d#60C4FD#EDC951#7ac630);
    10.     margin:0px auto;
    11.     position: absolute;
    12.     left50%;
    13.     transformtranslateX(-50%);
    14. }
    15. .startGame{
    16.     position: absolute;
    17.     left50%;
    18.     transformtranslateX(-50%);
    19.     width400px;
    20.     height400px;
    21.     margin0 auto;
    22.     backgroundurl("/default/game/jlyj/images/123.jpg");
    23. }
    24. .startGame a{
    25.     display: block;
    26.     width100px;
    27.     height40px;
    28.     line-height40px;
    29.     position: absolute;
    30.     left:50%;
    31.     margin-left: -50px;
    32.     bottom20px;
    33.     color:white;
    34.     border:1px solid white;
    35. }

    js

    1. /* 默认的重力地图 */
    2.     gravity: {
    3.         x: 0,
    4.         y: 0.3
    5.     },
    6.     /* 速度限制*/
    7.     vel_limit: {
    8.         x: 2,
    9.         y: 16
    10.     },
    11.     /*按下键时运动速度 */
    12.     movement_speed: {
    13.         jump: 6,
    14.         left0.3,
    15.         right0.3
    16.     },
    17.     /* 球员产生的坐标和球员的颜色 */
    18.     player: {
    19.         x: 2,
    20.         y: 2,
    21.         colour: '#FF9900'
    22.     },
    23.     /* 在tile keys中由“脚本”变量引用的脚本 */
    24.     scripts: {
    25.         /* 您可以使用“this”代替您的引擎变量(“game”),但是Codepen不喜欢它 */
    26.         change_colour: 'game.player.colour = "#"+(Math.random()*0xFFFFFF<<0).toString(16);',
    27.         /* 你可以在这里载入一个新的地图变量 */
    28.         next_level: 'alert("闯关成功!");game.load_map(map);',
    29.         death: 'alert("很遗憾,闯关失败!");game.load_map(map);',
    30.         unlock'game.current_map.keys[10].solid = 0;game.current_map.keys[10].colour = "#888";'
    31.     }
    32. };
    33. /* Clarity 引擎 */
    34. var Clarity = function () {
    35.     this.alert_errors   = false;
    36.     this.log_info       = true;
    37.     this.tile_size      = 16;
    38.     this.limit_viewport = false;
    39.     this.jump_switch    = 0;
    40.     this.viewport = {
    41.         x: 200,
    42.         y: 200
    43.     };
    44.     this.camera = {
    45.         x: 0,
    46.         y: 0
    47.     };
    48.     this.key = {
    49.         leftfalse,
    50.         rightfalse,
    51.         upfalse
    52.     };
    53.     this.player = {
    54.         loc: {
    55.             x: 0,
    56.             y: 0
    57.         },
    58.         vel: {
    59.             x: 0,
    60.             y: 0
    61.         },
    62.         can_jump: true
    63.     };
    64.     window.onkeydown = this.keydown.bind(this);
    65.     window.onkeyup   = this.keyup.bind(this);
    66. };
    67. Clarity.prototype.error = function (message) {
    68.     if (this.alert_errors) alert(message);
    69.     if (this.log_info) console.log(message);
    70. };
    71. Clarity.prototype.log = function (message) {
    72.     if (this.log_info) console.log(message);
    73. };
    74. Clarity.prototype.set_viewport = function (x, y) {
    75.     this.viewport.x = x;
    76.     this.viewport.y = y;
    77. };
    78. Clarity.prototype.keydown = function (e) {
    79.     var _this = this;
    80.     switch (e.keyCode) {
    81.         case 37:
    82.             _this.key.left = true;
    83.             break;
    84.         case 38:
    85.             _this.key.up = true;
    86.             break;
    87.         case 39:
    88.             _this.key.right = true;
    89.             break;
    90.     }
    91. };
    92. Clarity.prototype.keyup = function (e) {
    93.     var _this = this;
    94.     switch (e.keyCode) {
    95.         case 37:
    96.             _this.key.left = false;
    97.             break;
    98.         case 38:
    99.             _this.key.up = false;
    100.             break;
    101.         case 39:
    102.             _this.key.right = false;
    103.             break;
    104.     }
    105. };

    源码icon-default.png?t=N7T8https://www.ormcc.com/

    需要源码请关注添加好友哦^ ^

    转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

  • 相关阅读:
    类图 UML从入门到放弃系列之二
    LeetCode530.二叉搜索树的最小绝对差 501二叉搜索树中的众数 236二叉树的最近公共祖先
    【云原生之Docker实战】使用Docker部署mBlog微博系统
    视频编解码 — 码控算法
    matlab绘制尖角colorbar
    9月8日作业
    Presto 中orderby 算子的实现过程
    Python的打包神器—Nuitka!
    进阶——旋转数组
    stu04-快速生成HTML5文档结构
  • 原文地址:https://blog.csdn.net/qq_16659821/article/details/133751401