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, 1, 0);
20 } else if (Key.isDown(Key.LEFT)) {
21 keyPressed=_root.moveChar(ob, -1, 0);
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, 0, 1);
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 }
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, 1, 0);
20 } else if (Key.isDown(Key.LEFT)) {
21 keyPressed=_root.moveChar(ob, -1, 0);
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, 0, 1);
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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述