Organization

Blitz3D Forums/Blitz3D Programming/Organization

Let me show you my Object type and "UpdateObject functions:
;object type
Type obj
	Field obj_type$                         ;enemy, car, box, etc.
	Field name$                             ;name of object ("box1", "Bob's Car", etc.
	Field x#,y#,z#                          ;object position
	Field e_weapon                          ;enemy's weapon - leave at "0" if not an enemy
	Field d_secure                          ;if the door is secure (true/false) - only for doors
	Field el_dest#                          ;the y dest. of the elevator - only for elevator
	Field entity                            ;the actual mesh
	Field alpha#                            ;alpha of object
	Field shininess#                        ;shininess of object
	Field c_speed#                          ;car speed - leave at "0" if not a car
	Field c_wheels[4]                       ;car wheels - don't use if not a car
	Field x_vel#, y_vel#, z_vel#            ;velocity of the object
	Field w_type$                           ;weapon name
	Field w_id                              ;weapon id
	Field w_damage                          ;damage the weapon does
	Field offsetx, offsety, offsetz         ;offset values
End Type


Function:
;updates all objects
Function UpdateObjects()
	
	For o.obj = Each obj
	For pl_o.user = Each user
	
		Select o\obj_type$
		
			Case "enemy
			
				;enemy AI
			
			Case "car"
				
				;update car
				
			Case "crate" 
					
				;update crate
			
			Case "glass"
			
				;update glass
				
			Case "weapon"
		
			
			Case "door"
				If obj\d_secure = True
					If door_rotation <= 90 And good_code = True And EntityDistance(pl_o\camera,o\entity)<=5 And MouseHit(2)
						door_rotation = door_rotation + 1
						RotateEntity o\entity, 0, door_rotation, 0
					EndIf 
				Else
					If door_rotation <= 90 And EntityCollided(pl_o\camera,DOOR_COL) And MouseHit(2)
						door_rotation = door_rotation + 1
						RotateEntity o\entity, 0, door_rotation, 0
					EndIf
				EndIf
					
			Case "keypad"
				If EntityDistance(p\camera, o\entity)<=5 And MouseHit(2)
					While good_code = False
						Rect 350, 250, 25, 25
						Locate 350, 250 
						code$ = Input("Insert code - ")
					
						If code = right_code
							good_code = True
						EndIf
					Wend
				EndIf 
				
			Case "elevator"
				
				If EntityCollided(p\camera, LIFT_COL) And o\y <= o\el_dest
					MoveEntity o\entity, 0, -0.5, 0
				EndIf 
					
				
			Case "oil"
			
				If picked = o\entity
					e.effect = New effect
					e\entity = CopyEntity(ex_1\entity)
					PositionEntity e\entity, px#, py#, pz#
					RotateEntity o\entity, 0, 0, 90
					MoveEntity o\entity, 0, 1.5, 0
					
					If EntityDistance(p\camera, o\entity)<=5
						p\health = p\health - 5
					EndIf 
					
				EndIf 
				
			Case "computer"
							
				;computer catch on fire
				
			Case "weapon"
			
				;update weapon
							
		End Select 
		
		EntityAlpha o\entity, o\alpha#
		EntityShininess o\entity, o\shininess#
		
			
	Next 
	Next 
		
End Function