<RGSS>
class Stg_enemy < Sprite #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :dx #横方向の当たり判定 attr_reader :dy #縦方向の当たり判定 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(x,y,type) super() @type = type self.bitmap = RPG::Cache.picture("enemy"+"#{@type}") self.ox = self.bitmap.width / 2 self.oy = self.bitmap.height / 2 self.x = x self.y = y @dx = 50 @dy = 50 case @type when 1 @spx = 0 @spy = 2 when 2 @spx = 0 @spy = 4 when 3 @spx = -1 @spy = 1 end @count = 0 #生存時間 end #-------------------------------------------------------------------------- # ● 敵キャラの移動処理 #-------------------------------------------------------------------------- def move move_select() self.x += @spx self.y += @spy #画面外に出たら消滅 if screenout? self.dispose return true end return false end #-------------------------------------------------------------------------- # ● 敵キャラの種類別移動 #-------------------------------------------------------------------------- def move_select @count += 1 case @type when 2 #途中で引き返す @spy = -4 if @count == 65 when 3 #ジグザグ移動 @spx *= -1 if @count % 120 == 0 end end #-------------------------------------------------------------------------- # ● 画面外判定 #-------------------------------------------------------------------------- def screenout? return true if self.x > 640 + self.bitmap.width / 2 return true if self.x < 0 - self.bitmap.width / 2 return true if self.y > 480 + self.bitmap.height / 2 return true if self.y < 0 - self.bitmap.height / 2 return false end #-------------------------------------------------------------------------- # ● 攻撃判定 ■更新■ #-------------------------------------------------------------------------- def attack case @type when 1 #20フレームに一回弾を発射 if @count % 20 == 0 return 1 end when 2 #10フレームに一回弾を発射 if @count % 10 == 0 return 2 end when 3 #30フレームに一回弾を発射 if @count % 30 == 0 return 3 end end return 0 end end
<RGSS2>