Project1
标题:
以下代码能用其他内嵌表达式代替一部分吗?
[打印本页]
作者:
TheRebirth
时间:
2012-4-30 17:14
标题:
以下代码能用其他内嵌表达式代替一部分吗?
本帖最后由 iisnow 于 2012-4-30 18:21 编辑
"#{}"这个倒是知道,但我感觉似乎不能这样写: @player = TShoot_Player"#{$game_variables[5]}".new(228, 336) (目的是:比如五号变量值为2,则加载TShoot_Player2这个类)
我感觉写这个好麻烦啊...↓
#--------------------------------------------------------------------------
# ● 自機弾の追加処理
#--------------------------------------------------------------------------
def add_pbullet(x, y, angle, speed, index, type)
i = @bullet.index(nil)
i = @bullet.size if i == nil
@bullet[i] = TShoot_PBullet1.new(x, y, angle, speed, index, i) if type == 1
@bullet[i] = TShoot_PBullet2.new(x, y, angle, speed, index, i) if type == 2
@bullet[i] = TShoot_PBullet3.new(x, y, angle, speed, index, i) if type == 3
@bullet[i] = TShoot_PBullet4.new(x, y, angle, speed, index, i) if type == 4
@bullet[i] = TShoot_PBullet5.new(x, y, angle, speed, index, i) if type == 5
return i
end
#--------------------------------------------------------------------------
# ● 敵機弾の追加処理
#--------------------------------------------------------------------------
def add_ebullet(x, y, vx, vy, index, type)
i = @bullet.index(nil)
i = @bullet.size if i == nil
@bullet[i] = TShoot_EBullet1.new(x, y, vx, vy, index, i) if type == 1
@bullet[i] = TShoot_EBullet2.new(x, y, vx, vy, index, i) if type == 2
@bullet[i] = TShoot_EBullet3.new(x, y, vx, vy, index, i) if type == 3
@bullet[i] = TShoot_EBullet4.new(x, y, vx, vy, index, i) if type == 4
@bullet[i] = TShoot_EBullet5.new(x, y, vx, vy, index, i) if type == 5
@bullet[i] = TShoot_EBullet6.new(x, y, vx, vy, index, i) if type == 6
@bullet[i] = TShoot_EBullet7.new(x, y, vx, vy, index, i) if type == 7
@bullet[i] = TShoot_EBullet8.new(x, y, vx, vy, index, i) if type == 8
@bullet[i] = TShoot_EBullet9.new(x, y, vx, vy, index, i) if type == 9
@bullet[i] = TShoot_EBullet10.new(x, y, vx, vy, index, i) if type == 10
@bullet[i] = TShoot_EBullet11.new(x, y, vx, vy, index, i) if type == 11
@bullet[i] = TShoot_EBullet12.new(x, y, vx, vy, index, i) if type == 12
@bullet[i] = TShoot_EBullet13.new(x, y, vx, vy, index, i) if type == 13
@bullet[i] = TShoot_EBullet14.new(x, y, vx, vy, index, i) if type == 14
@bullet[i] = TShoot_EBullet15.new(x, y, vx, vy, index, i) if type == 15
@bullet[i] = TShoot_EBullet16.new(x, y, vx, vy, index, i) if type == 16
return i
end
#--------------------------------------------------------------------------
# ● アイテムの追加処理
#--------------------------------------------------------------------------
def add_item(x, y, vx, vy, type)
i = @item.index(nil)
i = @item.size if i == nil
@item[i] = TShoot_Item1.new(x, y, vx, vy, type) if type == 0
@item[i] = TShoot_Item2.new(x, y, vx, vy, type) if type == 1
@item[i] = TShoot_Item3.new(x, y, vx, vy, type) if type == 2
@item[i] = TShoot_Item4.new(x, y, vx, vy, type) if type == 3
@item[i] = TShoot_Item5.new(x, y, vx, vy, type) if type == 4
@item[i] = TShoot_Item6.new(x, y, vx, vy, type) if type == 5
@item[i] = TShoot_Item7.new(x, y, vx, vy, type) if type == 6
@item[i] = TShoot_Item8.new(x, y, vx, vy, type) if type == 7
@item[i] = TShoot_Item9.new(x, y, vx, vy, type) if type == 8
end
#--------------------------------------------------------------------------
# ● エフェクトの追加処理
#--------------------------------------------------------------------------
def add_effect(type, x, y, vx, vy)
i = @popup.index(nil)
i = @popup.size if i == nil
if type == 1
@popup[i] = TShoot_Effect1.new(x, y, vx, vy)
elsif type == 2
@popup[i] = TShoot_Effect2.new(x, y, vx, vy)
elsif type == 3
@popup[i] = TShoot_Effect3.new(x, y, vx, vy)
elsif type == 4
@popup[i] = TShoot_Effect4.new(x, y, vx, vy)
elsif type == 5
@popup[i] = TShoot_Effect5.new(x, y, vx, vy)
elsif type == 6
@popup[i] = TShoot_Effect6.new(x, y, vx, vy)
elsif type == 7
@popup[i] = TShoot_Effect7.new(x, y, vx, vy)
elsif type == 8
@popup[i] = TShoot_Effect8.new(x, y, vx, vy)
elsif type == 9
@popup[i] = TShoot_Effect9.new(x, y, vx, vy)
elsif type == 10
@popup[i] = TShoot_Effect10.new(x, y, vx, vy)
elsif type == 11
@popup[i] = TShoot_Effect11.new(x, y, vx, vy)
elsif type == 12
@popup[i] = TShoot_Effect12.new(x, y, vx, vy)
elsif type == 13
@popup[i] = TShoot_Effect13.new(x, y, vx, vy)
elsif type == 14
@popup[i] = TShoot_Effect14.new(x, y, vx, vy)
elsif type == 15
@popup[i] = TShoot_Effect15.new(x, y, vx, vy)
end
end
复制代码
字会挂掉么...一开始我没看见字...
dsu_plus_rewardpost_czw
作者:
iisnow
时间:
2012-4-30 18:27
请使用eval:
比如你中间那么一段其实就是:
eval("@bullet[i] = TShoot_EBullet#{type}.new(x, y, vx, vy, index, i)")
作者:
end55rpg
时间:
2012-4-30 18:34
楼上正解
要么用eval要么哈西数组
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1