class Sprite_Small1 < Sprite
attr_accessor :available
attr_accessor :vx #x 速度
attr_accessor :vy #y 速度
attr_accessor :ax #x 加速度
attr_accessor :ay #y 加速度
attr_accessor :vx0 #x 初速度
attr_accessor :vy0 #y 初速度
attr_accessor :an #角度
attr_accessor :an0 #初速度角度
attr_accessor :omiga #角速度
attr_accessor :aomiga #角速度加速度
attr_accessor :rr #向心运动半径
attr_accessor :lifespan # 存活时间
attr_accessor :lifetime # 已存活时间
#attr_accessor :event_list # change behaviors according to time
# [eventtime,new_vx,new_vy,new_ax,new_ay,sound_effect]
# e.g. eventlist.push([300,5,5,1,1,""])
attr_accessor :actor_or_enemy #敌我识别,0为我,1为敌
attr_accessor :row_flag #旋转标志
#--------------------------------------------------------------------------
# ● 初始化对像
# viewport : 显示端口
# character: 发射者
# angle : 弧度
#--------------------------------------------------------------------------
def initialize(viewport,character,angle)
super(viewport)
@character = character
if @character.is_a?(Game_Actor)
@actor_or_enemy = 0
else
@actor_or_enemy = 1
end
self.blend_type = 0
@chox = @character.screen_x+10
@choy = @character.screen_y-100
@x = @chox #发射点X
@y = @choy #发射点Y
#if @x <= 19 and @y <= 14
# @x = enemy.x * 32
# @y = enemy.y * 32
#end
@an = angle #角度
@an0 = angle #初速度角度
#p @an * 180 / Math::PI
@mathx = (Math.cos(@an))*18
@mathy = (Math.sin(@an))*18
reset
self.bitmap = RPG::Cache.picture("bullet/小玉-黄")
self.available = true
self.visible = true
#self.zoom_x = 0.5
#self.zoom_y = 0.5
update
end
#--------------------------------------------------------------------------
# ● 设置对像
#--------------------------------------------------------------------------
def reset
return if self.disposed?
self.ox = 8 #图片半径8
self.oy = 8
self.x = @x
self.y = @y
#@screen_x = @character.true_x#-100
#@screen_y = @character.true_y#-100
@vx0 = @mathx #初速x
@vy0 = @mathy #初速y
self.vx = @vx0 #速度x
self.vy = @vy0 #速度y
self.omiga = 0 #角速度
self.aomiga = 0 #角速度加速度
@an = self.get_angle #角度
self.rr = 130 #旋转半径
self.ax = 0 #@rv**2/rr*(Math.cos(@an))
self.ay = 0 #@rv**2/rr*(Math.sin(@an))
self.lifespan = 1024 #存活时间
self.lifetime = 0
#self.event_list = []
self.available = false
self.visible = false
#@x = self.get_screen_pos[0]
#@y = self.get_screen_pos[1]
end
def can_be_seen?(recal = true)
#self.x = recal ? get_screen_pos[0] : @screen_x
#self.y = recal ? get_screen_pos[1] : @screen_y
if self.x>-640 and self.x<$width+640 and self.y>-480 and self.y<$height+480
return true
else
return false
end
end
def get_angle #角度获取:以发射点为圆心,极坐标判定角度
sign = (self.x-@chox)>0 ? 0 : Math::PI
return Math.atan((self.y-@choy)/((self.x-@chox) == 0 ? 1 : (self.x-@chox)))+sign
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.visible = false
end
super
end
def move
return false if self.visible == false
########################
if self.available
if self.lifetime < self.lifespan
case self.lifetime
when 1..26 #减速运动,每t速度衰减1.13
if @vx0.abs > 0
if @vx.abs <= 1
@vx0 = 0
self.vx = 0
else
@vx0 /= 1.13
self.vx /= 1.13
end
end
if @vy0.abs > 0
if @vy.abs <= 1
@vy0 = 0
self.vy = 0
else
@vy0 /= 1.13
self.vy /= 1.13
end
end #速度为0时开始旋转
if @vx0 == 0 and @vy0 == 0 and @row_flag != true
self.x = @chox + @rr*Math.cos(@an0) #X定点为初方向对应的圆周
self.y = @choy + @rr*Math.sin(@an0) #Y定点为初方向对应的圆周
@row_flag = true
end
when 27 #旋转的角速度加速度为0.3
if @row_flag != true
self.x = @chox + @rr*Math.cos(@an0)
self.y = @choy + @rr*Math.sin(@an0)
@row_flag = true
end
self.aomiga = 0.3
when 28..37 #转动半径-1
@rr -= 1
when 38..48 #转动半径-3
@rr -= 3
when 49..50 #转动半径-2
@rr -= 2
when 51..60 #转动半径-1
@rr -= 1
when 70..79 #转动半径+1
@rr += 1
when 80..89 #转动半径+2
@rr += 2
when 90 #加速63t,角速度达到18.9
self.aomiga = -1+0.01*rand(100) #角速度代入随机负值
@randr = rand(11) #转动半径增加值代入随机值
when 91..102 #转动半径+4*0.1*随机值
@rr += 4 + 0.1*@randr
when 103..113 #转动半径+随机值
@rr += @randr
when 114 #关闭转动,将当前的速度变为X速度和Y速度,置一初速度VX0,
@row_flag = false #将四叶草甩出去
v = self.omiga*Math::PI/180*((self.y-@choy)*(self.y-@choy)+(self.x-@chox)*(self.x-@chox))**0.5
an = self.get_angle
self.vx = v*Math.cos(an)
self.vy = v*Math.sin(an)
@vx0 = self.vx
when 114..139 #减速运动,速度衰减1.11
if @vx0.abs > 1
@vx0 /= 1.11
self.vx /= 1.11
self.vy /= 1.11
if @vx0.abs <= 1
@vx0 = 0
self.vx = 0
self.vy = 0
end
end
when 140 #速度归零
self.vx = 0
self.vy = 0
when 240 #小玉代入随机加速度,匀加速离开场景
an = rand(360)*Math::PI/180
v = rand(5)
self.ax = (0.1+0.05*v)*Math.cos(an)
self.ay = (0.1+0.05*v)*Math.sin(an)
end
if @row_flag #转动模式,x和y直接由角速度和转动半径决定
@an = self.get_angle
@an += self.omiga*Math::PI/180
self.omiga += self.aomiga
self.x = @chox + @rr*Math.cos(@an)
self.y = @choy + @rr*Math.sin(@an)
else #加速模式,x和y由正常的加速减速运动
self.x += self.vx
self.y += self.vy
self.vx += self.ax
self.vy += self.ay
end
# if self.lifetime == 115
# @row_flag = false
# end
#for e in self.event_list
# if e[0] == self.lifetime
# self.vx = e[1] unless e[1].nil?
# self.vy = e[2] unless e[2].nil?
# self.ax = e[3] unless e[3].nil?
# self.ay = e[4] unless e[4].nil?
# Audio.thndj_se_play(e[5]) unless e[5].nil?
# break
# end
#end
if self.can_be_seen?(false)
self.visible = true unless self.visible
#self.set_screen_pos(false)
#angle = self.get_angle
#if self.angle != angle
# self.angle = angle
#end
else
self.visible = false if self.visible
#p "v4"
end
self.lifetime += 1
else
self.visible = false if self.visible
self.available = false if self.available
#p "v2"
end
# if self.can_be_seen?(false)
# super()
#end
else
if self.visible
#p "v1"
self.visible = false
# super()
end
end
##############################
#return false if @x > 640 or @y > 480 or @x < 0 or @y < 0
#@x = self.get_screen_pos[0]
#@y = self.get_screen_pos[1]
check
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
#p self.visible
return if self.visible == false
if move == false
return "delete"
end
end
def check
return unless $scene.is_a?(Scene_Battle)
dx = self.x#+self.bitmap.width*0.5*0.75
dy = self.y#+self.bitmap.height*0.5*0.75
ra = 64 #子弹判定半径7,判定点半径1,合计8
if self.actor_or_enemy == 1 #敌军
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
sprite = $scene.spriteset.actor_sprites[$game_party.actors.size-1-i]
tx = actor.screen_x-sprite.cw*0.05 #根据位图大小取判定点位置X
ty = actor.screen_y-sprite.ch*0.445 #根据位图大小取判定点位置Y
if (dx-tx)*(dx-tx) + (dy-ty)*(dy-ty) <= ra #圆函数判定
value = 1 + rand(5)
value /= 2 if actor.guarding?
actor.hp -= value
actor.damage["event"] = value
actor.damage_pop["event"] = true
actor.animation.push([807+rand(3),true]) #击中动画
$scene.status_window.refresh
self.visible = false
end
if $game_party.all_dead?
# 切换到游戏结束画面
$scene = Scene_Gameover.new
return
end
#p "v5"
end#for
else #我军弹幕
for i in 0...$game_troop.enemies.size
actor = $game_troop.enemies[i]
sprite = $scene.spriteset.enemy_sprites[$game_troop.enemies.size-1-i]
tx = actor.screen_x+sprite.cw*0.1 #根据位图大小取判定点位置X
ty = actor.screen_y-sprite.ch*0.445 #根据位图大小取判定点位置Y
if (dx-tx)*(dx-tx) + (dy-ty)*(dy-ty) <= ra #圆函数判定
value = 1 + rand(5)
value /= 2 if actor.guarding?
actor.hp -= value
actor.damage["event"] = value
actor.damage_pop["event"] = true
actor.animation.push([807+rand(3),true]) #击中动画
$scene.status_window.refresh
self.visible = false
end
end #for
end #if
end #def
end