Ejemplo n.º 1
0
 private void collisionTest()
 {
     if (eventHandlerCount > 0)
     {
         foreach (AttackedCollisionGroup attackedGroup in attackedGroups)
         {
             if (attackedGroup.nEntityID != nAttackEntityID)
             {
                 //Trace.Log("collisionTest!");
                 Vector3 collisionPos = Vector3.zero;
                 if (true == CollisionDetection.collisionDetection(this, attackedGroup, ref collisionPos))
                 {
                     Trace.Log("Hit!");
                     CollisionArgs args = new CollisionArgs();
                     args.type              = CollisionArgType.CollisionDetected;
                     args.nAttackEntityID   = nAttackEntityID;
                     args.nAttackedEntityID = attackedGroup.nEntityID;
                     args.nFeedBackID       = nFeedBackID;
                     args.collisionPos      = collisionPos;
                     collisionEvent(this, args);
                     bEnableCollision = false;
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    private void HandleCollisionEvent(object sender, CollisionArgs e)
    {
        Bullet bullet = (Bullet)sender;

        switch (e.Tag)
        {
        case Tags.NONE:
            audioPlayer.Play(bullet.Audio, Sounds.STRAY, 1f, -0.25f);
            break;

        case Tags.GROUND:
            audioPlayer.Play(bullet.Audio, Sounds.GROUND_IMPACT, 1f, -0.25f);
            break;

        case Tags.ROBOT:
            bullet.Sparks1.Play();
            audioPlayer.Play(bullet.Audio, Sounds.LIGHT_IMPACT, 1f, -0.25f);
            break;

        case Tags.OBSTACLE:
        case Tags.WALL:
            bullet.Sparks2.Play();
            audioPlayer.Play(bullet.Audio, Sounds.GROUND_IMPACT, 1f, -0.25f);
            break;
        }
    }
Ejemplo n.º 3
0
        private void LoadZone_LoadMap(object sender, CollisionArgs e)
        {
            var collider = (Collider)sender;
            var ent      = (Entity)collider.Entity;

            LoadMap("maps/testmap/", ent.Properties.GetPropertyValue("Map"));

            // Find the target spawn of the loadzone.
            string targetSpawnName = ent.Properties.GetPropertyValue("TargetSpawn");
            bool   set             = false;

            foreach (var o in engine.entities)
            {
                if (o.type == "Spawn" && o.name == targetSpawnName)
                {
                    // Set position to target position of loadingzone.
                    var p_coll = player.GetComponent <Collider>();
                    // Vector2.UnitX because we want to center X only.
                    p_coll.SetPosition((o.pos - (player.size / 2) * Vector2.UnitX));

                    Console.WriteLine("Player position set to: " + o.pos);
                    set = true;
                    break;
                }

                if (set)
                {
                    break;
                }
            }
        }
 void playerController_OnFirstContactBegin(object sender, CollisionArgs e)
 {
     // Stop if we collide from sides
     if (e.Contact.Normal.X < -0.5f || e.Contact.Normal.X > 0.5f)
     {
         movingToTarget = false;
     }
 }
Ejemplo n.º 5
0
    protected virtual void OnRaiseCollisionEvent(CollisionArgs e)
    {
        EventHandler <CollisionArgs> handler = RaiseCollisionEvent;

        if (handler != null)
        {
            handler(this, e);
        }
    }
Ejemplo n.º 6
0
 private void HandleCollisionEvent(object sender, CollisionArgs e)
 {
     if (!isPlayingStepSound &&
         veloSqrMag > 16f &&
         (e.Tag == Tags.GROUND || e.Tag == Tags.OBSTACLE))
     {
         StartCoroutine(PlayStepSoundCR());
     }
 }
Ejemplo n.º 7
0
    private void OnRaiseCollisionEvent(CollisionArgs e)
    {
        EventHandler <CollisionArgs> handler = RaiseCollisionEvent;

        if (handler != null)
        {
            handler(this, e);
        }
    }
Ejemplo n.º 8
0
 public void OnDestroy()
 {
     if (eventHandlerCount > 0)
     {
         Trace.Log("ResNode.DestroyRes!");
         CollisionArgs args = new CollisionArgs();
         args.type = CollisionArgType.CollisionDestroy;
         collisionEvent(this, args);
     }
 }
Ejemplo n.º 9
0
        public override void OnCollision(object sender, CollisionArgs collisionArgs)
        {
            if (collisionArgs.Box == null)
            {
                LevelManager.RestartLevel();
                return;
            }

            var data = collisionArgs.Box.Data;

            if (data is Block block)
            {
                switch (block.Type)
                {
                case BlockType.Spike:
                    LevelManager.RestartLevel();
                    break;

                case BlockType.Goal:
                    isPaused = true;
                    MediaPlayer.Play(Assets.Victory);
                    MediaPlayer.MediaStateChanged += MediaStateChanged;
                    return;
                }
            }

            var side = collisionArgs.Side;

            if (side.HasFlag(Side.Top) ||
                side.HasFlag(Side.Bottom))
            {
                movement.Y = 0.0f;
                isJumping  = false;
            }

            if (side.HasFlag(Side.Bottom))
            {
                isOnGround = true;
            }

            if (side.HasFlag(Side.Left) ||
                side.HasFlag(Side.Right))
            {
                movement.X = 0.0f;
            }

            if (side.HasFlag(Side.Right) ||
                side.HasFlag(Side.Left) ||
                side.HasFlag(Side.Top))
            {
                isAlive = false;
            }
        }
Ejemplo n.º 10
0
        private void GetPushed(object sender, CollisionArgs e)
        {
            if (e.Side == COLLISION_SIDE.Left)
            {
                this.Entity.pos.X += 1;
            }
            else if (e.Side == COLLISION_SIDE.Right)
            {
                this.Entity.pos.X -= 1;
            }

            this.Update(0.16f);
        }
Ejemplo n.º 11
0
    private void HandleCollisionEvent(object sender, CollisionArgs e)
    {
        Block block = (Block)sender;

        if (e.Tag == Tags.CLEAR)
        {
            block.Drop();
        }
        else if (e.Tag == Tags.GROUND)
        {
            audioPlayer.Play(block.Audio, Sounds.BLOCK,
                             e.Collision.relativeVelocity.magnitude / 15f); // TBD: velocity -> volume
        }
    }
Ejemplo n.º 12
0
            public void SetUp()
            {
                //arrange
                uut = new CollisionDetector(new CollisionCollection());

                receivedArgs            = null;
                numberOfCollisionEvents = 0;

                uut.NewCollision += (s, a) =>
                {
                    receivedArgs = a;
                    numberOfCollisionEvents++;
                };
            }
Ejemplo n.º 13
0
 private void OnBallCollision(object sender, CollisionArgs e)
 {
     if (e.CompareTag(Tags.GROUND))
     {
         if (ball.Velocity.magnitude < 7f)
         {
             // TBD
             Done();
         }
     }
     else if (e.CompareTag(Tags.OUT))
     {
         Done();
     }
 }
Ejemplo n.º 14
0
        public IEnumerator OnLaserCollision(CollisionArgs sender)
        {
            float force = 75 * sender.damage;

            Vector2 forceAngle = CalcObject.AngleToAddForce(sender.point, gameObject.transform.position, force
                                                            );

            body.AddForce(forceAngle);

            if (!scream.isPlaying)
            {
                float maxPan = 33;
                scream.panStereo = transform.position.x / maxPan;
                scream.Play();
            }
            yield return(null);
        }
Ejemplo n.º 15
0
        private void CheckCollision(object sender, CollisionArgs e)
        {
            if (death)
            {
                return;
            }

            if (e.Side == COLLISION_SIDE.Top)
            {
                //if( !physics.jumping)
                //{
                //    if (still)
                //    {
                //        spriteAnim.SetSprites(anim_still);
                //    }
                //}

                if (physics.isJumping)
                {
                    if (spriteAnim.Sprites.Equals(this.anim_jump))
                    {
                        spriteAnim.SetSprites(anim_still);
                    }
                    physics.isJumping = false;
                }
                else if (physics.isFalling)
                {
                    spriteAnim.SetSprites(anim_still);

                    physics.Land();
                }
            }
            //else if (e.Side == COLLISION_SIDE.Left)
            //{
            //    physics.vel = Vector2.Zero;
            //    still = true;
            //}
            //else if (e.Side == COLLISION_SIDE.Right)
            //{
            //    physics.vel = Vector2.Zero;
            //    still = true;
            //}
            //else if (e.Side == COLLISION_SIDE.Left)
            //{
            //}
        }
Ejemplo n.º 16
0
 public override void OnCollision(object sender, CollisionArgs collisionArgs)
 {
 }
        void bulletCollidedHandler(object sender, CollisionArgs e)
        {
            bullet.Collided -= new EventHandler<CollisionArgs>(bulletCollidedHandler);

            object scn = this.Scene.Find("Welt" + e.Collider.ID);
            if (e.Collider == scn)//level.GetType() == e.Collider.GetType())
            {
                if (this.Scene.SceneObjects.Contains(bullet))
                {

                    bulletInAir = false;
                    Scene.Remove(bullet);
                    cameraMovement.move(zeit, 3000, PosX1, level.getSpieler1Pos()); //TODO Kamera fahrt noch ändern
                }
            }
            if (e.Collider is Objekte)
            {
                ((Objekte)e.Collider).decreaseLP();
                Scene.Remove(bullet);
                cameraMovement.move(zeit, 3000, PosX1, level.getSpieler1Pos());//TODO Kamera fahr noch ändern
                bulletInAir = false;
            }
        }
Ejemplo n.º 18
0
        private void bulletCollidedHandler(object sender, CollisionArgs e)
        {
            bulletInAir = false;

            object scn = this.Scene.Find("Welt" + e.Collider.ID);
            if (e.Collider == scn)//level.GetType() == e.Collider.GetType())
            {
                if (this.Scene.SceneObjects.Contains(bullet))
                {
                    Scene.Remove(bullet);
                    bullet.Collided -= new EventHandler<CollisionArgs>(bulletCollidedHandler);

                    cameraMovement.move(zeit, 3000, PosX1, level.getSpieler1Pos()); //TODO Kamera fahrt noch ändern
                }
            }
            //TODO: Objektkollision

            if (e.Collider != scn)
            {
                Objektverwaltung.removeLP(e.Collider);

                Scene.Remove(bullet);
                cameraMovement.move(zeit, 3000, PosX1, level.getSpieler1Pos());//TODO Kamera fahr noch ändern
                bulletInAir = false;
            }
        }
Ejemplo n.º 19
0
 private void GetCollected(object sender, CollisionArgs e)
 {
     if (e.Side != COLLISION_SIDE.None)
     {
     }
 }
Ejemplo n.º 20
0
 public void OnCollided(CollisionArgs args)
 {
     Collided?.Invoke(this, args);
 }