具体地说 也就是
调用 move_up 方法 -> 改变了@y 值 ->
update中 判断到了 @y*128 和 @real_y 坐标不一致 ->
开始更新@real_y坐标 直到一致 -> @real_y坐标变化中 -> screen_y 也跟着变化->
结果人物动了起来
具体实现方法 希望大家去按顺序看
move_up
update_move
screen_x,screen_y
Sprite_Character类的 update 方法
就可以明白怎么回事了
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
if SmInput.trigger?(SmInput::S) and not jumping?
case @direction
when 2
jump(0, 1)
when 4
jump(-1, 0)
when 6
jump(1, 0)
when 8
jump(0, -1)
end
end
if SmInput.trigger?(SmInput::A) and not jumping? and !@effect and !moving?
case @direction
when 2
@animation_id = 102
when 4
@animation_id = 103
when 6
@animation_id = 104
when 8
@animation_id = 105
end
end
#--------------------------------------------------------------------------
# ● 检测player周围是否存在事件(返回id)
#--------------------------------------------------------------------------
def check_player_around(dir)
id = 0
@events.each do |key,value|
case dir
when 2
if (value.x == $game_player.x and value.y == $game_player.y+1)
id = key
break
end
when 4
if (value.x == $game_player.x-1 and value.y == $game_player.y)
id = key
break
end
when 6
if (value.x == $game_player.x+1 and value.y == $game_player.y)
id = key
break
end
when 8
if (value.x == $game_player.x+1 and value.y == $game_player.y-1)
id = key
break
end
end
end
return id
end
if @_animation != nil and (Graphics.frame_count % 2 == 0)
@_animation_duration -= 1
if [102,103,104,105].include? @_animation.id
if @_animation_duration == 5
id = $game_map.check_player_round($game_player.direction)
if id != 0
$game_map.events[id].animation_id = 4
end
end
end
update_animation
end
if SmInput.repeat?(SmInput::D) > 0
@power += 1
@loop_animation_id = 92
@looping_ani = true
else
if @power >= 30
fire(@direction)
end
@power = 0
@looping_ani = false
end
@character.effect = self.effect?
# 循环动画
if @character.loop_animation_id != 0
loop_animation($data_animations[@character.loop_animation_id])
@character.loop_animation_id = 0
end
if @_loop_animation != nil and @character.looping_ani == false
stop_loop_animation
end
def stop_loop_animation
loop_animation(nil)
end
class Game_Character
attr_accessor :effect
attr_accessor :loop_animation_id
attr_accessor :looping_ani
attr_accessor :move_speed
attr_accessor :through
alias :ori_initialize :initialize
def initialize
ori_initialize
@effect = false
@loop_animation_id = 0
@looping_ani = false
end
end
def fire(d)
# 根据player方位来建立名为[火]的事件 然后顺着player方向移动
# 移动次数根据离map边缘坐标决定
name = "fire"
case d
when 2
id = $game_map.add_event(@x,@y,"火",name)
($game_map.height-@y).times{$game_map.events[id].move_down}
when 4
id = $game_map.add_event(@x,@y,"火",name)
@x.times{$game_map.events[id].move_left}
when 6
id = $game_map.add_event(@x,@y,"火",name)
($game_map.width-@x).times{$game_map.events[id].move_right}
when 8
id = $game_map.add_event(@x,@y,"火",name)
@y.times{$game_map.events[id].move_up}
end
end
#--------------------------------------------------------------------------
# ● update 别名
#--------------------------------------------------------------------------
alias :ori_update :update
def update
ori_update
# 检测地图上是否存在名为[火]的事件
if (id=check_event_name("火")) != 0
# 获取 [火] 的real_x和real_y
real_x,real_y = @events[id].real_x,@events[id].real_y
# 检测地图上是否有事件被[火]碰撞(击中),返回事件id
target_id = check_event_id(real_x,real_y)
# 击中的情况下
if target_id != 0
# 事件上播放挨打动画
show_event_ani(target_id,4)
# 删除[火]的事件
delete_event(id)
return
end
# 碰到边界消失
case @events[id].direction
when 4
if @events[id].real_x == 0
delete_event(id)
end
when 6
if @events[id].real_x >= $game_map.width*128-128
delete_event(id)
end
when 8
if @events[id].real_y == 0
delete_event(id)
end
when 2
if @events[id].real_y >= $game_map.height*128-128
delete_event(id)
end
end
end
end
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |