예제 #1
0
        public void collideParticleRayTrace(Particle p, float step_time, bool drag = true, bool killZero = true)
        {
            Vector2i posA              = new Vector2i((int)p.LastPos.X, (int)p.LastPos.Y);
            Vector2i posB              = new Vector2i((int)p.Pos.X, (int)p.Pos.Y);
            bool     collided          = false;
            Vector2f intersectionPoint = new Vector2f(0.0f, 0.0f);

            AppMath.Raytrace(posA.X, posA.Y, posB.X, posB.Y,
                             (x, y) =>
            {
                collided = this.IsObastacleAtPos(new Vector2f(x, y));
                if (collided)
                {
                    intersectionPoint.X = x;
                    intersectionPoint.Y = y;

                    p.Pos     = intersectionPoint;
                    p.LastPos = p.Pos;
                    //if we want to drag to the wall:

                    if (drag)
                    {
                        p.Vel.X = 0.0f;
                        p.Vel.Y = 0.0f;
                    }

                    p.Intersects = true;

                    p.Life = killZero ? 0.0f : p.Life;
                }

                return(collided);
            }
                             );
        }
예제 #2
0
        public bool checkCollisionWithWorld(cWorld world, ref Vector2f intersectionOut)
        {
            Vector2i posA     = new Vector2i((int)this.lastPosition.X, (int)this.lastPosition.Y); //world.ToMapPos(this.lastPosition);
            Vector2i posB     = new Vector2i((int)this.position.X, (int)this.position.Y);         // world.ToMapPos(this.Position);
            bool     collided = false;

            Vector2f intersectionPoint = new Vector2f(0.0f, 0.0f);

            AppMath.Raytrace(posA.X, posA.Y, posB.X, posB.Y,
                             (x, y) =>
            {
                collided = world.IsWallAtPos(new Vector2f(x, y)); //world.GetCurrentLevel.IsObstacleAtPos(x, y);

                intersectionPoint.X = x;                          // = world.ToWorldPos(new Vector2i(x, y));
                intersectionPoint.Y = y;


                return(collided);
            }
                             );

            intersectionOut.X = intersectionPoint.X;
            intersectionOut.Y = intersectionPoint.Y;
            return(collided);
        }
예제 #3
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);
        }