Global and Collisions

Blitz3D Forums/Blitz3D Beginners Area/Global and Collisions

There are loads of ways of doing this but I wouldn't recommend using the handle method above. As has been suggested, just add an 'ID' or 'Style' field + a 'points' field into the actor type and create some constants to refer to each ID. This will tell you what kind of monster that .actor is.

e.g.

;Load Actor(s)

SeedRnd MilliSecs()

Const ID_PLAYER = 0
Const ID_MONSTER1 = 1
Const ID_MONSTER2 = 2

Type actor
	Field ID
	Field Points
	Field Entity
End Type

ACTORcreate( ID_PLAYER )				;create 1 of player
ACTORcreate( ID_MONSTER1 , 20 , 5115 )	;create 20 of monster1
ACTORcreate( ID_MONSTER2 , 15 , 1000 ) 	;create 15 of monster2

;
;
;
;
;
;
;
;

;Shooting the badguy
If CountCollisions(b\sprite)>0 ;this is my bullet

	;SG	
	Entity = EntityCollided(b\sprite,TYPE_BADGUY) ;collisions have been set via Const

	If Entity > 0

		a.actor = Object.actor( EntityName( Entity ) )
		If a <> Null
			enemy_hit_counter=enemy_hit_counter+1
			EmitSound bad_guy_sound,a\entity
			RotateEntity a\entity,0,270,0
			
			If enemy_hit_counter => 1


				;SG
				score = score + a\Points
				
				;do stuff based on ID
				Select a\ID
					Case ID_PLAYER
					Case ID_MONSTER1
					Case ID_MONSTER2
				End Select
				
				;SG
						
				PlaySound spawn_sound
				kill_counter=kill_counter+1
				HideEntity a\entity
				TranslateEntity a\entity,0,-200,0
				PositionEntity a\entity,80,-1,-88
				ShowEntity a\entity
			 	enemy_hit_counter=0
			EndIf
			
		EndIf

	EndIf

EndIf

;=====================================================================
;=====================================================================
;=====================================================================

Function ACTORcreate( ID , Number = 1 , Points = 0 )

	For loop = 1 To Number
	
		a.actor = New actor
		a\entity  = CopyEntity( scifiguy )
		
		;SG
		a\ID = ID
		a\Points = Points
		;SG
		
		EntityType a\entity,TYPE_BADGUY
		EntityRadius a\entity,rsize#
		Animate a\entity,1,.5,1
		PositionEntity a\entity,Rnd(1,200),32,Rnd(1,290)
		ScaleEntity a\entity,.12,.12,.12
		NameEntity a\Entity, Handle(a)
		
	Next
	
End Function