i try to run it and it says one of my entities doesnt exist but i have checked it and i dont think anything's wrong can u see whats wrong?
Graphics3D 800, 600, 0, 1
SetBuffer BackBuffer()
Const player_col= 1
Const level_col = 2
Const enemy_col = 3
Const bullet_col= 4
Type bullettype
Field entityhandle
End Type
Type badguytype
Field entityhandle
Field state
End Type
light = CreateLight()
RotateEntity light, 30, 30, 0
camera_pivot= CreatePivot()
camera= CreateCamera(camera_pivot)
CameraRange camera,1,1000
level = CreateCube():ScaleEntity level,50,50,50:FlipMesh level:MoveEntity level,0,50,0:EntityColor level,20,20,200
levelfloor=CreatePlane():MoveEntity levelfloor,0,.002,0:EntityColor levelfloor,0,100,0
If KeyDown(2) Then weapon1= LoadMesh("SWORD.3ds", camera)
If KeyDown(3) Then weapon2= LoadMesh("pdpistol.3dd", camera)
bulletmesh= CreateCone() : RotateMesh bulletmesh,90,0,0 : ScaleEntity bulletmesh,.1,.1,.1
EntityType bulletmesh, bullet_col
EntityRadius bulletmesh,.01
enemymesh = LoadMesh("F15E.3ds")
EntityType enemymesh, enemy_col
HideEntity bulletmesh
HideEntity enemymesh
For iter= 1 To 10
badguy.badguyType = New badguyType
badguy\entityhandle= CopyEntity(enemymesh)
badguy\state = Rnd(1, 2)
Next
MoveEntity camera,0,.9,0
MoveEntity weapon1 Or weapon2, .1,-.15,.1
MoveEntity player, 20, 1, -20
For badguy = Each badguyType
PositionEntity badguy\entityhandle, Rnd(100)-50,.95, Rnd(100)-50
Next
EntityType camera_pivot, player_col
EntityRadius camera_pivot,.3,.95
EntityType level, level_col
Collisions player_col, level_col,5, 5
Collisions player_col, enemy_col, 1,2
Collisions enemy_col, level_col,10, 5
Collisions bullet_col, level_col, 100, 1
While Not KeyHit(1)
wkey = KeyDown(17) ;collect user input
skey = KeyDown(31) ;It's a good practice to collect these inputs only once
akey = KeyDown(30) ;per loop. This will prevent odd behaviors from happening,
dkey = KeyDown(32) ;for instance if the state of a key changes between multiple
mouse1 = MouseHit(1) ;checks of that key while still in the same loop.
If wkey Then MoveEntity camera_pivot, 0, 0, .1 ;Forward - w key
If skey Then MoveEntity camera_pivot, 0, 0, -.1 ;Back - s key
If akey Then MoveEntity camera_pivot, -.1, 0, 0 ;Left - a key
If dkey Then MoveEntity camera_pivot, .1, 0, 0 ;Right - d key
TurnEntity camera_pivot, 0, -MouseXSpeed()/5.0, 0 ;rotate player Pivot according to mouse X movement
TurnEntity camera, MouseYSpeed()/5.0, 0, 0 ;rotate camera up/down according to mouse Y movement
If EntityPitch(camera) < -45 ;don't allow camera to look below -45 degrees
RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera)
EndIf
If EntityPitch(camera) > 45 ;don't allow camera to look above 45 degrees
RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera)
EndIf
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 ;reset mouse position to middle of screen
TranslateEntity camera_pivot, 0, -.1, 0 ;simple gravity
If mouse1 ;check if left mouse button was pressed
bullet.bullettype = New bullettype ;create a bullet
bullet\entityhandle = CopyEntity(bulletmesh) ;create the bullet mesh
PositionEntity bullet\entityhandle, EntityX(weapon1, 1), EntityY(weapon1, 1), EntityZ(weapon1, 1) ;place the bullet at the guns position
RotateEntity bullet\entityhandle, EntityPitch(weapon1, 1), EntityYaw(weapon1, 1), EntityRoll(weapon1, 1);orientate the bullet with the gun
ResetEntity bullet\entityhandle ;otherwise bullet could hit enemy while moving from 0,0,0 to current position
EndIf
For thisbullet.bullettype = Each bullettype ;iterate through all of the bullets
MoveEntity thisbullet\entityhandle, 0, 0, 2 ;move the bullet forward along the bullets Z axis
If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet
EndIf
Next
UpdateWorld ;figures out collisions
For thisbullet = Each bullettype ;iterate through all of the bullets
If CountCollisions(thisbullet\entityhandle) > 0 ;check if bullet collided with something
enemyhit = EntityCollided(thisbullet\entityhandle, 3) ;note which enemy bullet collided with (if any)
If enemyhit > 0 ;enemyhit contains entity handle of enemy that was hit
For thisbadguy.badguytype = Each badguytype ;iterate through all of the badguys
If enemyhit = thisbadguy\entityhandle ;check if the enemy hit = this badguy
If thisbadguy\state <> 5 ;check if badguy is alive
thisbadguy\state = 5 ;dead ;make him dead
RotateEntity thisbadguy\entityhandle, 90, 0, 0 ;make him horizontal
EntityType thisbadguy\entityhandle, 0 ;turn off collisions for this badguy
TranslateEntity thisbadguy\entityhandle, 0, -.9, 0;set him on the ground
Exit ;exits the badguy For-Next loop (no need to check rest of badguys)
EndIf
EndIf
Next
EndIf
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
EndIf
Next
RenderWorld ;draws the 3d scene
Flip ;displays the scene to the screen
Wend
End
Graphics3D 800, 600, 0, 1
SetBuffer BackBuffer()
Const player_col= 1
Const level_col = 2
Const enemy_col = 3
Const bullet_col= 4
Type bullettype
Field entityhandle
End Type
Type badguytype
Field entityhandle
Field state
End Type
light = CreateLight()
RotateEntity light, 30, 30, 0
camera_pivot= CreatePivot()
camera= CreateCamera(camera_pivot)
CameraRange camera,1,1000
level = CreateCube():ScaleEntity level,50,50,50:FlipMesh level:MoveEntity level,0,50,0:EntityColor level,20,20,200
levelfloor=CreatePlane():MoveEntity levelfloor,0,.002,0:EntityColor levelfloor,0,100,0
If KeyDown(2) Then weapon1= LoadMesh("SWORD.3ds", camera)
If KeyDown(3) Then weapon2= LoadMesh("pdpistol.3dd", camera)
bulletmesh= CreateCone() : RotateMesh bulletmesh,90,0,0 : ScaleEntity bulletmesh,.1,.1,.1
EntityType bulletmesh, bullet_col
EntityRadius bulletmesh,.01
enemymesh = LoadMesh("F15E.3ds")
EntityType enemymesh, enemy_col
HideEntity bulletmesh
HideEntity enemymesh
For iter= 1 To 10
badguy.badguyType = New badguyType
badguy\entityhandle= CopyEntity(enemymesh)
badguy\state = Rnd(1, 2)
Next
MoveEntity camera,0,.9,0
MoveEntity weapon1 Or weapon2, .1,-.15,.1
MoveEntity player, 20, 1, -20
For badguy = Each badguyType
PositionEntity badguy\entityhandle, Rnd(100)-50,.95, Rnd(100)-50
Next
EntityType camera_pivot, player_col
EntityRadius camera_pivot,.3,.95
EntityType level, level_col
Collisions player_col, level_col,5, 5
Collisions player_col, enemy_col, 1,2
Collisions enemy_col, level_col,10, 5
Collisions bullet_col, level_col, 100, 1
While Not KeyHit(1)
wkey = KeyDown(17) ;collect user input
skey = KeyDown(31) ;It's a good practice to collect these inputs only once
akey = KeyDown(30) ;per loop. This will prevent odd behaviors from happening,
dkey = KeyDown(32) ;for instance if the state of a key changes between multiple
mouse1 = MouseHit(1) ;checks of that key while still in the same loop.
If wkey Then MoveEntity camera_pivot, 0, 0, .1 ;Forward - w key
If skey Then MoveEntity camera_pivot, 0, 0, -.1 ;Back - s key
If akey Then MoveEntity camera_pivot, -.1, 0, 0 ;Left - a key
If dkey Then MoveEntity camera_pivot, .1, 0, 0 ;Right - d key
TurnEntity camera_pivot, 0, -MouseXSpeed()/5.0, 0 ;rotate player Pivot according to mouse X movement
TurnEntity camera, MouseYSpeed()/5.0, 0, 0 ;rotate camera up/down according to mouse Y movement
If EntityPitch(camera) < -45 ;don't allow camera to look below -45 degrees
RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera)
EndIf
If EntityPitch(camera) > 45 ;don't allow camera to look above 45 degrees
RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera)
EndIf
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 ;reset mouse position to middle of screen
TranslateEntity camera_pivot, 0, -.1, 0 ;simple gravity
If mouse1 ;check if left mouse button was pressed
bullet.bullettype = New bullettype ;create a bullet
bullet\entityhandle = CopyEntity(bulletmesh) ;create the bullet mesh
PositionEntity bullet\entityhandle, EntityX(weapon1, 1), EntityY(weapon1, 1), EntityZ(weapon1, 1) ;place the bullet at the guns position
RotateEntity bullet\entityhandle, EntityPitch(weapon1, 1), EntityYaw(weapon1, 1), EntityRoll(weapon1, 1);orientate the bullet with the gun
ResetEntity bullet\entityhandle ;otherwise bullet could hit enemy while moving from 0,0,0 to current position
EndIf
For thisbullet.bullettype = Each bullettype ;iterate through all of the bullets
MoveEntity thisbullet\entityhandle, 0, 0, 2 ;move the bullet forward along the bullets Z axis
If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000 ;check if the bullet is way out of bounds
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet
EndIf
Next
UpdateWorld ;figures out collisions
For thisbullet = Each bullettype ;iterate through all of the bullets
If CountCollisions(thisbullet\entityhandle) > 0 ;check if bullet collided with something
enemyhit = EntityCollided(thisbullet\entityhandle, 3) ;note which enemy bullet collided with (if any)
If enemyhit > 0 ;enemyhit contains entity handle of enemy that was hit
For thisbadguy.badguytype = Each badguytype ;iterate through all of the badguys
If enemyhit = thisbadguy\entityhandle ;check if the enemy hit = this badguy
If thisbadguy\state <> 5 ;check if badguy is alive
thisbadguy\state = 5 ;dead ;make him dead
RotateEntity thisbadguy\entityhandle, 90, 0, 0 ;make him horizontal
EntityType thisbadguy\entityhandle, 0 ;turn off collisions for this badguy
TranslateEntity thisbadguy\entityhandle, 0, -.9, 0;set him on the ground
Exit ;exits the badguy For-Next loop (no need to check rest of badguys)
EndIf
EndIf
Next
EndIf
FreeEntity thisbullet\entityhandle ;delete the bullet mesh
Delete thisbullet ;delete the bullet
EndIf
Next
RenderWorld ;draws the 3d scene
Flip ;displays the scene to the screen
Wend
End