|
@@ -22,28 +22,86 @@
|
|
|
// THE SOFTWARE.
|
|
// THE SOFTWARE.
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
|
|
+using System.Collections.Generic;
|
|
|
using AtomicEngine;
|
|
using AtomicEngine;
|
|
|
|
|
|
|
|
namespace FeatureExamples
|
|
namespace FeatureExamples
|
|
|
{
|
|
{
|
|
|
public class RagdollSample : Sample
|
|
public class RagdollSample : Sample
|
|
|
{
|
|
{
|
|
|
- Scene scene;
|
|
|
|
|
- bool drawDebug;
|
|
|
|
|
- Camera camera;
|
|
|
|
|
|
|
+ Scene scene; // perspective (3d) scene, you know, where the ragdolls are.
|
|
|
|
|
+ Camera camera; // the regular camera
|
|
|
|
|
+ bool drawDebug; // bool to turn on/off debug hud.
|
|
|
|
|
+
|
|
|
|
|
+ // the 2nd scene for the hud "overlay"
|
|
|
|
|
+ Scene hudScene; // the hud scene
|
|
|
|
|
+ Camera hudCamera; // ortho cam for the (pixel perfect) hud
|
|
|
|
|
+ Vector <Sprite2D> filler; // for bargraph display
|
|
|
|
|
+
|
|
|
|
|
+ // more fun features...
|
|
|
|
|
+ List <float> bulletMass; // how heavy the bullet is
|
|
|
|
|
+ List <float> bulletSpeed; // how fast the bullet is
|
|
|
|
|
+ List <float> bulletSize; // how big the bullet is
|
|
|
|
|
+ int massCount, speedCount, sizeCount; // counters
|
|
|
|
|
+
|
|
|
|
|
+ float bulletArc; // shooting inclination
|
|
|
|
|
|
|
|
public RagdollSample() : base() { }
|
|
public RagdollSample() : base() { }
|
|
|
|
|
|
|
|
public override void Start()
|
|
public override void Start()
|
|
|
{
|
|
{
|
|
|
|
|
+ massCount = 2;
|
|
|
|
|
+ speedCount = 2;
|
|
|
|
|
+ sizeCount = 2;
|
|
|
|
|
+
|
|
|
|
|
+ bulletMass = new List<float>();
|
|
|
|
|
+ bulletSpeed = new List<float>();
|
|
|
|
|
+ bulletSize = new List<float>();
|
|
|
|
|
+
|
|
|
|
|
+ filler = new Vector <Sprite2D>();
|
|
|
|
|
+
|
|
|
|
|
+ bulletMass.Add(1.0f);
|
|
|
|
|
+ bulletMass.Add(10.0f);
|
|
|
|
|
+ bulletMass.Add(50.0f);
|
|
|
|
|
+ bulletMass.Add(100.0f);
|
|
|
|
|
+ bulletMass.Add(300.0f);
|
|
|
|
|
+ bulletMass.Add(666.0f);
|
|
|
|
|
+ bulletMass.Add(1000.0f);
|
|
|
|
|
+ bulletSpeed.Add(10.0f);
|
|
|
|
|
+ bulletSpeed.Add(22.0f);
|
|
|
|
|
+ bulletSpeed.Add(41.0f);
|
|
|
|
|
+ bulletSpeed.Add(72.0f);
|
|
|
|
|
+ bulletSpeed.Add(116.0f);
|
|
|
|
|
+ bulletSpeed.Add(200.0f);
|
|
|
|
|
+ bulletSpeed.Add(450.0f);
|
|
|
|
|
+ bulletSize.Add(0.25f);
|
|
|
|
|
+ bulletSize.Add(0.5f);
|
|
|
|
|
+ bulletSize.Add(1.25f);
|
|
|
|
|
+ bulletSize.Add(3.25f);
|
|
|
|
|
+ bulletSize.Add(5.25f);
|
|
|
|
|
+ bulletSize.Add(7.25f);
|
|
|
|
|
+ bulletSize.Add(11.25f);
|
|
|
|
|
+ bulletSize.Add(16.25f);
|
|
|
|
|
+
|
|
|
|
|
+ bulletArc = 0.25f;
|
|
|
|
|
+
|
|
|
base.Start();
|
|
base.Start();
|
|
|
CreateScene();
|
|
CreateScene();
|
|
|
|
|
+ CreateHUD(); // add an overlay HUD that tells you settings
|
|
|
SimpleCreateInstructionsWithWasd(
|
|
SimpleCreateInstructionsWithWasd(
|
|
|
- "\nLMB to spawn physics objects\n" +
|
|
|
|
|
- "F5 to save scene, F7 to load\n" +
|
|
|
|
|
- "Space to toggle physics debug geometry");
|
|
|
|
|
|
|
+ "LMB to spawn physics objects\n" +
|
|
|
|
|
+ "U=Mass, I=Speed, O=Size, R=Restart\n" +
|
|
|
|
|
+ "Space to toggle physics debug geometry\n");
|
|
|
SetupViewport();
|
|
SetupViewport();
|
|
|
SubscribeToEvents();
|
|
SubscribeToEvents();
|
|
|
|
|
+
|
|
|
|
|
+ RestartJacks ();
|
|
|
|
|
+
|
|
|
|
|
+ UpdateSpeedHud (speedCount);
|
|
|
|
|
+ UpdateMassHud (massCount);
|
|
|
|
|
+ UpdateSizeHud (sizeCount);
|
|
|
|
|
+
|
|
|
|
|
+ GetSubsystem<Input>().SetMouseVisible (false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SubscribeToEvents()
|
|
void SubscribeToEvents()
|
|
@@ -70,23 +128,74 @@ namespace FeatureExamples
|
|
|
SpawnObject();
|
|
SpawnObject();
|
|
|
|
|
|
|
|
/* TODO: Scene.SaveXML/Scene.LoadXML
|
|
/* TODO: Scene.SaveXML/Scene.LoadXML
|
|
|
-
|
|
|
|
|
if (input.GetKeyPress(Constants.KEY_F5))
|
|
if (input.GetKeyPress(Constants.KEY_F5))
|
|
|
scene.SaveXml(fileSystem.UserDocumentsDir + "/Scenes/Physics.xml");
|
|
scene.SaveXml(fileSystem.UserDocumentsDir + "/Scenes/Physics.xml");
|
|
|
-
|
|
|
|
|
if (input.GetKeyPress(Constants.KEY_F7))
|
|
if (input.GetKeyPress(Constants.KEY_F7))
|
|
|
scene.LoadXml(fileSystem.UserDocumentsDir + "/Scenes/Physics.xml");
|
|
scene.LoadXml(fileSystem.UserDocumentsDir + "/Scenes/Physics.xml");
|
|
|
-
|
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+ if (input.GetKeyPress (Constants.KEY_U)) {
|
|
|
|
|
+ massCount++;
|
|
|
|
|
+ if ( massCount > 5 )
|
|
|
|
|
+ massCount = 0;
|
|
|
|
|
+ UpdateMassHud (massCount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (input.GetKeyPress (Constants.KEY_I)) {
|
|
|
|
|
+ speedCount++;
|
|
|
|
|
+ if ( speedCount> 5 )
|
|
|
|
|
+ speedCount = 0;
|
|
|
|
|
+ UpdateSpeedHud (speedCount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (input.GetKeyPress (Constants.KEY_O)) {
|
|
|
|
|
+ sizeCount++;
|
|
|
|
|
+ if ( sizeCount > 5 )
|
|
|
|
|
+ sizeCount = 0;
|
|
|
|
|
+ UpdateSizeHud (sizeCount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (input.GetKeyPress (Constants.KEY_P)) {
|
|
|
|
|
+ if ( bulletArc == 0.0 )
|
|
|
|
|
+ bulletArc = 0.25f;
|
|
|
|
|
+ else if ( bulletArc > 0.0 )
|
|
|
|
|
+ bulletArc = 0.0f;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (input.GetKeyPress (Constants.KEY_R)) {
|
|
|
|
|
+ RestartJacks ();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (input.GetKeyPress(Constants.KEY_SPACE))
|
|
if (input.GetKeyPress(Constants.KEY_SPACE))
|
|
|
drawDebug = !drawDebug;
|
|
drawDebug = !drawDebug;
|
|
|
|
|
+
|
|
|
|
|
+ UpdateFps ();
|
|
|
|
|
+ CleanUpSome ();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void UpdateFps ()
|
|
|
|
|
+ {
|
|
|
|
|
+ var eng = GetSubsystem<Engine>();
|
|
|
|
|
+ string mystr = "FPS: " + eng.GetFps ().ToString ();
|
|
|
|
|
+ mystr += "\nUse WASD keys and mouse/touch to move\n"
|
|
|
|
|
+ + "LMB to spawn physics objects\n"
|
|
|
|
|
+ + "U=Mass, I=Speed, O=Size, R=Restart\n"
|
|
|
|
|
+ + "Space to toggle physics debug geometry";
|
|
|
|
|
+ SetInstructions ( mystr );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SetupViewport()
|
|
void SetupViewport()
|
|
|
{
|
|
{
|
|
|
var renderer = GetSubsystem<Renderer>();
|
|
var renderer = GetSubsystem<Renderer>();
|
|
|
- renderer.SetViewport(0, new Viewport(scene, CameraNode.GetComponent<Camera>()));
|
|
|
|
|
|
|
+ var cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
+
|
|
|
|
|
+ renderer.SetNumViewports(2); // use 2 viewports, 1 for 3d and 1 for the 2d hud
|
|
|
|
|
+ var viewport2_ = new Viewport(hudScene, hudCamera ); // hud orthographic viewport, scene and camera
|
|
|
|
|
+ var overlayRenderPath = new RenderPath();
|
|
|
|
|
+ overlayRenderPath.Load(cache.GetResource<XMLFile>("PostProcess/FrontPath.xml")); //special renderpath that does not clear
|
|
|
|
|
+ viewport2_.SetRenderPath(overlayRenderPath); // apply to hud viewport, so the background is transparent
|
|
|
|
|
+ renderer.SetViewport(0, new Viewport(scene, camera)); // perspective viewport, scene and camera
|
|
|
|
|
+ renderer.SetViewport(1, viewport2_); // and add in the HUD viewport
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CreateScene()
|
|
void CreateScene()
|
|
@@ -141,7 +250,37 @@ namespace FeatureExamples
|
|
|
shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);
|
|
shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Create animated models
|
|
|
|
|
|
|
+ // Create the camera. Limit far clip distance to match the fog
|
|
|
|
|
+ CameraNode = new Node();
|
|
|
|
|
+ CameraNode.SetName("Camera");
|
|
|
|
|
+ camera = CameraNode.CreateComponent<Camera>();
|
|
|
|
|
+ camera.FarClip = 300.0f;
|
|
|
|
|
+ // Set an initial position for the camera scene node above the plane
|
|
|
|
|
+ CameraNode.Position = new Vector3(0.0f, 3.0f, -20.0f);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void RestartJacks()
|
|
|
|
|
+ {
|
|
|
|
|
+ var ll = new Vector <Node>(); //get rid of some old objects
|
|
|
|
|
+ scene.GetChildrenWithName ( ll, "Sphere", true);
|
|
|
|
|
+ for ( int ii=0; ii<ll.Size; ii++ ) {
|
|
|
|
|
+ ll[ii].Remove ();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var nn = new Vector <Node>();
|
|
|
|
|
+ scene.GetChildrenWithName ( nn, "Stuffing", true);
|
|
|
|
|
+ for ( int ii=0; ii<nn.Size; ii++ ) {
|
|
|
|
|
+ nn[ii].Remove ();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var mm = new Vector <Node>();
|
|
|
|
|
+ scene.GetChildrenWithName ( mm, "Jack", true);
|
|
|
|
|
+ for ( int ii=0; ii<mm.Size; ii++ ) {
|
|
|
|
|
+ mm[ii].Remove ();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Create animated models, you dont know ... jack
|
|
|
|
|
+ var cache = GetSubsystem<ResourceCache>();
|
|
|
for (int z = -1; z <= 1; ++z)
|
|
for (int z = -1; z <= 1; ++z)
|
|
|
{
|
|
{
|
|
|
for (int x = -4; x <= 4; ++x)
|
|
for (int x = -4; x <= 4; ++x)
|
|
@@ -172,13 +311,146 @@ namespace FeatureExamples
|
|
|
modelNode.AddComponent(new Ragdoll());
|
|
modelNode.AddComponent(new Ragdoll());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Create the camera. Limit far clip distance to match the fog
|
|
|
|
|
- CameraNode = new Node();
|
|
|
|
|
- camera = CameraNode.CreateComponent<Camera>();
|
|
|
|
|
- camera.FarClip = 300.0f;
|
|
|
|
|
- // Set an initial position for the camera scene node above the plane
|
|
|
|
|
- CameraNode.Position = new Vector3(0.0f, 3.0f, -20.0f);
|
|
|
|
|
|
|
+ void CreateHUD()
|
|
|
|
|
+ {
|
|
|
|
|
+ float hscal = 0.4f;
|
|
|
|
|
+ //
|
|
|
|
|
+ // create a 2nd viewport and scene for a hud with sprites.
|
|
|
|
|
+ //
|
|
|
|
|
+ hudScene = new Scene();
|
|
|
|
|
+ hudScene.CreateComponent<Octree>();
|
|
|
|
|
+ // Create camera node
|
|
|
|
|
+ var hudCam = hudScene.CreateChild("HudCamera");
|
|
|
|
|
+ // Set camera's position
|
|
|
|
|
+ hudCam.SetPosition(new Vector3(0.0f, 0.0f, -10.0f));
|
|
|
|
|
+ hudCamera = hudCam.CreateComponent<Camera>();
|
|
|
|
|
+ hudCamera.SetOrthographic(true);
|
|
|
|
|
+ var graphics = GetSubsystem<Graphics>();
|
|
|
|
|
+ hudCamera.SetOrthoSize ((float)graphics.GetHeight () * PixelSize ); //PIXEL_SIZE
|
|
|
|
|
+
|
|
|
|
|
+ var cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
+
|
|
|
|
|
+ // add a crosshair in the center of the screen
|
|
|
|
|
+ var sprite = cache.GetResource<Sprite2D>("Textures/NinjaSnowWar/Sight.png");
|
|
|
|
|
+ var targetSprite_ = hudScene.CreateChild("targetSprite");
|
|
|
|
|
+ targetSprite_.SetPosition2D(new Vector2(0,0));
|
|
|
|
|
+ targetSprite_.SetScale2D( new Vector2(0.75f, 0.75f));
|
|
|
|
|
+ var staticSprite = targetSprite_.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ staticSprite.SetSprite(sprite); // Set sprite
|
|
|
|
|
+ staticSprite.SetBlendMode( AtomicEngine.BlendMode.BLEND_ALPHA ); // Set blend mode
|
|
|
|
|
+ staticSprite.SetAlpha(0.3f);
|
|
|
|
|
+
|
|
|
|
|
+ // borrow the spinning coin from the 2DSprite example to show what the possibilities are
|
|
|
|
|
+ float halfWidth = graphics.Width * 0.5f * PixelSize;
|
|
|
|
|
+ float halfHeight = graphics.Height * 0.5f * PixelSize;
|
|
|
|
|
+ // Get animation set
|
|
|
|
|
+ AnimationSet2D animationSet = cache.Get<AnimationSet2D>("Urho2D/GoldIcon.scml");
|
|
|
|
|
+ if (animationSet == null) return;
|
|
|
|
|
+ var spriteNode2 = hudScene.CreateChild("AnimatedSprite2D");
|
|
|
|
|
+ AnimatedSprite2D animatedSprite = spriteNode2.CreateComponent<AnimatedSprite2D>();
|
|
|
|
|
+ animatedSprite.AnimationSet = animationSet; // Set animation
|
|
|
|
|
+ animatedSprite.SetAnimation("idle", LoopMode2D.LM_DEFAULT);
|
|
|
|
|
+ spriteNode2.SetPosition2D(new Vector2(halfWidth - 0.4f, halfHeight - 0.4f));
|
|
|
|
|
+
|
|
|
|
|
+ // (bullet) mass, speed size feature huds
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill1.png") );
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill2.png") );
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill3.png") );
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill4.png") );
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill5.png") );
|
|
|
|
|
+ filler.Push ( cache.GetResource<Sprite2D>("Textures/hudfill6.png") );
|
|
|
|
|
+
|
|
|
|
|
+ Sprite2D spritem = cache.GetResource<Sprite2D>("Textures/hudmass.png");
|
|
|
|
|
+ Node hudm = hudScene.CreateChild("hudMass");
|
|
|
|
|
+ hudm.SetScale2D(new Vector2(hscal,hscal));
|
|
|
|
|
+ hudm.SetPosition2D( new Vector2( 0f - (halfWidth/3.0f), halfHeight - 0.4f));
|
|
|
|
|
+ StaticSprite2D hudSpritem = hudm.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSpritem.SetSprite(spritem);
|
|
|
|
|
+ hudSpritem.SetAlpha(0.9f);
|
|
|
|
|
+ hudSpritem.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSpritem.SetOrderInLayer(3);
|
|
|
|
|
+ Node hudfm = hudm.CreateChild("hudMassFill");
|
|
|
|
|
+ hudfm.SetScale2D(new Vector2(1f,1f));
|
|
|
|
|
+ hudfm.SetPosition2D( new Vector2( 0f, 0f));
|
|
|
|
|
+ StaticSprite2D hudSpritefm = hudfm.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSpritefm.SetSprite(filler[0]);
|
|
|
|
|
+ hudSpritefm.SetAlpha(0.9f);
|
|
|
|
|
+ hudSpritefm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSpritefm.SetOrderInLayer(-3);
|
|
|
|
|
+
|
|
|
|
|
+ Sprite2D sprites = cache.GetResource<Sprite2D>("Textures/hudspeed.png");
|
|
|
|
|
+ Node huds = hudScene.CreateChild("hudSpeed");
|
|
|
|
|
+ huds.SetScale2D(new Vector2(hscal,hscal));
|
|
|
|
|
+ huds.SetPosition2D( new Vector2( 0f, halfHeight - 0.4f));
|
|
|
|
|
+ StaticSprite2D hudSprites = huds.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSprites.SetSprite(sprites);
|
|
|
|
|
+ hudSprites.SetAlpha(0.9f);
|
|
|
|
|
+ hudSprites.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSprites.SetOrderInLayer(3);
|
|
|
|
|
+ Node hudsm = huds.CreateChild("hudSpeedFill");
|
|
|
|
|
+ hudsm.SetScale2D(new Vector2(1f,1f));
|
|
|
|
|
+ hudsm.SetPosition2D( new Vector2( 0f, 0f));
|
|
|
|
|
+ StaticSprite2D hudSpritesm = hudsm.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSpritesm.SetSprite(filler[0]);
|
|
|
|
|
+ hudSpritesm.SetAlpha(0.9f);
|
|
|
|
|
+ hudSpritesm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSpritesm.SetOrderInLayer(-3);
|
|
|
|
|
+
|
|
|
|
|
+ Sprite2D spritez = cache.GetResource<Sprite2D>("Textures/hudsize.png");
|
|
|
|
|
+ Node hudz = hudScene.CreateChild("hudSize");
|
|
|
|
|
+ hudz.SetScale2D(new Vector2(hscal,hscal));
|
|
|
|
|
+ hudz.SetPosition2D( new Vector2( 0f + (halfWidth/3.0f), halfHeight - 0.4f));
|
|
|
|
|
+ StaticSprite2D hudSpritez = hudz.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSpritez.SetSprite(spritez);
|
|
|
|
|
+ hudSpritez.SetAlpha(0.9f);
|
|
|
|
|
+ hudSpritez.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSpritez.SetOrderInLayer(3);
|
|
|
|
|
+ Node hudzm = hudz.CreateChild("hudSizeFill");
|
|
|
|
|
+ hudzm.SetScale2D(new Vector2(1f,1f));
|
|
|
|
|
+ hudzm.SetPosition2D( new Vector2( 0f, 0f));
|
|
|
|
|
+ StaticSprite2D hudSpritezm = hudzm.CreateComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSpritezm.SetSprite(filler[0]);
|
|
|
|
|
+ hudSpritezm.SetAlpha(0.9f);
|
|
|
|
|
+ hudSpritezm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA);
|
|
|
|
|
+ hudSpritezm.SetOrderInLayer(-3);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void UpdateMassHud ( int value )
|
|
|
|
|
+ {
|
|
|
|
|
+ Node xNode = hudScene.GetChild("hudMass", true);
|
|
|
|
|
+ if (xNode != null) {
|
|
|
|
|
+ Node fillx = xNode.GetChild("hudMassFill");
|
|
|
|
|
+ if (fillx != null) {
|
|
|
|
|
+ StaticSprite2D hudSprite = fillx.GetComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSprite.SetSprite(filler[value]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void UpdateSpeedHud ( int value )
|
|
|
|
|
+ {
|
|
|
|
|
+ Node xNode = hudScene.GetChild("hudSpeed", true);
|
|
|
|
|
+ if (xNode != null) {
|
|
|
|
|
+ Node fillx = xNode.GetChild("hudSpeedFill");
|
|
|
|
|
+ if (fillx != null) {
|
|
|
|
|
+ StaticSprite2D hudSprite = fillx.GetComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSprite.SetSprite(filler[value]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void UpdateSizeHud ( int value )
|
|
|
|
|
+ {
|
|
|
|
|
+ Node xNode = hudScene.GetChild("hudSize", true);
|
|
|
|
|
+ if (xNode != null) {
|
|
|
|
|
+ Node fillx = xNode.GetChild("hudSizeFill");
|
|
|
|
|
+ if (fillx != null) {
|
|
|
|
|
+ StaticSprite2D hudSprite = fillx.GetComponent<StaticSprite2D>();
|
|
|
|
|
+ hudSprite.SetSprite(filler[value]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SpawnObject()
|
|
void SpawnObject()
|
|
@@ -188,25 +460,39 @@ namespace FeatureExamples
|
|
|
Node boxNode = scene.CreateChild("Sphere");
|
|
Node boxNode = scene.CreateChild("Sphere");
|
|
|
boxNode.Position = CameraNode.Position;
|
|
boxNode.Position = CameraNode.Position;
|
|
|
boxNode.Rotation = CameraNode.Rotation;
|
|
boxNode.Rotation = CameraNode.Rotation;
|
|
|
- boxNode.SetScale(0.25f);
|
|
|
|
|
|
|
+ boxNode.SetScale(bulletSize[sizeCount]);
|
|
|
StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
|
|
StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
|
|
|
boxObject.Model = cache.Get<Model>("Models/Sphere.mdl");
|
|
boxObject.Model = cache.Get<Model>("Models/Sphere.mdl");
|
|
|
boxObject.SetMaterial(cache.Get<Material>("Materials/StoneSmall.xml"));
|
|
boxObject.SetMaterial(cache.Get<Material>("Materials/StoneSmall.xml"));
|
|
|
boxObject.CastShadows = true;
|
|
boxObject.CastShadows = true;
|
|
|
|
|
|
|
|
RigidBody body = boxNode.CreateComponent<RigidBody>();
|
|
RigidBody body = boxNode.CreateComponent<RigidBody>();
|
|
|
- body.Mass = 1.0f;
|
|
|
|
|
|
|
+ body.Mass = bulletMass[massCount];
|
|
|
body.RollingFriction = 0.15f;
|
|
body.RollingFriction = 0.15f;
|
|
|
CollisionShape shape = boxNode.CreateComponent<CollisionShape>();
|
|
CollisionShape shape = boxNode.CreateComponent<CollisionShape>();
|
|
|
shape.SetSphere(1.0f, Vector3.Zero, Quaternion.Identity);
|
|
shape.SetSphere(1.0f, Vector3.Zero, Quaternion.Identity);
|
|
|
|
|
|
|
|
- const float objectVelocity = 10.0f;
|
|
|
|
|
|
|
+ float objectVelocity = bulletSpeed[speedCount];
|
|
|
|
|
|
|
|
// Set initial velocity for the RigidBody based on camera forward vector. Add also a slight up component
|
|
// Set initial velocity for the RigidBody based on camera forward vector. Add also a slight up component
|
|
|
// to overcome gravity better
|
|
// to overcome gravity better
|
|
|
- body.SetLinearVelocity(CameraNode.Rotation * new Vector3(0.0f, 0.25f, 1.0f) * objectVelocity);
|
|
|
|
|
|
|
+ body.SetLinearVelocity(CameraNode.Rotation * new Vector3(0.0f, bulletArc, 1.0f) * objectVelocity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ void CleanUpSome() // destroy the bullets when they get far enough away
|
|
|
|
|
+ {
|
|
|
|
|
+ Node cam = CameraNode; // note - the camera isnt in the scene
|
|
|
|
|
+ if ( cam == null )
|
|
|
|
|
+ return;
|
|
|
|
|
+ var mm = new Vector <Node>();
|
|
|
|
|
+ scene.GetChildrenWithName ( mm, "Sphere", true);
|
|
|
|
|
+ for ( int ii=0; ii<mm.Size; ii++ ) {
|
|
|
|
|
+ float dist = ( mm[ii].GetWorldPosition() - cam.GetWorldPosition() ).Length;
|
|
|
|
|
+ if (dist > 270.0f) {
|
|
|
|
|
+ mm[ii].Remove ();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|