예제 #1
0
        public virtual void checkContactWithPlayer()
        {
            cPlayer player = Scene.Player;

            float d = (float)cAppMath.Vec2Distance(player.Bounds.center, this.Bounds.center);

            if (d <= MAX_PULL_DISTANCE)
            {
                // pull pickup
                Vector2f toPlayer = cAppMath.Vec2NormalizeReturn(player.Bounds.center - this.Bounds.center);
                this.pulling = true;
                // G * ((m1*m2) / (d*d))
                float f = PULL_FORCE * (100000.0f / (d * d));
                this.AddForce(toPlayer * f);
            }
            else
            {
                this.pulling = false;
            }


            if (!pickedUp && cCollision.OverlapAABB(player.Bounds, this.HitCollisionRect))
            {
                player.pickUp(pickup);
                pickedUp = true;
            }
        }
예제 #2
0
        public virtual void checkContactWithPlayer()
        {
            cPlayer player = Scene.Player;

            float d = (float)AppMath.Vec2Distance(player.Bounds.center, this.Bounds.center);

            if (!this.pulling)
            {
                this.pulling = d <= MAX_PULL_DISTANCE;
            }

            if (!pickedUp && cCollision.OverlapAABB(player.Bounds, this.HitCollisionRect))
            {
                player.pickUp(pickup);
                pickedUp = true;
            }
        }
예제 #3
0
 public void attemptMeleeAttack(cPlayer player)
 {
     if (cCollision.OverlapAABB(this.hitCollisionRect, player.HitCollisionRect))
     {
         if (!attacking)
         {
             this.attacking = true;
         }
         else
         {
             if (attackCharger.isReady())
             {
                 player.MeleeHit(1, this);
             }
         }
     }
     else
     {
         this.attacking = false;
     }
 }
예제 #4
0
        public override void Update(float step_time)
        {
            this.renderer.Update(step_time);

            cPlayer player = Scene.Player;

            if (this.pulling)
            {
                Vector2f predicted = AppMath.Vec2NormalizeReturn((player.Bounds.center + (player.Velocity * step_time)) - this.Bounds.center);
                // pull pickup
                //Vector2f toPlayer = cAppMath.Vec2NormalizeReturn(player.Bounds.center - this.Bounds.center);

                // G * ((m1*m2) / (d*d))
                float f = PULL_FORCE * 150f; // * (100000.0f / ( d*d) );
                this.AddForce(predicted * f);
            }

            /*
             * else
             * {
             *  this.pulling = false;
             * }
             */

            // applying some gravity
            force.Y += (false == pulling) ? (Constants.GRAVITY * 40.0f * step_time) : 0.0f;

            velocity.X += force.X * step_time;
            velocity.Y += force.Y * step_time;

            //velocity.X = Math.Abs(velocity.X) < 0.05f ? 0.0f : velocity.X;
            //velocity.Y = Math.Abs(velocity.Y) < 0.05f ? 0.0f : velocity.Y;

            double len = AppMath.Vec2Length(velocity);

            if (len < 0.1)
            {
                velocity = new Vector2f(0.0f, 0.0f);
            }

            AppMath.Vec2Truncate(ref velocity, MaxSpeed);

            // get more precise result calling it here (because of the updated velocity)
            // instead of calling at the beginning of this update method
            checkCollisionWithWorld(step_time);

            lastPosition = position;
            position.X  += velocity.X * step_time;
            position.Y  += velocity.Y * step_time;

            Bounds.SetPosByCenter(position);
            this.hitCollisionRect = Bounds;

            if (!AppMath.Vec2IsZero(velocity))
            {
                heading     = AppMath.Vec2NormalizeReturn(velocity);
                orientation = AppMath.GetAngleOfVector(heading);
            }

            force = new Vector2f(0.0f, 0.0f);
        }
예제 #5
0
 public GameObjectGrid(GameScene scene, Vector2f world_size, cPlayer player) : base(world_size)
 {
     this.refScene   = scene;
     this.player     = player;
     visibleEntities = new List <cGameObject>();
 }