Показать сообщение отдельно
Старый 08.10.2007, 18:38   #4
jimon
 
Сообщений: n/a
Re: Тип Камеры

да кстати, вот последний тип камеры из jAqua

Type TCamera

	'camera coordinates
	Field camera_x#,camera_y#
	
	Field Zoom# = 1.0
	Field GlobalAlpha# = 1.0
	
	Field EnableZoom% = 1
	Field EnableGlobalAlpha% = 1
	
	Field GrapX#
	Field GrapY#
	
	Method Serealize()
		SerFloat(camera_x)
		SerFloat(camera_y)
		SerFloat(Zoom)
		SerFloat(GlobalAlpha)
		SerInt(EnableZoom)
		SerInt(EnableGlobalAlpha)
	End Method
	
	'draw image with camera
	Method DrawImages(image:TImage,x#,y#,frame%=0)
		If image = Null Then
			RuntimeError "WTF ?! null image in camera.drawimages , please debug again :)"
		End If
		
		If EnableGlobalAlpha = 1 Then SetAlpha(GetAlpha()*GetGlobalAlpha())
		
		If EnableZoom = 1 Then
			Local scx#,scy#
			GetScale scx,scy
			SetScale scx*GetZoom(),scy*GetZoom()
		End If
		
		DrawImage image,GetScrX(x),GetScrY(y),frame
	End Method
	
	Method GetZoom#()
		If EnableZoom = 1 Then
			Return Zoom
		Else
			Return 1.0
		End If
	End Method
	Method GetGlobalAlpha#()
		If EnableGlobalAlpha = 1 Then
			Return GlobalAlpha
		Else
			Return 1.0
		End If
	End Method
	
	'move camera
	Method Move(x#,y#)
		camera_x :+ x
		camera_y :+ y
	End Method
	
	'set camera positon
	Method SetXY(x#,y#)
		camera_x = x
		camera_y = y
	End Method
	
	'get camera position
	Method GetX#()
		Return camera_x
	End Method
	Method GetY#()
		Return camera_y
	End Method
	
	'get mouse position with camera
	Method GetMouseX#()
		Return GetWorldX(MouseX())
	End Method
	Method GetMouseY#()
		Return GetWorldY(MouseY())
	End Method
	
	'get screen coordinates from world
	Method GetScrX#(x#)
		Return (x - camera_x)*GetZoom()
	End Method
	Method GetScrY#(y#)
		Return (y - camera_y)*GetZoom()
	End Method

	'get world coordinates from screen
	Method GetWorldX#(x#)
		Return x/GetZoom() + camera_x
	End Method
	Method GetWorldY#(y#)
		Return y/GetZoom() + camera_y
	End Method
	
	'return 1 if cordinates in current viewport
	Method InViewPort%(x#,y#)
		Local x2#,y2#
		x2 = GetScrX(x)
		y2 = GetScrY(y)
		
		If x2 >= 0 And x2 <= GrapX And y2 >= 0 And y2 <= GrapY Then
			Return 1
		Else
			Return 0
		End If
	End Method
	Method BoxInViewPort%(x#,y#,Width#,Height#)
		Local x2#,y2#,x3#,y3#
		x2 = GetScrX(x + Width/2.0)
		y2 = GetScrY(y + Height/2.0)
		x3 = GetScrX(x - Width/2.0)
		y3 = GetScrY(y - Height/2.0)
		
		If x2 >= 0 And x3 <= GrapX And y2 >= 0 And y3 <= GrapY Then
			Return 1
		Else
			Return 0
		End If
	End Method
	Method ImageInViewPort%(Img:TImage,x#,y#)
	
		Local x2#,y2#,x3#,y3#
		x2 = GetScrX(x + Float(Img.width)/2.0)
		y2 = GetScrY(y + Float(Img.height)/2.0)
		x3 = GetScrX(x - Float(Img.width)/2.0)
		y3 = GetScrY(y - Float(Img.height)/2.0)
		
		If x2 >= 0 And x3 <= GrapX And y2 >= 0 And y3 <= GrapY Then
			Return 1
		Else
			Return 0
		End If
	End Method
	
	
	Function Create:TCamera()
		Local cam:TCamera = New TCamera
		cam.GrapX = GraphicsWidth()
		cam.GrapY = GraphicsHeight()
		
		Return cam
	End Function
	
End Type
можете удалить метод Serealize нафиг
ибо вам он не нужен
 
Ответить с цитированием