zoukankan      html  css  js  c++  java
  • 分析3个函数

     1 //////////////////////////////////////////////////////////////
     2 //  移动响应,返回布尔值
     3 //  通过检测,可控制影片剪辑的播放 ——
     4 //  —知识点:函数的设计
     5 //////////////////////////////////////////////////////////////
     6 
     7 function moveChar(ob, dirx, diry) {
     8     ob.x += dirx*ob.speed;
     9     ob.y += diry*ob.speed;
    10     ob.clip.gotoAndStop(dirx+diry*2+3);
    11     ob.clip._x = ob.x;
    12     ob.clip._y = ob.y;
    13     return (true);
    14 }
    15 function detectKeys() {
    16     var ob = _root.char;
    17     var keyPressed = false;
    18     if (Key.isDown(Key.RIGHT)) {
    19         keyPressed=_root.moveChar(ob, 10);
    20     } else if (Key.isDown(Key.LEFT)) {
    21         keyPressed=_root.moveChar(ob, -10);
    22     } else if (Key.isDown(Key.UP)) {
    23         keyPressed=_root.moveChar(ob, 0-1);
    24     } else if (Key.isDown(Key.DOWN)) {
    25         keyPressed=_root.moveChar(ob, 01);
    26     }
    27     if (!keyPressed) {
    28         ob.clip.char.gotoAndStop(1);
    29     } else {
    30         ob.clip.char.play();
    31     }
    32 }
    33 
    34 //////////////////////////////////////////////////////////////
    35 //  运动物体在数组地图中的周围情况监测
    36 //////////////////////////////////////////////////////////////
    37 
    38 function getMyCorners (x, y, ob) {
    39     ob.downY = Math.floor((y+ob.height-1)/game.tileH);
    40     ob.upY = Math.floor((y-ob.height)/game.tileH);
    41     ob.leftX = Math.floor((x-ob.width)/game.tileW);
    42     ob.rightX = Math.floor((x+ob.width-1)/game.tileW);
    43     //检测他们是否是障碍物
    44     ob.upleft = game["t_"+ob.upY+"_"+ob.leftX].walkable;
    45     ob.downleft = game["t_"+ob.downY+"_"+ob.leftX].walkable;
    46     ob.upright = game["t_"+ob.upY+"_"+ob.rightX].walkable;
    47     ob.downright = game["t_"+ob.downY+"_"+ob.rightX].walkable;
    48 }
    49 
    50 //////////////////////////////////////////////////////////////
    51 //  物体开始运动,首先判断周围情况
    52 //////////////////////////////////////////////////////////////
    53 
    54 function moveChar(ob, dirx, diry) {
    55     getMyCorners (ob.x, ob.y+ob.speed*diry, ob);
    56     if (diry == -1) {
    57         if (ob.upleft and ob.upright) {
    58             ob.y += ob.speed*diry;
    59         } else {
    60             ob.y = ob.ytile*game.tileH+ob.height;
    61         }
    62     }
    63     if (diry == 1) {
    64         if (ob.downleft and ob.downright) {
    65             ob.y += ob.speed*diry;
    66         } else {
    67             ob.y = (ob.ytile+1)*game.tileH-ob.height;
    68         }
    69     }
    70     getMyCorners (ob.x+ob.speed*dirx, ob.y, ob);
    71     if (dirx == -1) {
    72         if (ob.downleft and ob.upleft) {
    73             ob.x += ob.speed*dirx;
    74         } else {
    75             ob.x = ob.xtile*game.tileW+ob.width;
    76         }
    77     }
    78     if (dirx == 1) {
    79         if (ob.upright and ob.downright) {
    80             ob.x += ob.speed*dirx;
    81         } else {
    82             ob.x = (ob.xtile+1)*game.tileW-ob.width;
    83         }
    84     }
    85     ob.clip._x = ob.x;
    86     ob.clip._y = ob.y;
    87     ob.clip.gotoAndStop(dirx+diry*2+3);
    88     ob.xtile = Math.floor(ob.clip._x/game.tileW);
    89     ob.ytile = Math.floor(ob.clip._y/game.tileH);
    90     //---------下面两行由qhwa添加--------
    91     ob.height = ob.clip._height/2;
    92     ob.width = ob.clip._width/2;
    93     //---------------------------------
    94     return (true);
    95 }
  • 相关阅读:
    图书馆业务制图
    单元测试(输入一个数组和它的大小,输出这个数组中最大子数组的和)
    build to win读后感
    小学四则运算
    微信公众平台具体方案和人员分工
    问卷调查结果剖析
    题目确定与需求分析
    课程介绍与团队简介
    网站LOGO以及网页样式
    C Sharp进行网站信息抽取与小型内部搜索引擎的讲解
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/1606257.html
Copyright © 2011-2022 走看看