Hello all.
I have had this problem before & overcome it by making the types global, however this time it's not working.
I have a bullet, the bullet hits an enemy & the damage points of the bullet is deducted from the enemys life.
here is the section of the code where the problem is occouring. If anyone could help it would be greatly apreciated.
Type bullet
Field obj
Field bspeed#
Field bdamage#
Field life#
End Type
Function create_bullet(parent)
b.bullet = New bullet
b\obj = CreateSphere(10,parent)
EntityType b\obj,bullet_col
ScaleEntity b\obj,.25,.25,.25
PositionEntity b\obj,0,0,2
EntityColor b\obj,0,255,0
EntityFX b\obj,1
b\life = 50
b\bspeed = 4
b\bdamage = 1
EntityParent b\obj,0
End Function
Function update_bullet()
For b.bullet = Each bullet
MoveEntity b\obj,0,0,b\bspeed
b\life = b\life - 1
;If EntityX(b\obj) < -71 Then
; PositionEntity b\obj,70,0,EntityZ(b\obj)
;Else If EntityX(b\obj) > 71 Then
; PositionEntity b\obj,-70,0,EntityZ(b\obj)
;Else If EntityZ(b\obj) < -51 Then
; PositionEntity b\obj,EntityX(b\obj),0,50
;Else If EntityZ(b\obj) > 51 Then
; PositionEntity b\obj,EntityX(b\obj),0,-50
;End If
If EntityCollided (b\obj,enemy_col) Then
e\life = e\life - b\bdamage ; this is the line where it says object dose not exist
FreeEntity b\obj
Delete b
Else If b\life < 0 Then
FreeEntity b\obj
Delete b
End If
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Type enemy
Field mesh
Field x#,y#
Field xv#,yv#
Field life#
Field alpha#
Field rotx#,roty#,rotz#
Field order% = -1
End Type
Function create_enemy()
For a = 0 To 9
e.enemy = New enemy
e\mesh = CopyEntity(cube)
EntityType e\mesh,enemy_col
e\x# = Rnd(-74,74)
e\y# = Rnd(-54,54)
e\xv# = Rnd(-.5,.5)
e\yv# = Rnd(-.5,.5)
e\rotx# = Rnd(-2,2)
e\roty# = Rnd(-2,2)
e\rotz# = Rnd(-2,2)
e\life# = 10
e\alpha# = 1
e\order = e\order - 1
PositionEntity e\mesh,e\x,0,e\y
EntityOrder e\mesh,e\order
Next
End Function
Function update_enemy()
For e.enemy = Each enemy
e\x = e\x - e\xv
e\y = e\y - e\yv
PositionEntity e\mesh,e\x#,0,e\y#
If e\x# < -75 Then
e\x# = 74
Else If e\x# > 75 Then
e\x# = - 74
Else If e\y# < -55 Then
e\y# = 54
Else If e\y# > 55 Then
e\y# = -54
End If
TurnEntity e\mesh,e\rotx#,e\roty#,e\rotz#
If e\life =< 0 Then
FreeEntity e\mesh
Delete e
End If
Next
End Function
|