Тема: Обьект.
Показать сообщение отдельно
Старый 12.07.2013, 02:52   #6
Nex
Гигант индустрии
 
Аватар для Nex
 
Регистрация: 13.09.2008
Сообщений: 2,893
Написано 1,185 полезных сообщений
(для 3,298 пользователей)
Ответ: Обьект.

Graphics3D 1024,768,32,2
SetBuffer (BackBuffer ())

Global camera,player,bot,bot_start_position

Global player_life# = 100.0

Global dt# = 0.001
Global move_speed# = 100.0

Global agrDist# = 15.0
Global bot_x#=10,bot_z#

Global time_shoot%, time_shoot_delay%=1000

Type TBullet
	Field ent%,life#
End Type 

camera = CreateCamera ()
	RotateEntity camera,50,0,0
	PositionEntity camera,0,15,-15
light = CreateLight ()
	RotateEntity light,65,0,0

ground = CreatePlane ()
	EntityColor ground,121,141,40

player = CreateCube ()
	EntityColor player,105,188,217
	PositionEntity player,-10,1,0

bot_start_position = CreateCube ()
	EntityColor bot_start_position,50,50,50
	EntityAlpha bot_start_position,0.4
	ScaleEntity bot_start_position,0.3,0.3,0.3
	PositionEntity bot_start_position,bot_x,1,bot_z
bot = CreateCube  ()
	EntityColor bot,128,128,128
	PositionEntity bot,bot_x,1,bot_z

	SetFont (LoadFont ("Verdana",15,1,0,0))

While Not KeyHit (1)
	UpdatePlayer ()
	UpdateBot ()
	UpdateBullet ()
UpdateWorld ()
RenderWorld ()
	Draw2D ()
Flip 
Wend
End 

Function CreateBullet (parent%=0)
	b.TBullet = New TBullet
		b\life = 100
		b\ent = CreateCube (parent)
	   		EntityColor b\ent,165,110,37
			ScaleEntity b\ent,0.3,0.3,0.3
		EntityParent b\ent,0
End Function

Function UpdateBullet ()
	For b.TBullet = Each TBullet
		If b\life <=0 Then
			FreeEntity b\ent
			Delete b
		Else 
			b\life = b\life -1
	
			MoveEntity b\ent,0,0,((move_speed*4.0)*dt)
	
			If EntityDistance (b\ent,player) <1.5 Then
				player_life = player_life -10
				FreeEntity b\ent
				Delete b
			EndIf
		EndIf 
	Next 
End Function 

Function UpdatePlayer ()
	If KeyDown (200) Then MoveEntity player,0,0,move_speed*dt
	If KeyDown (208) Then MoveEntity player,0,0,-move_speed*dt
	If KeyDown (203) Then MoveEntity player,-move_speed*dt,0,0
	If KeyDown (205) Then MoveEntity player,move_speed*dt,0,0
End Function 

Function UpdateBot ()
	If EntityDistance# (bot,player) <agrDist# Then
		EntityColor bot,255,0,0
				
		PointEntity bot,player
		MoveEntity bot,0,0,(move_speed/4.0)*dt

		If time_shoot <= MilliSecs () Then
			CreateBullet (bot)
			time_shoot = MilliSecs () + time_shoot_delay
		EndIf 
	Else
		EntityColor bot,128,128,128

		PointEntity bot, bot_start_position
		MoveEntity bot,0,0,(move_speed/4.0)*dt
	EndIf 
End Function

Function Draw2D ()
	Color 0,0,0
		Text 11,11,"Life: "+player_life
	Color 255,255,255
		Text 10,10,"Life: "+player_life
End Function
(Offline)
 
Ответить с цитированием
Эти 2 пользователя(ей) сказали Спасибо Nex за это полезное сообщение:
Demon (12.07.2013), PREy (12.07.2013)