一辆简单战车的SPRING脚本

下面是SPRING的新手用MOD样板的一辆4轮战车的脚本,可以说SPRING将脚本进一步简化了,更加容易理解,即使不会编程的人也能很容易的利用这些例子修改。红色是解析

–Define the wheel pieces 定义轮子
local wheel1 = piece “wheel1” 模型中的"wheel1"是第一个轮子
local wheel2 = piece “wheel2” 轮子2
local wheel3 = piece “wheel3” 轮子3
local wheel4 = piece “wheel4” 轮子4
local wheel_speed = math.rad(180) 战车移动时轮子的转动速度是180
–Define the pieces of the weapon 定义武器
local turret = piece “turret” 模型中的"turret"是这辆战车的炮台
local barrel = piece “barrel” 模型中的"barrel" 是这辆战车的炮管
local flare = piece “flare” 模型中的 “flare” 是这辆战车的炮管口开炮时显示的火光
–define other pieces 定义其它
local body = piece “body” 模型中的“body”是这辆坦克的车身。

function script.Create() 出生状态定义,例如机器人从坐着的姿态站起来,或者闪一下光,这里没有内容,战车出生时将没有特殊效果。这个倒是无关重要了。

end 结束

----driving animation 开车时的动作
http://answers.springlobby.info/ … els-on-moving-units 不熟悉这些的可以到这个网址查,作者在脚本里留的
function script.StartMoving() 调用功能开始移动
– Spring.Echo (“starting to move!”)
Spin(wheel1, x_axis, wheel_speed) 轮子1沿X轴以wheel_speed旋转
Spin(wheel2, x_axis, wheel_speed)
Spin(wheel3, x_axis, wheel_speed)
Spin(wheel4, x_axis, wheel_speed)
end 结束

function script.StopMoving() 调用功能停止移动
– Spring.Echo (“Stopped moving!”)
StopSpin (wheel1,x_axis) 停止轮子1的旋转
StopSpin (wheel2,x_axis)
StopSpin (wheel3,x_axis)
StopSpin (wheel4,x_axis)
end 结束

----aimining & fire weapon 武器开火的动作
function script.AimFromWeapon1() 调用功能武器1瞄准
return turret
end

function script.QueryWeapon1() 武器1的炮弹出射点
return flare
end

function script.AimWeapon1( heading, pitch ) 这个就是上面调用的功能武器1瞄准
–aiming animation: instantly turn the gun towards the enemy
Turn(turret, y_axis, heading) 炮台沿y轴的转动速度
Turn(barrel, x_axis, -pitch) 炮管沿X轴的转动速度
return true
end

function script.FireWeapon1() 功能武器1开火

end

—death animation 死亡动作
function script.Killed(recentDamage, maxHealth) 调用死亡功能,检查死亡时受到的伤害占生命值的百分比。根据这个受伤程度可以采取不同的死亡方式。
Explode (body, SFX.SHATTER) 使用SFX.SHATTER 特效炸散模型中的body这个部分。
end

实现的东西跟TA是一样的,移动时的轮子转动,瞄准时的炮台和炮管转动,死亡时根据伤害程度采取不同的死亡方式。
相对TA来说更为简洁。可以用记事本直接修改,无须进行编译,方便了好多。