赞 | 97 |
VIP | 149 |
好人卡 | 1 |
积分 | 18 |
经验 | 73418 |
最后登录 | 2022-10-19 |
在线时间 | 2524 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1759
- 在线时间
- 2524 小时
- 注册时间
- 2010-10-12
- 帖子
- 1454
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
#============================================================================== # ■ EFS_Arrow #------------------------------------------------------------------------------ # 定义弓箭失的类 #============================================================================== =begin * 8 * * * * * 4 *#* 6 * * * * * 2 * =end class EFS_Arrow < Sprite attr_accessor:hit #-------------------------------------------------------------------------- # ● 初始化数据 #-------------------------------------------------------------------------- def initialize(viewport) super(viewport) @hit = false @direction = 2 @wait_count = 0 @angle = 0 @velocity = 15 @hight = 50 @flat_flying = false end #-------------------------------------------------------------------------- # ● 发射箭失 #-------------------------------------------------------------------------- def display(event,target_event,name,d_name) #赋值 @final_x = target_event.x*32- 34 @final_y = target_event.y*32- 68 @event=event @target_e = target_event @d_name = d_name @direction = event.direction return if self.bitmap!=nil #创建新的位图 self.bitmap=RPG::Cache.character(name,0) #设置角度 case @direction when 2 base_angle = 180 when 4 base_angle = 90 when 6 base_angle = 270 when 8 base_angle = 0 end #起始位置 self.ox = self.bitmap.width / 2 self.oy = self.bitmap.height / 2 self.x = event.screen_x self.y = event.screen_y-32 self.z = 11 x1=self.x y1=self.y #目标坐标 x3=target_event.screen_x y3=target_event.screen_y-32 #调整 adjust_with_distance #最高点 x2=(x1+x3)/2 y2=(y1+y3)/2-@hight case @direction #################################### when 2 #↓ x2 = self.x y2 = self.y y1= y3 if event.x<target_event.x x1= x3-2*(x2-x3).abs elsif event.x>target_event.x x1= x3+2*(x2-x3).abs else #待修改 shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y) return end return if @flat_flying #计算abc值 @a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3) @x = x2 #速度、Δ角度计算 v = @velocity @angle = Math.atan2(y2,x2)*180/Math::PI @angle_max = -@angle t = (x3-x1)/v @delta_angle = @angle/t if event.x<target_event.x self.angle = base_angle+@angle elsif event.x>target_event.x self.angle = base_angle-@angle else #待修改 shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y) return end #目标点备份 @to_x=x3 @to_y=y3 #################################### when 4 #← #计算abc值 @a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3) @x = x1 #速度、Δ角度计算 v = @velocity @angle = Math.atan2(y2,x2)*180/Math::PI @angle_max = -@angle t = (x3-x1)/v @delta_angle = 2*@angle/t self.angle = base_angle-@angle #目标点备份 @to_x=x3 @to_y=y3 #################################### when 6 #→ #计算abc值 @a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3) @x = x1 #速度、Δ角度计算 v = @velocity @angle = Math.atan2(y2,x2)*180/Math::PI @angle_max = -@angle t = (x3-x1)/v @delta_angle = 2*@angle/t self.angle = base_angle+@angle #目标点备份 @to_x=x3 @to_y=y3 #################################### when 8 #↑ x1=self.x y1=self.y x2 = target_event.screen_x y2 = target_event.screen_y-32 y3 = y1 if event.x<target_event.x x3= x3+2*(x2-x1).abs elsif event.x>target_event.x x3= x3-2*(x2-x1).abs else #待修改 shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y) end return if @flat_flying #计算abc值 @a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3) @x = x1 #速度、Δ角度计算 v = @velocity @angle = Math.atan2(y1,x1)*180/Math::PI @angle_max = -@angle t = (x3-x1)/v @delta_angle = @angle/t if event.x<target_event.x self.angle = base_angle-@angle elsif event.x>target_event.x self.angle = base_angle+@angle else #待修改 shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y) return end #目标点备份 @to_x=x2 @to_y=y2 end #################################### end def shoot_flat(x1,x3,y1,y3) case @direction when 2 self.angle = 180 when 4 self.angle = 90 when 6 self.angle = 270 when 8 self.angle = 0 end #目标点备份 @to_x=x3 @to_y=y3 @x = x1 @y = y1 @flat_flying = true return end def test loop do update Graphics.update break if droped? end end #-------------------------------------------------------------------------- # ● 根据距离自动调整速度、高度 #-------------------------------------------------------------------------- def adjust_with_distance d = ((@event.x - @target_e.x).abs + (@event.y - @target_e.y).abs).round @height = d*32/1.5 @velocity = d*1.5 end #-------------------------------------------------------------------------- # ● 刷新画面 #-------------------------------------------------------------------------- def update super if arrived? and not droped? drop else if droped? self.ox = $game_map.display_x / 4 self.oy = $game_map.display_y / 4 self.x = @final_x self.y = @final_y remove else self.x=@x if @flat_flying self.y = @y else self.y = HzhjMath.parabola_y(@x,@a,@b,@c) self.angle -= @delta_angle end case @direction when 2 if @flat_flying @y += @velocity else @x = @event.x < @target_e.x ? @x+@velocity/2 : @x-@velocity/2 end when 4 @x-=@velocity when 6 @x+=@velocity when 8 if @flat_flying @y -= @velocity else @x = @event.x < @target_e.x ? @x+@velocity/2 : @x-@velocity/2 end end end end end #-------------------------------------------------------------------------- # ● 到达目的地没 #-------------------------------------------------------------------------- def arrived? case @direction when 2 return self.y>=@to_y when 4 return self.x<=@to_x when 6 return self.x>=@to_x when 8 return self.y<=@to_y end end #-------------------------------------------------------------------------- # ● 落地 #-------------------------------------------------------------------------- def drop self.angle = 0 self.bitmap = RPG::Cache.character(@d_name,0) self.src_rect.set(rand(4)*100,(@direction/2-1)*100,100,100) self.x =@target_e.x*32 - 34 self.y =@target_e.y*32 - 68 self.ox = $game_map.display_x / 4 self.oy = $game_map.display_y / 4 self.z = 11 @wait_count = 450 end #-------------------------------------------------------------------------- # ● 落地? #-------------------------------------------------------------------------- def droped? return self.bitmap == RPG::Cache.character(@d_name,0) end #-------------------------------------------------------------------------- # ● 消失 #-------------------------------------------------------------------------- def remove if @wait_count == 0 self.bitmap = nil else @wait_count -= 1 end end def delete self.bitmap = nil end end
#==============================================================================
# ■ EFS_Arrow
#------------------------------------------------------------------------------
# 定义弓箭失的类
#==============================================================================
=begin
* 8 *
* *
* *
4 *#* 6
* *
* *
* 2 *
=end
class EFS_Arrow < Sprite
attr_accessor:hit
#--------------------------------------------------------------------------
# ● 初始化数据
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@hit = false
@direction = 2
@wait_count = 0
@angle = 0
@velocity = 15
@hight = 50
@flat_flying = false
end
#--------------------------------------------------------------------------
# ● 发射箭失
#--------------------------------------------------------------------------
def display(event,target_event,name,d_name)
#赋值
@final_x = target_event.x*32- 34
@final_y = target_event.y*32- 68
@event=event
@target_e = target_event
@d_name = d_name
@direction = event.direction
return if self.bitmap!=nil
#创建新的位图
self.bitmap=RPG::Cache.character(name,0)
#设置角度
case @direction
when 2
base_angle = 180
when 4
base_angle = 90
when 6
base_angle = 270
when 8
base_angle = 0
end
#起始位置
self.ox = self.bitmap.width / 2
self.oy = self.bitmap.height / 2
self.x = event.screen_x
self.y = event.screen_y-32
self.z = 11
x1=self.x
y1=self.y
#目标坐标
x3=target_event.screen_x
y3=target_event.screen_y-32
#调整
adjust_with_distance
#最高点
x2=(x1+x3)/2
y2=(y1+y3)/2-@hight
case @direction
####################################
when 2 #↓
x2 = self.x
y2 = self.y
y1= y3
if event.x<target_event.x
x1= x3-2*(x2-x3).abs
elsif event.x>target_event.x
x1= x3+2*(x2-x3).abs
else
#待修改
shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y)
return
end
return if @flat_flying
#计算abc值
@a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3)
@x = x2
#速度、Δ角度计算
v = @velocity
@angle = Math.atan2(y2,x2)*180/Math::PI
@angle_max = -@angle
t = (x3-x1)/v
@delta_angle = @angle/t
if event.x<target_event.x
self.angle = base_angle+@angle
elsif event.x>target_event.x
self.angle = base_angle-@angle
else
#待修改
shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y)
return
end
#目标点备份
@to_x=x3
@to_y=y3
####################################
when 4 #←
#计算abc值
@a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3)
@x = x1
#速度、Δ角度计算
v = @velocity
@angle = Math.atan2(y2,x2)*180/Math::PI
@angle_max = -@angle
t = (x3-x1)/v
@delta_angle = 2*@angle/t
self.angle = base_angle-@angle
#目标点备份
@to_x=x3
@to_y=y3
####################################
when 6 #→
#计算abc值
@a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3)
@x = x1
#速度、Δ角度计算
v = @velocity
@angle = Math.atan2(y2,x2)*180/Math::PI
@angle_max = -@angle
t = (x3-x1)/v
@delta_angle = 2*@angle/t
self.angle = base_angle+@angle
#目标点备份
@to_x=x3
@to_y=y3
####################################
when 8 #↑
x1=self.x
y1=self.y
x2 = target_event.screen_x
y2 = target_event.screen_y-32
y3 = y1
if event.x<target_event.x
x3= x3+2*(x2-x1).abs
elsif event.x>target_event.x
x3= x3-2*(x2-x1).abs
else
#待修改
shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y)
end
return if @flat_flying
#计算abc值
@a,@b,@c = HzhjMath.parabola(x1, y1, x2, y2, x3, y3)
@x = x1
#速度、Δ角度计算
v = @velocity
@angle = Math.atan2(y1,x1)*180/Math::PI
@angle_max = -@angle
t = (x3-x1)/v
@delta_angle = @angle/t
if event.x<target_event.x
self.angle = base_angle-@angle
elsif event.x>target_event.x
self.angle = base_angle+@angle
else
#待修改
shoot_flat(event.screen_x,target_event.screen_x,event.screen_y,target_event.screen_y)
return
end
#目标点备份
@to_x=x2
@to_y=y2
end
####################################
end
def shoot_flat(x1,x3,y1,y3)
case @direction
when 2
self.angle = 180
when 4
self.angle = 90
when 6
self.angle = 270
when 8
self.angle = 0
end
#目标点备份
@to_x=x3
@to_y=y3
@x = x1
@y = y1
@flat_flying = true
return
end
def test
loop do
update
Graphics.update
break if droped?
end
end
#--------------------------------------------------------------------------
# ● 根据距离自动调整速度、高度
#--------------------------------------------------------------------------
def adjust_with_distance
d = ((@event.x - @target_e.x).abs + (@event.y - @target_e.y).abs).round
@height = d*32/1.5
@velocity = d*1.5
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
if arrived? and not droped?
drop
else
if droped?
self.ox = $game_map.display_x / 4
self.oy = $game_map.display_y / 4
self.x = @final_x
self.y = @final_y
remove
else
self.x=@x
if @flat_flying
self.y = @y
else
self.y = HzhjMath.parabola_y(@x,@a,@b,@c)
self.angle -= @delta_angle
end
case @direction
when 2
if @flat_flying
@y += @velocity
else
@x = @event.x < @target_e.x ? @x+@velocity/2 : @x-@velocity/2
end
when 4
@x-=@velocity
when 6
@x+=@velocity
when 8
if @flat_flying
@y -= @velocity
else
@x = @event.x < @target_e.x ? @x+@velocity/2 : @x-@velocity/2
end
end
end
end
end
#--------------------------------------------------------------------------
# ● 到达目的地没
#--------------------------------------------------------------------------
def arrived?
case @direction
when 2
return self.y>=@to_y
when 4
return self.x<=@to_x
when 6
return self.x>=@to_x
when 8
return self.y<=@to_y
end
end
#--------------------------------------------------------------------------
# ● 落地
#--------------------------------------------------------------------------
def drop
self.angle = 0
self.bitmap = RPG::Cache.character(@d_name,0)
self.src_rect.set(rand(4)*100,(@direction/2-1)*100,100,100)
self.x =@target_e.x*32 - 34
self.y =@target_e.y*32 - 68
self.ox = $game_map.display_x / 4
self.oy = $game_map.display_y / 4
self.z = 11
@wait_count = 450
end
#--------------------------------------------------------------------------
# ● 落地?
#--------------------------------------------------------------------------
def droped?
return self.bitmap == RPG::Cache.character(@d_name,0)
end
#--------------------------------------------------------------------------
# ● 消失
#--------------------------------------------------------------------------
def remove
if @wait_count == 0
self.bitmap = nil
else
@wait_count -= 1
end
end
def delete
self.bitmap = nil
end
end
鄙人瞎j8乱写的一个从地图上某事件能发射一只抛物线移动的弓箭到目标事件的一个测试的玩意儿。。
于是问题来了, 游戏中,如果人物移动,画面跟着移动的话,弹道就偏了。
我不能使用
self.ox = $game_map.display_x / 4
self.oy = $game_map.display_y / 4
这种方法,因为我要把弓箭给旋转一定角度
所以问题来了=A=
这个应该怎么解决
|
|