Mark Sibly 7 лет назад
Родитель
Сommit
3c3fa607a1

+ 62 - 0
modules/mojo3d/components/flybehaviour.monkey2

@@ -0,0 +1,62 @@
+
+Namespace mojo3d
+
+Class FlyBehaviour Extends Behaviour
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity )
+	End
+	
+	Property Speed:Float()
+		
+		Return _speed
+	
+	Setter( speed:Float )
+		
+		_speed=speed
+	End
+	
+	Method OnUpdate( elapsed:Float ) Override
+		
+		Local rspeed:=_speed*(elapsed/(1.0/60.0))
+		
+		Local entity:=Entity
+		
+		Local view:=App.ActiveWindow
+	
+		If Keyboard.KeyDown( Key.Up )
+			entity.RotateX( rspeed )
+		Else If Keyboard.KeyDown( Key.Down )
+			entity.RotateX( -rspeed )
+		Endif
+		
+		If Keyboard.KeyDown( Key.Left )
+			entity.RotateY( rspeed,True )
+		Else If Keyboard.KeyDown( Key.Right )
+			entity.RotateY( -rspeed,True )
+		Endif
+	
+		If Keyboard.KeyDown( Key.A )
+			entity.MoveZ( .1 )
+		Else If Keyboard.KeyDown( Key.Z )
+			entity.MoveZ( -.1 )
+		Endif
+		
+		If Mouse.ButtonDown( MouseButton.Left )
+			If Mouse.X<view.Width/3
+				entity.RotateY( rspeed,True )
+			Else If Mouse.X>view.Width/3*2
+				entity.RotateY( -rspeed,True )
+			Else
+				entity.Move( New Vec3f( 0,0,.1 ) )
+			Endif
+		Endif
+		
+	End
+	
+	Private
+	
+	Field _speed:Float=3.0
+	
+End

+ 0 - 68
modules/mojo3d/components/flycomponent.monkey2

@@ -1,68 +0,0 @@
-
-Namespace mojo3d
-
-Class FlyComponent Extends Component
-	
-	Const Type:=New ComponentType( "FlyController",0,ComponentTypeFlags.Singleton )
-	
-	Method New( entity:Entity )
-		
-		Super.New( entity,Type )
-	End
-	
-	Property Speed:Float()
-		
-		Return _speed
-	
-	Setter( speed:Float )
-		
-		_speed=speed
-	End
-	
-	Method OnUpdate( elapsed:Float ) Override
-		
-		Local c:=Entity.GetComponent<GameController>()
-		Assert( c,"Entity has no game controller" )
-		
-		Local rspeed:=_speed*(elapsed/(1.0/60.0))
-		
-		Local entity:=Entity
-		
-		Local view:=App.ActiveWindow
-	
-		If c.ButtonDown( Button.Up )
-			entity.RotateX( rspeed )
-		Else If c.ButtonDown( Button.Down )
-			entity.RotateX( -rspeed )
-		Endif
-		
-		If c.ButtonDown( Button.Left )
-			entity.RotateY( rspeed,True )
-		Else If c.ButtonDown( Button.Right )
-			entity.RotateY( -rspeed,True )
-		Endif
-	
-		If c.ButtonDown( Button.Forward )
-			entity.MoveZ( .1 )
-		Else If c.ButtonDown( Button.Backward )
-			entity.MoveZ( -.1 )
-		Endif
-		
-'		If Mouse.ButtonDown( MouseButton.Left )
-'			If Mouse.X<view.Width/3
-'				entity.RotateY( rspeed,True )
-'			Else If Mouse.X>view.Width/3*2
-'				entity.RotateY( -rspeed,True )
-'			Else
-'				entity.Move( New Vec3f( 0,0,.1 ) )
-'			Endif
-'		Endif
-		
-	End
-	
-	Private
-	
-	Field _speed:Float=3.0
-	
-End
-

+ 0 - 33
modules/mojo3d/components/gamecontroller.monkey2

@@ -1,33 +0,0 @@
-
-Namespace mojo3d
-
-Enum Button
-	Up
-	Down
-	Left
-	Right
-	Fire
-	Forward
-	Backward
-End
-
-Class GameController Extends Component
-	
-	Const Type:=New ComponentType( "GameController",-1,ComponentTypeFlags.Singleton )
-	
-	Method New( entity:Entity )
-		
-		Super.New( entity,Type )
-	End
-	
-	Method ButtonDown:Bool( button:Button ) Virtual
-	
-		Return False
-	End
-	
-	Method ButtonHit:Bool( button:Button ) Virtual
-		
-		Return False
-	End
-	
-End

+ 0 - 38
modules/mojo3d/components/keyboardcontroller.monkey2

@@ -1,38 +0,0 @@
-
-Namespace mojo3d
-
-Class KeyboardController Extends GameController
-	
-	Method New( entity:Entity )
-		
-		Super.New( entity )
-	End
-	
-	Method ButtonToKey:Key( button:Button )
-
-		Select button
-		Case Button.Up Return Key.Up
-		Case Button.Down Return Key.Down
-		Case Button.Left Return Key.Left
-		Case Button.Right Return Key.Right
-		Case Button.Fire Return Key.Space
-		Case Button.Forward Return Key.A
-		Case button.Backward Return Key.Z
-		End
-			
-		Return Null
-	End
-	
-	Method ButtonDown:Bool( button:Button ) Override
-		
-		Return Keyboard.KeyDown( ButtonToKey( button ) )
-	End
-	
-	Method ButtonHit:Bool( button:Button ) Override
-		
-		Return Keyboard.KeyHit( ButtonToKey( button ) )
-	End
-	
-End
-
-	

+ 1 - 3
modules/mojo3d/mojo3d.monkey2

@@ -9,9 +9,7 @@ Namespace mojo3d
 #Import "components/animation"
 #Import "components/animator"
 #Import "components/behaviour"
-#Import "components/flycomponent"
-#Import "components/gamecontroller"
-#Import "components/keyboardcontroller"
+#Import "components/flybehaviour"
 
 #Import "entities/camera"
 #Import "entities/light"

+ 1 - 5
modules/mojo3d/tests/ducks.monkey2

@@ -57,11 +57,7 @@ Class MyWindow Extends Window
 		_camera.FOV=90
 		_camera.Move( 0,15,-20 )
 		
-		_camera.AddComponent<KeyboardController>()
-'		New KeyboardController( _camera )
-		
-		_camera.AddComponent<FlyComponent>()
-'		New FlyComponent( _camera )
+		_camera.AddComponent<FlyBehaviour>()
 		
 		'create light
 		_light=New Light