Still haven't been able to get it to run. Missing functions...
EDIT: just had to stitch it all together. Here's the connected code for others as confused as me...
`RESERVATIONS
`OBJECTS
`1 = MechBase
`2 = MechTop
`3 = Weapon 1
`4 = Weapon 2
`100 .. 110 = Weapon Primitives
`111 = Bullet Primitive
`112 = Flare Primitive
`200-299 = Bullets
`300-399 = Flares
`SOUNDS
`1..3 = WEAPON1 SOUND
`4..6 = WEAPON2 SOUND
`7 = Mech Walk
`8 = Mech rotate
`100 = MINIGUN - SPIN
`101 = MINIGUN - SHOT1
`102 = MINIGUN - SHOT2
`103 = MINIGUN - WINDUP
`104 = MINIGUN - WINDDOWN
`105 = GENERIC - NO AMMO
`TYPES
type SystemType
timeStamp as double integer
ticksPerLoop as integer
mousemove_x as integer
turnSensitivity# as float
endtype
Type AnimType
startFrame as integer
endFrame as integer
endtype
type BulletType
damage# as float
speed# as float
life as integer
endtype
type FlareType
alpha# as float
alphadec# as float
endtype
type MinigunType
ammo as integer
windup as integer
refire as integer
firing as integer
endtype
type PlayerType
topAng# as float
anim as integer
NewAnim as integer
animFrame# as float
animSpeed# as float
animSmooth as integer
movespeed# as float
turnSpeed# as float
weapon1Type as integer
weapon2Type as integer
endtype
`CONSTANTS
#constant Const_CameraSmooth = 10
#constant Const_CameraSmoothRotate = 10
#constant Const_MinigunWindup = 70
#constant Const_MinigunRefire = 3
#constant Const_PlayerTurnSpeedMax = 2.2
#constant Const_PlayerSpeedMaxForwards = 0.06
#constant Const_PlayerSpeedMaxBackwards = -0.04
#constant Const_PlayerAccel = 0.003
#constant Const_PlayerDecel = 0.01
#constant Const_PlayerTurnAccel = 0.06
#constant Const_PlayerMaxTurnSpeed = 0.6
InitialiseSystem()
InitialiseWeapons()
LoadSounds()
SetupPlayer()
system.timeStamp = PERFTIMER()
global loops as double integer
global TimerA as double integer
loops = 0
TimerA = timer()
make object plain 500,30,30
xrotate object 500,270
load image "imagestarmac.bmp",1
texture object 500,1
scale object texture 500,4,4
position light 0,50,50,50
`color light 0,rgb(255,200,150)
set shadow shading on 1,-1,100,1
set shadow shading on 2,-1,100,1
set shadow shading on 3,-1,100,1
set shadow shading on 4,-1,100,1
do
inc loops,1
InputCapture()
ControlPlayer()
AnimatePlayer()
ProcessBullets()
ProcessFlares()
ProcessCamera()
ScreenUpdate()
loop
function InputCapture()
system.mousemove_x = mousemovex()
endfunction
function InitialiseSystem()
set display mode 1280,1024,32
autocam off
hide mouse
`position camera 0,15,-5
`point camera 0,0,0
xrotate camera 70
sync on
sync rate 0
global System as SystemType
System.turnSensitivity# = 4.0
startTime = PERFTIMER()
wait 3000
endTime = PERFTIMER()
system.ticksPerLoop = ((endTime-StartTime)/3000.0)*(1000.0/60.0)
endfunction
function ScreenUpdate()
do
newTime = PERFTIMER()
difference = newTime - System.timeStamp
if difference > system.ticksPerLoop
System.timeStamp = System.timeStamp + system.ticksPerLoop
exitfunction
else
text 1,1,str$(screen fps())
text 1,20,str$((loops*1000)/(timer()-TimerA))
sync
set object interpolation 1,0
endif
loop
endfunction
function Minigun_Add(position)
Minigun(position).ammo = 500
Minigun(position).windup = 0
Minigun(position).refire = 0
endfunction
function Minigun_Fire(weapon)
if Minigun(weapon).firing = 0 or minigun(weapon).firing = 3
Minigun(weapon).firing = 1
offset = int((Minigun(weapon).windup / (Const_MinigunWindup * 1.0)) * 100000)
PlayCloneSound((weapon-1)*3+1,103,100,0,0,1,offset)
endif
if Minigun(weapon).firing = 1
inc Minigun(weapon).windup,1
endif
if Minigun(weapon).windup = Const_Minigunwindup
Minigun(weapon).firing = 2
PlayCloneSound((weapon-1)*3+1,100,100,0,0,0,0)
if Minigun(weapon).refire = 0
Minigun(weapon).refire = Const_MinigunRefire
if Minigun(weapon).ammo > 0
PlayCloneSound((weapon-1)*3+2,101+rnd(1),95,500,0,1,0)
dec Minigun(weapon).ammo,1
gunobj = 2+weapon
CreateBullet(object position x(gunobj),object position z(gunobj),object angle y(gunobj),0.5,10,2,20,40)
CreateFlare(object position x(gunobj),object position z(gunobj),object angle y(gunobj),1,30,25)
else
PlayCloneSound((weapon-1)*3+2,105,90,400,0,1,0)
endif
else
dec Minigun(weapon).refire,1
endif
endif
obj = 2+Weapon
rotate limb obj,4,0,0,limb angle z(obj,4)+Minigun(weapon).windup/2.0
endfunction
function Minigun_Stop(weapon)
`Minigun
if Minigun(weapon).firing = 1 or Minigun(weapon).firing = 2
Minigun(weapon).firing = 3
offset = int(((Const_MinigunWindup-Minigun(weapon).windup) / (Const_MinigunWindup * 1.0)) * 100000)
PlayCloneSound((weapon-1)*3+1,104,100,0,0,1,offset)
endif
if Minigun(weapon).windup > 0
dec Minigun(weapon).windup,1
obj = 2+Weapon
rotate limb obj,4,0,0,limb angle z(obj,4)+Minigun(weapon).windup/2.0
else
Minigun(weapon).firing = 0
endif
endfunction
function InitialiseWeapons()
dim Minigun(2) as minigunType
load object "modelsminigun.x",100
for w = 100 to 100
set object texture w,1,0
exclude object on w
next w
dim Bullet(99) as BulletType
load object "modelsbullet.x",111
exclude object on 111
dim Flare(99) as FlareType
load object "modelsflare.x",112
exclude object on 112
endfunction
function LoadSounds()
load sound "soundsmechwalk.wav",7
load sound "soundsmechrotate.wav",8
load sound "soundsminigunspin.wav",100
load sound "soundsminigunfire1.wav",101
load sound "soundsminigunfire2.wav",102
load sound "soundsminigunspinup.wav",103
load sound "soundsminigunspindown.wav",104
load sound "soundsnoammo.wav",105
endfunction
function PlaySound(num,vol,random,pan,override)
if sound playing(num) = 0 or override = 1
set sound volume num,vol
set sound speed num,40000-random+rnd(random*2)
set sound pan num,pan
play sound num
endif
endfunction
function PlayCloneSound(num,clone,vol,random,pan,override,offset)
playit = 0
if sound exist(num) = 0
playit = 1
else
if sound playing(num) = 0 or override = 1
playit = 1
stop sound num
delete sound num
endif
endif
if playit = 1
clone sound num,clone
set sound volume num,vol
set sound speed num,40000-random+rnd(random*2)
set sound pan num,pan
play sound num,offset
endif
endfunction
function ProcessCamera()
x# = curvevalue(object position x(1)-5*sin(object angle y(2)),camera position x(),Const_CameraSmooth)
z# = curvevalue(object position z(1)-5*cos(object angle y(2)),camera position z(),Const_CameraSmooth)
position camera x#,20,z#
ang# = curveangle(object angle y(2),camera angle y(),Const_CameraSmoothRotate)
yrotate camera ang#
endfunction
function ControlPlayer()
`TURRET MOVEMENT
topTurn# = System.mousemove_x/System.turnSensitivity#
if topTurn# > Const_PlayerTurnSpeedMax
topTurn# = Const_PlayerTurnSpeedMax
else
if topTurn# < Const_PlayerTurnSpeedMax *-1
topTurn# = Const_PlayerTurnSpeedMax *-1
endif
endif
Player.topAng# = wrapvalue(Player.topAng#+topTurn#)
if abs(topTurn#) > 0
PlaySound(8,100,100,0,0)
endif
`Movement
if keystate(17) and Player.movespeed# >= 0
Player.movespeed# = Player.movespeed# + Const_PlayerAccel
if Player.movespeed# > Const_PlayerSpeedMaxForwards
Player.movespeed# = Const_PlayerSpeedMaxForwards
endif
else
if keystate(31) and Player.movespeed# <= 0
Player.movespeed# = Player.movespeed# - Const_PlayerAccel
if Player.movespeed# < Const_PlayerSpeedMaxBackwards
Player.movespeed# = Const_PlayerSpeedMaxBackwards
endif
else
if Player.movespeed# > Const_PlayerDecel
`Ensure step isn't half way through
if (object frame(1) > 5.5 and object frame(1) < 6) or (object frame(1) > 10.5 and object frame(1) < 11)
Player.movespeed# = Player.movespeed# - Const_PlayerDecel
endif
else
if Player.movespeed# < Const_PlayerDecel*-1
if (object frame(1) > 16.5 and object frame(1) < 17) or (object frame(1) > 21.5 and object frame(1) < 22)
Player.movespeed# = Player.movespeed# + Const_PlayerDecel
endif
else
Player.movespeed# = 0
endif
endif
endif
endif
if keystate(30)
Player.turnSpeed# = Player.turnSpeed# - Const_PlayerTurnAccel
if Player.turnSpeed# < Const_PlayerMaxTurnSpeed *-1
Player.turnSpeed# = Const_PlayerMaxTurnSpeed *-1
endif
else
if keystate(32)
Player.turnSpeed# = Player.turnSpeed# + Const_PlayerTurnAccel
if Player.turnSpeed# > Const_PlayerMaxTurnSpeed
Player.turnSpeed# = Const_PlayerMaxTurnSpeed
endif
else
if Player.turnSpeed# > Const_PlayerTurnAccel
Player.turnSpeed# = Player.turnSpeed# - Const_PlayerTurnAccel
else
if Player.turnSpeed# < Const_PlayerTurnAccel *-1
Player.turnSpeed# = Player.turnSpeed# + Const_PlayerTurnAccel
else
Player.turnSpeed# = 0
endif
endif
endif
endif
`WEAPONS
if mouseclick() && 1
FirePlayerWeapon(1)
else
StopPlayerWeapon(1)
endif
if mouseclick() && 2
FirePlayerWeapon(2)
else
StopPlayerWeapon(2)
endif
endfunction
function AnimatePlayer()
`Move player
if Player.movespeed# > 0
Player.NewAnim = 1
Player.animSpeed# = Player.movespeed#*1.5
else
if Player.movespeed# < 0
Player.NewAnim = 2
Player.animSpeed# = abs(Player.movespeed#*1.5)
else
if Player.turnSpeed# < 0
Player.NewAnim = 3
Player.animSpeed# = abs(Player.turnSpeed#)/8.0
else
if Player.turnSpeed# > 0
Player.NewAnim = 4
Player.animSpeed# = Player.turnSpeed#/8.0
else
Player.NewAnim = 0
endif
endif
endif
endif
if Player.NewAnim <> Player.Anim
`if Player.animSmooth = 0
set object interpolation 1,Player.animSmooth*10
set object frame 1,Player_Anims(Player.NewAnim).startFrame
`endif
inc Player.animSmooth,1
if Player.animSmooth = 10
Player.animSmooth = 0
Player.Anim = Player.NewAnim
endif
else
set object interpolation 1,100
set object frame 1,object frame(1)+Player.animSpeed#
if object frame(1) < Player_Anims(Player.anim).startFrame or object frame(1) > Player_Anims(Player.anim).endFrame
set object frame 1,Player_Anims(Player.anim).startFrame
endif
`SOUND
select Player.anim
case 1
`Forwards
if (object frame(1) => 4 and object frame(1) < 4 + Player.animSpeed#) or (object frame(1) => 9 and object frame(1) < 9 + Player.animSpeed#)
PlaySound(7,100,1000,0,1)
endif
endcase
case 2
`Backwards
if (object frame(1) => 14 and object frame(1) < 14 + Player.animSpeed#) or (object frame(1) => 19 and object frame(1) < 19 + Player.animSpeed#)
PlaySound(7,98,1000,0,1)
endif
endcase
case 3
`Turn left
if (object frame(1) => 25 and object frame(1) < 25 + Player.animSpeed#) or (object frame(1) => 27 and object frame(1) < 27 + Player.animSpeed#)
PlaySound(7,96,1000,0,1)
endif
endcase
case 4
`Turn right
if (object frame(1) => 30 and object frame(1) < 30 + Player.animSpeed#) or (object frame(1) => 32 and object frame(1) < 32 + Player.animSpeed#)
PlaySound(7,96,1000,0,1)
endif
endcase
endselect
endif
`Turn player
yrotate object 1,wrapvalue(object angle y(1)+Player.turnSpeed#)
move object 1,Player.movespeed#
position object 2,limb position x(1,3),limb position y(1,3),limb position z(1,3)
yrotate object 2,object angle y(1)+Player.topAng#
`Player weapons
if object exist(3)
position object 3,limb position x(2,3),limb position y(2,3),limb position z(2,3)
yrotate object 3,object angle y(1)+Player.topAng#
endif
if object exist(4)
position object 4,limb position x(2,4),limb position y(2,4),limb position z(2,4)
yrotate object 4,object angle y(1)+Player.topAng#
endif
endfunction
function SetupPlayer()
Dim Player_Anims(4) as AnimType
Player_Anims(0).startFrame = 0
load object "modelsmechbase-stand.x",1
Player_Anims(0).endFrame = total object frames(1)
Player_Anims(1).startFrame = total object frames(1)
append object "modelsmechbase-forwards.x",1,total object frames(1)
Player_Anims(1).endFrame = total object frames(1)
Player_Anims(2).startFrame = total object frames(1)
append object "modelsmechbase-backwards.x",1,total object frames(1)
Player_Anims(2).endFrame = total object frames(1)
Player_Anims(3).startFrame = total object frames(1)
append object "modelsmechbase-turnleft.x",1,total object frames(1)
Player_Anims(3).endFrame = total object frames(1)
Player_Anims(4).startFrame = total object frames(1)
append object "modelsmechbase-turnright.x",1,total object frames(1)
Player_Anims(4).endFrame = total object frames(1)
yrotate object 1,90
fix object pivot 1
set object texture 1,1,0
load object "modelsmechtop.x",2
yrotate object 2,90
fix object pivot 2
set object texture 2,1,0
global Player as PlayerType
Player.topAng# = 0
Player.anim = 0
Player.animSpeed# = 0.1
Player.weapon1type = 1
AddPlayerWeapon(1,Player.weapon1type)
Player.weapon2type = 1
AddPlayerWeapon(2,Player.weapon2type)
endfunction
function AddPlayerWeapon(position,weapontype)
obj = position + 2
if object exist(obj) then delete object obj
clone object obj,weaponType+99
select WeaponType
case 1
Minigun_Add(position)
endcase
endselect
endfunction
function FirePlayerWeapon(weapon)
if weapon = 1
weapontype = Player.weapon1type
else
weapontype = Player.weapon2type
endif
select weapontype
case 1
Minigun_Fire(weapon)
endcase
endselect
endfunction
function StopPlayerWeapon(weapon)
if weapon = 1
weapontype = Player.weapon1type
else
weapontype = Player.weapon2type
endif
select weapontype
case 1
Minigun_Stop(weapon)
endcase
endselect
endfunction
function CreateBullet(x#,z#,ang#,offset#,damage#,speed#,life,size#)
bul = GetNextBullet()
if bul > -1
obj = bul+200
if object exist(obj) = 0
clone object obj,111
else
exclude object off obj
endif
set object transparency obj,2
position object obj,x#,2.4,z#
yrotate object obj,ang#
move object obj,offset#
scale object obj,size#/2.0,size#,size#
Bullet(bul).damage# = damage#
Bullet(bul).speed# = speed#
Bullet(bul).life = life
endif
endfunction
function GetNextBullet()
for b=0 to 99
if Bullet(b).life = 0
exitfunction b
endif
next b
endfunction -1
function ProcessBullets()
for b=0 to 99
if Bullet(b).life > 0
obj = b+200
dec Bullet(b).life,1
if Bullet(b).life = 0
exclude object on obj
endif
move object obj,Bullet(b).speed#
endif
next b
endfunction
function CreateFlare(x#,z#,ang#,offset#,dec#,size#)
bul = GetNextFlare()
if bul > -1
obj = bul+300
if object exist(obj) = 0
clone object obj,112
else
exclude object off obj
endif
set object transparency obj,2
set alpha mapping on obj,100
position object obj,x#,2.4,z#
yrotate object obj,ang#
move object obj,offset#
size# = size# - (0.25*size#)+rnd(size#*50)/100.0
scale object obj,size#/2.0,size#,size#
Flare(bul).alpha# = 90
Flare(bul).alphadec# = dec#
endif
endfunction
function GetNextFlare()
for b=0 to 99
if Flare(b).alpha# <= 0
exitfunction b
endif
next b
endfunction -1
function ProcessFlares()
for b=0 to 99
if Flare(b).alpha# > 0
obj = b+300
set alpha mapping on obj,Flare(b).alpha#
dec Flare(b).alpha#, Flare(b).alphadec#
if Flare(b).alpha# <= 0
exclude object on obj
endif
endif
next b
endfunction
IT IS SO COOL!!!! I LOVE IT!!!!!!
"There will always be evil, for, without evil, the good shall lose their virtue."