public void OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            ////Do not collide with whatever created the bullet
            if (args.CollideWith == Creator)
            {
                return;
            }

            if (args.CollideWith.Equals("Particle"))
            {
                return;
            }

            ////We cast to RigidBodyCollisionEventArgs to get access to the info about the shapes involved.
            var rigidBodyArgs = args as RigidBodyCollisionEventArgs;

            if (rigidBodyArgs != null && rigidBodyArgs.OtherShape.IsSensor)
            {
                return;
            }

            //Scene.Current.RemoveObject(GameObj);
            Speed = -Speed;

            if (args.CollideWith.FullName == obstacle.FullName)
            {
                Vector3 offset = new Vector3(0, -40, 0);
                if (Generation < 2)
                {
                    Vector3 pos   = m_Transform.Pos;
                    float   angle = m_Transform.Angle;
                    //Scene.Current.RemoveObject(GameObj);
                    for (float i = 1.5f; i < 2.5f; i += 0.3f)
                    {
                        GameObject particle = Particles.Res.Instantiate(pos + offset, -angle + i);

                        ParticleController particleController = particle.GetComponent <ParticleController>();
                        particleController.Creator    = GameObj;
                        particleController.Generation = Generation + 1;
                        particleController.Speed      = -particleController.Speed;

                        Scene.Current.AddObject(particle);
                    }
                }
                else
                {
                    //Scene.Current.RemoveObject(GameObj);
                }
            }
        }
Ejemplo n.º 2
0
        void ICmpUpdatable.OnUpdate()
        {
            cameraTransform.MoveTo(GameObj.Transform.Pos + cameraOffset);
            cameraTransform.Angle = GameObj.Transform.Angle;
            RigidBody body = this.GameObj.GetComponent <RigidBody>();

            if (DualityApp.Keyboard[Key.Left])
            {
                body.ApplyLocalForce(-0.001f * body.Inertia);
            }
            else if (DualityApp.Keyboard[Key.Right])
            {
                body.ApplyLocalForce(0.001f * body.Inertia);
            }
            else
            {
                body.AngularVelocity -= body.AngularVelocity * 0.1f * Time.TimeMult;
            }

            if (DualityApp.Keyboard[Key.Up])
            {
                body.ApplyLocalForce(Vector2.UnitY * -0.2f * body.Mass);
            }
            else if (DualityApp.Keyboard[Key.Down])
            {
                body.ApplyLocalForce(Vector2.UnitY * 0.2f * body.Mass);
            }


            //code for bullets
            m_FiringDelayCounter += Time.TimeMult;
            if (DualityApp.Keyboard[Key.Space] && Particles != null &&
                m_FiringDelayCounter > FiringDelay)
            {
                for (int i = 0; i < 360; i += 10)
                {
                    m_FiringDelayCounter = 0;
                    Transform  transform = GameObj.GetComponent <Transform>();
                    GameObject particle  = Particles.Res.Instantiate(transform.Pos +
                                                                     transform.GetWorldVector(FiringOffset), transform.Angle + i);

                    ParticleController particleController = particle.GetComponent <ParticleController>();
                    particleController.Creator = GameObj;

                    Scene.Current.AddObject(particle);
                }
            }
        }
        void ICmpUpdatable.OnUpdate()
        {
            cameraTransform.MoveTo(GameObj.Transform.Pos + cameraOffset);
            cameraTransform.Angle = GameObj.Transform.Angle;
            RigidBody body = this.GameObj.GetComponent <RigidBody>();

            //pause sound code
            if (sonarSound.Sources.ElementAt(0).Paused == false && (Time.MainTimer.TotalSeconds - soundStart > 5.50))
            {
                sonarSound.Sources.ElementAt(0).Paused = true;
            }

            if (DualityApp.Keyboard[Key.Left])
            {
                body.ApplyLocalForce(-0.001f * body.Inertia);
            }
            else if (DualityApp.Keyboard[Key.Right])
            {
                body.ApplyLocalForce(0.001f * body.Inertia);
            }
            else
            {
                body.AngularVelocity -= body.AngularVelocity * 0.1f * Time.TimeMult;
            }

            if (DualityApp.Keyboard[Key.Up])
            {
                body.ApplyLocalForce(Vector2.UnitY * -0.2f * body.Mass);
            }
            else if (DualityApp.Keyboard[Key.Down])
            {
                body.ApplyLocalForce(Vector2.UnitY * 0.2f * body.Mass);
            }


            //code for bullets
            m_FiringDelayCounter += Time.TimeMult;
            if (DualityApp.Keyboard[Key.Space] && Particles != null &&
                m_FiringDelayCounter > FiringDelay)
            {
                for (int i = 0; i < 360; i += 10)
                {
                    m_FiringDelayCounter = 0;
                    Transform  transform = GameObj.GetComponent <Transform>();
                    GameObject particle  = Particles.Res.Instantiate(transform.Pos +
                                                                     transform.GetWorldVector(FiringOffset), transform.Angle + i);

                    ParticleController particleController = particle.GetComponent <ParticleController>();
                    particleController.Creator = GameObj;

                    //DualityApp.Sound.PlaySound(Sound.Beep);
                    if (sonarSound.Sources.ElementAt(0).Paused == true)
                    {
                        sonarSound.Sources.ElementAt(0).Paused = false;
                        soundStart = Time.MainTimer.TotalSeconds;
                    }

                    Scene.Current.AddObject(particle);
                }
            }

            //code for arrow
            Vector3 difference = arrow.GetLocalVector(finish.Pos) - arrow.Pos;
            //Log.Game.Write(difference.ToString());
            double angleDegrees = Math.Acos(difference.Y / difference.X);
            double angleRads    = (Math.PI / 180f) * angleDegrees;

            //Log.Game.Write("degrees: " + angleDegrees.ToString());
            Log.Game.Write("rads" + angleRads.ToString());
            if (!Double.IsNaN(angleRads))
            {
                arrow.Angle = (float)angleRads + (float)Math.PI;
            }
        }