<RGSS>
class Stg_bullet < Sprite #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :dx #横方向の当たり判定 attr_reader :dy #縦方向の当たり判定 #-------------------------------------------------------------------------- # ● オブジェクト初期化 ■更新■ #-------------------------------------------------------------------------- #@typeにより、弾の種類を分岐している。target_x,y(自機の位置) rad ラジアン def initialize(x, y, type = 0, target_x = 0 , target_y = 0, rad = 0, rot = 0) super() @type = type case @type when 0 #自機が撃つ弾 self.bitmap = RPG::Cache.picture("bullet") @dx = 2 @dy = 2 @spx = 0 @spy = -16 when 1 #敵が撃つ弾 self.bitmap = RPG::Cache.picture("e_bullet") @dx = 8 @dy = 8 @spx = 0 @spy = 8 when 2 #敵が撃つ弾、自機狙い弾 self.bitmap = RPG::Cache.picture("e_bullet") @dx = 8 @dy = 8 @spx = 6 @spy = 6 #おそらく速度設定 @spx = @spx*(target_x-x) / Math.sqrt((target_x-x)**2+(target_y-y)**2) @spy = @spy*(target_y-y) / Math.sqrt((target_x-x)**2+(target_y-y)**2) when 3 #敵が撃つ弾、Nウェイ弾 self.bitmap = RPG::Cache.picture("e_bullet") @dx = 8 @dy = 8 @spx = 6 @spy = 6 @spx = @spx*(target_x-x) / Math.sqrt((target_x-x)**2+(target_y-y)**2) @spy = @spy*(target_y-y) / Math.sqrt((target_x-x)**2+(target_y-y)**2) @spx = @spx * Math.cos(rad) - @spy * Math.sin(rad) @spy = @spx * Math.sin(rad) + @spy * Math.cos(rad) when 4 #敵が撃つ弾・回転弾 self.bitmap = RPG::Cache.picture("e_bullet") @dx = 8 @dy = 8 @spx = 6 @spy = 6 @spx = @spx * Math.cos(rot * Math::PI / 180) @spy = @spy * Math.sin(rot * Math::PI / 180) end self.ox = self.bitmap.width / 2 self.oy = self.bitmap.height / 2 self.x = x self.y = y @fx = x #浮動少数を確保する為のx座標確保変数(xは弾のx座標) @fy = y #浮動少数を確保する為のy座標確保変数(yは弾のy座標) end #-------------------------------------------------------------------------- # ● 弾の移動処理 #-------------------------------------------------------------------------- def move #浮動少数座標に移動量を加算 @fx += @spx @fy += @spy #浮動少数座標を座標に代入(座標には整数値が入る) self.x = @fx self.y = @fy #画面外に出たら消滅 if screenout?#30行目にて定義 self.dispose return true end return false 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 end
<RGSS2>