Hi Rich - you're right,
local Enemy as EnemyType[1000] works perfectly. I had just forgotten to write
local (Markus fixed that!)
But I'm unsure about this one:
Enemy[ID].Mesh = LoadObject( "toxiccrate.x", 1.0)
Do I really need to load the file from the hard drive for each single enemy?
//******************************************************
// Spawning Enemies
//******************************************************
//Init App
SetWindowTitle( "Spawning enemies" )
SetSyncRate(0, 0)
SetWindowSize( 1600, 1200, 0 )
SetScissor(0, 0, 0, 0)
UseNewDefaultFonts( 1 )
SetGenerateMipmaps( 1 ) //Generate Mipmaps for nicer looking textures
floorTexID = LoadImage("aaa.png")
SetImageWrapU( floorTexID, 1 )
SetImageWrapV( floorTexID, 1 )
floorNrm = LoadImage("aaaB_nrm.png")
SetImageWrapU( floorNrm, 1 )
SetImageWrapV( floorNrm, 1 )
floorBoxID = CreateObjectPlane( 60, 60 )
SetObjectLightMode( floorBoxID, 1 )
SetObjectPosition( floorBoxID, 0, 0, 0 )
SetObjectRotation( floorBoxID, 90, 0, 0 )
SetObjectMeshUVScale( floorBoxID, 1, 0, 10, 10 )
SetObjectImage( floorBoxID, floorTexID, 0 )
SetObjectNormalMap( floorBoxID, floorNrm )
SetSkyBoxHorizonColor( 128,128,128 )
SetSkyBoxHorizonSize( 10, 2 )
SetSkyBoxSkyColor( 7, 7, 13)
SetSkyBoxSunColor( 128,128,128 )
SetSkyBoxVisible( 1 )
SetSkyBoxSunSize( 1, 3.0 )
SetSkyBoxSunVisible( 1 )
mainLight As Integer = 472
CreatePointLight(mainLight, 0, 2, -0.3, 5, 200, 200, 200 )
SetPointLightMode( mainLight, 1 )
SetPointLightPosition( mainLight, 0, 30, 0 )
SetPointLightRadius( mainLight, 70 )
SetPointLightColor( mainLight, 0, 0, 255 )
SetSunActive (1)
SetSunDirection( -0.3714, -0.7428, 0.5571 )
setsunColor(120,110,80)
/*===============================================================================
ENEMIES
===============================================================================*/
// TODO:
// I need to use actual time for LifeTime
Type EnemyType
does_enemy_exist as Integer
Health as Integer
Mesh as Integer
Dif as Integer
Nrm as Integer
LifeTime as Integer
EndType
local Enemy as EnemyType[1000]
For E = 0 to Enemy.length
Enemy[E].does_enemy_exist = 0
Enemy[E].Health = 0
Enemy[E].LifeTime = 0
next
function SpawnEnemy(E ref as EnemyType, SpawnSpotX as Float, SpawnSpotY as Float, SpawnSpotZ as Float)
E.does_enemy_Exist = 1
E.Health = 100
E.Mesh = LoadObject( "book.x", 1.0)
E.Dif = LoadImage("book_D.png")
E.Nrm = LoadImage("book_N.png")
SetObjectImage(E.Mesh, E.Dif, 0)
SetObjectNormalMap(E.Mesh, E.Nrm)
setObjectPosition (E.Mesh, SpawnSpotX, SpawnSpotY, SpawnSpotZ)
endfunction
function MoveEnemy(E ref as EnemyType, xMove as Float, yMove as Float, zMove as Float)
setObjectPosition (E.Mesh, getObjectX(E.Mesh)+xMove, getObjectY(E.Mesh)+yMove, getObjectZ(E.Mesh)+zMove)
endfunction
function CloneEnemy(E ref as EnemyType)
endfunction
function HitEnemy(E ref as EnemyType)
endfunction
function DestroyEnemy(E ref as EnemyType)
E.does_enemy_Exist = 0
endfunction
SpawnEnemy(Enemy[0], 0, 0, 0)
SpawnEnemy(Enemy[3], 1, 5, 0)
do
print (Enemy.length)
// Loop through all existing enemies
for E = 0 to Enemy.Length
if Enemy[E].does_enemy_Exist = 1
Enemy[E].LifeTime = Enemy[E].LifeTime + 1
if Enemy[E].LifeTime > 1000
MoveEnemy(Enemy[E], 0.0, 0.02, -0.02)
endif
endif
next
if GetRawKeyPressed(27) //Esc
End //Close App
endif
if GetRawKeyState(13) = 1 //Enter
MoveEnemy(Enemy[0], 0.03, 0.01, -0.02)
endif
/*===============================================================================
RENDER TO SCREEN CAMERA
===============================================================================*/
//Sync to update the monitor display (the HMD display is updated through AGKVR's Render Command
//so this Sync is not necessary to for rendering to the HMD)
Sync()
loop