设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1764|回复: 3
打印 上一主题 下一主题

[已经解决] 角色改为占4格后的碰撞设置

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
89 小时
注册时间
2009-3-7
帖子
144
跳转到指定楼层
1
发表于 2012-1-18 15:56:03 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 猫猫鱼 于 2012-1-18 18:25 编辑

这是坦克所占的4格图
实际格子只占了这格,其他的3格都是虚的,因为游戏需要这么大的角色,所以就产生了这问题,怎么把角色所占的格数改为2X2,碰撞什么的都正确不会重叠?
也就是说角色所占的4格都不能穿到墙里。都变为实格。

Lv1.梦旅人

梦石
0
星屑
50
在线时间
380 小时
注册时间
2010-8-11
帖子
68
2
发表于 2012-1-18 18:54:41 | 只看该作者
game_character1里
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
改成
new_x = x + (d == 6 ? 2 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -2 : 0)

点评

这样的话即使是单格事件也会按照四格碰撞判断,应该加上一个属性判断是单格还是四格。  发表于 2012-1-18 19:11
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
89 小时
注册时间
2009-3-7
帖子
144
3
 楼主| 发表于 2012-1-18 19:08:51 | 只看该作者
这样子的话,只判断了走的那方向的格内有无墙,但是如果是往右走,而头上那格是墙的话,头就穿墙了。
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
380 小时
注册时间
2010-8-11
帖子
68
4
发表于 2012-1-19 13:24:11 | 只看该作者
  1.   def passable?(x, y, d)
  2.     # 求得新的坐标
  3.     new_x = x + (d == 6 ? 2 : d == 4 ? -1 : 0)
  4.     new_y = y + (d == 2 ? 1 : d == 8 ? -2 : 0)
  5.     # 坐标在地图以外的情况
  6.     unless $game_map.valid?(new_x, new_y)
  7.       # 不能通行
  8.       return false
  9.     end
  10.     # 穿透是 ON 的情况下
  11.     if @through
  12.       # 可以通行
  13.       return true
  14.     end
  15.     # 移动者的元件无法来到指定方向的情况下
  16.     unless $game_map.passable?(x, y, d, self)
  17.       # 通行不可
  18.       return false
  19.     end
  20.     # 从指定方向不能进入到移动处的元件的情况下
  21.     if d == 2 or d == 8
  22.       unless $game_map.passable?(new_x, new_y, 10 - d) and $game_map.passable?(new_x + 1, new_y, 10 - d)
  23.        return false
  24.       end
  25.     elsif d ==4 or d == 6
  26.       unless $game_map.passable?(new_x, new_y, 10 - d) and $game_map.passable?(new_x , new_y - 1, 10 - d)
  27.        return false
  28.       end
  29.     end
  30.     # 循环全部事件
  31.    
  32.     for event in $game_map.events.values
  33.       # 事件坐标于移动目标坐标一致的情况下
  34.       if (d == 2 or d == 8)and(event.x == new_x or event.x + 1 == new_x or event.x == new_x + 1) and (event.y == new_y or event.y - 1 == new_y ) or ((d == 4 or d == 6)and(event.x == new_x or event.x + 1 == new_x ) and (event.y == new_y or event.y - 1 == new_y or event.y == new_y - 1))
  35.             # 穿透为 ON
  36.         unless event.through
  37.           # 自己就是事件的情况下
  38.           if self != $game_player
  39.             # 不能通行
  40.             return false
  41.           end
  42.           # 自己是主角、对方的图形是角色的情况下
  43.           if event.character_name != ""
  44.             # 不能通行
  45.             return false
  46.           end
  47.         end
  48.       end
  49.     end
  50.     # 主角的坐标与移动目标坐标一致的情况下
  51.     if (d == 2 or d == 8)and($game_player.x == new_x or $game_player.x + 1 == new_x or $game_player.x == new_x + 1) and ($game_player.y == new_y or $game_player.y - 1 == new_y ) or ((d == 4 or d == 6)and($game_player.x == new_x or $game_player.x + 1 == new_x ) and ($game_player.y == new_y or $game_player.y - 1 == new_y or $game_player.y == new_y - 1))
  52.      # 穿透为 ON
  53.       unless $game_player.through
  54.         # 自己的图形是角色的情况下
  55.         if @character_name != ""
  56.           # 不能通行
  57.           return false
  58.         end
  59.       end
  60.     end
  61.     # 可以通行
  62.     return true
  63.   end
复制代码
替换相同部分就可以

点评

怎么感谢你呢  发表于 2012-1-19 13:37
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-1 22:34

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表