ninja.monkey2 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "<mojo3d-loaders>"
  6. #Import "assets/psionic/ninja.b3d"
  7. #Import "assets/psionic/nskinbl.jpg"
  8. Using std..
  9. Using mojo..
  10. Using mojo3d..
  11. Class MyWindow Extends Window
  12. Field _scene:Scene
  13. Field _camera:Camera
  14. Field _light:Light
  15. Field _ground:Model
  16. Field _ninja:Model
  17. Field _animator:Animator
  18. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  19. Super.New( title,width,height,flags )
  20. 'create scene
  21. '
  22. _scene=Scene.GetCurrent()
  23. _scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
  24. 'create camera
  25. '
  26. _camera=New Camera( Self )
  27. _camera.AddComponent<FlyBehaviour>()
  28. _camera.Near=.1
  29. _camera.Far=100
  30. _camera.Move( 0,5,-7 )
  31. 'create light
  32. '
  33. _light=New Light
  34. _light.Rotate( 75,15,0 ) 'aim directional light 'down' - Pi/2=90 degrees.
  35. _light.CastsShadow=True
  36. 'create ground
  37. '
  38. _ground=Model.CreateBox( New Boxf( -50,-5,-50,50,0,50 ),1,1,1,New PbrMaterial( Color.Green ) )
  39. _ground.CastsShadow=False
  40. 'create turtle
  41. '
  42. _ninja=Model.LoadBoned( "asset::ninja.b3d" )
  43. _animator=_ninja.Animator
  44. _ninja.RotateY( 165 )
  45. ' _ninja.Scale=New Vec3f( .125 )
  46. _animator.MasterSpeed=0.5
  47. Local anim1:=_animator.Animations[0].Slice( "Walk",1,14,AnimationMode.Looping )
  48. Local anim2:=_animator.Animations[0].Slice( "Idle",206,250,AnimationMode.Looping )
  49. Local anim3:=_animator.Animations[0].Slice( "Attack",134,145,AnimationMode.OneShot )
  50. _animator.Animations.Add( anim1 )
  51. _animator.Animations.Add( anim2 )
  52. _animator.Animations.Add( anim3 )
  53. End
  54. Method OnRender( canvas:Canvas ) Override
  55. RequestRender()
  56. If _animator.Animating?.Name<>"Attack"
  57. If Keyboard.KeyHit( Key.Space ) 'attack!
  58. _animator.Animate( "Attack",.2 )
  59. Else If Keyboard.KeyDown( Key.Enter ) 'walk
  60. _animator.Animate( "Walk",.2 )
  61. Else 'idle
  62. _animator.Animate( "Idle",.2 )
  63. Endif
  64. Endif
  65. _scene.Update()
  66. _camera.Render( canvas )
  67. canvas.Scale( Width/640.0,Height/480.0 )
  68. canvas.DrawText( "Hold [Enter] to strut, [Space] to attack! anim time="+_ninja.Animator.Time,0,0 )
  69. End
  70. End
  71. Function Main()
  72. New AppInstance
  73. New MyWindow
  74. App.Run()
  75. End