Exemple #1
0
        private cMonster getclosestMonsterColliding(IEnumerable <cMonster> possibleColliders, cBullet bul, Vector2f pos_by, float time)
        {
            // int index = -1;
            double   prevDist = Double.MaxValue;
            double   newDist  = 0.0;
            cMonster returner = null;

            foreach (var mon in possibleColliders)
            {
                if (mon.IsKilled)
                {
                    continue;
                }

                // order by distance to find the closest
                if (cSatCollision.checkAndResolve(bul, mon, time, false))
                {
                    newDist = AppMath.Vec2DistanceSqrt(mon.Bounds.center, pos_by);

                    if (newDist < prevDist)
                    {
                        prevDist = newDist;
                        returner = mon;
                    }
                }
            }

            return(returner);
        }
Exemple #2
0
        public override void Update(float step_time)
        {
            this.Marked = false;

            Vector2f playerCenter      = this.Scene.Player.Bounds.center;
            double   sqrDistFromPlayer = AppMath.Vec2DistanceSqrt(playerCenter, this.Bounds.center);

            Vector2i posA = new Vector2i((int)this.Bounds.center.X, (int)this.Bounds.center.Y);
            Vector2i posB = new Vector2i((int)this.Scene.Player.Bounds.center.X, (int)this.Scene.Player.Bounds.center.Y);
            bool     playerHiddenForMe = true;
            Vector2f intersectionPoint = new Vector2f(0.0f, 0.0f);



            if (sqrDistFromPlayer <= 80000.0) // 100 unit distance  1000000.0
            {
                AppMath.Raytrace(posA.X, posA.Y, posB.X, posB.Y,
                                 (x, y) =>
                {
                    playerHiddenForMe = this.pscene.World.IsObastacleAtPos(new Vector2f(x, y));

                    return(playerHiddenForMe);
                }

                                 );

                //this.wake();



                if (playerHiddenForMe == false)
                {
                    this.wake();

                    if (playerCenter.X > this.Position.X)
                    {
                        if (velocity.X < 0.0f)
                        {
                            this.StopMovingX();
                        }
                        this.StartMovingRight();
                    }

                    if (playerCenter.X < this.Position.X)
                    {
                        if (velocity.X > 0.0f)
                        {
                            this.StopMovingX();
                        }
                        this.StartMovingLeft();
                    }
                }

                if (attacking)
                {
                    this.StopMoving();
                }


                /*
                 * if (this.Scene.Player.Bounds.topLeft.Y < this.Bounds.topLeft.Y)
                 *  this.StartJumping();
                 * else
                 *  this.StopJumping();
                 */
            }
            else
            {
                this.StopMoving();
                this.sleep();
            }

            this.spriteControl.Update(this.GetSpriteState());


            base.updateMovement(step_time);

            //base.Update(step_time);
        }