Пример #1
0
        public override void Update(double time)
        {
            if (GunStowTimer.Elapsed.TotalSeconds > 0.25)
            {
                GunStowTimer.Reset();
                WieldingGun = false;

                //Henry: this is right after the gun is shot, so throw the bullet then.

                // TODO: Un-hard-code this:
                Vector2d bullet_velo =
                    new Vector2d(TileX * Math.Cos(_AimAngle), Math.Sin(_AimAngle));
                //bullet_velo.Normalize();

                bullet_velo.Y *= _AnimationCurrent == AnimationAimGunFwdCrouch ? 0.0 : 1.0;
                bullet_velo   *= 300;

                //Henry: made it so the bullet was lower & closer to player
                double shot_offset_x = (SizeX + 3) * TileX * 0.15;
                double shot_offset_y = SizeY * (Crouching ? -0.1 :
                                                _AnimationCurrent == AnimationAimGunFwdDown ? -0.4 :
                                                _AnimationCurrent == AnimationAimGunFwdUp ? 0.8 : 0.25) - 16;

                Sound.Play("sfx_shoot_gun");
                var bullet = new BasicBullet(this._RenderSet.Scene,
                                             this.PositionX + shot_offset_x,
                                             this.PositionY + shot_offset_y,
                                             bullet_velo.X, bullet_velo.Y);
            }
            if (Crouching)
            {
                FixtureUpper.CollisionCategories = Category.None;
                FixtureLower.CollisionCategories = Category.Cat1;
            }
            else
            {
                FixtureUpper.CollisionCategories = Category.Cat1;
            }
            //Body.LinearVelocity /= Math.Max(Body.LinearVelocity.Length() / (10f * (float)Configuration.MeterInPixels), 1.0f);
            Body.LinearDamping = 0.5f;
            base.Update(time);
            bool going_down = Body.LinearVelocity.Y < 0.01f;

            if (going_down && !GoneDown)   // Inflection
            // This is here because sometimes collision event isn't raised
            {
                lock (_RenderSet.Scene.Game.UpdateLock) // Paranoid
                    BodyPlatformRayCast(PlatformCollisionRaycast);
            }
            GoneDown = going_down;
            //((BooleanIndicator)Program.MainGame.TestIndicators[0]).State = GoneDown;
        }
Пример #2
0
        public bool KeyUp(object sender, KeyboardKeyEventArgs e)
        {
            if (e.Key == Configuration.KeyUseEquippedItem && _WieldingGun) {
                UpdateEventHandler late;
                late = (u_sender, u_e) =>
                {
                    // TODO: Un-hard-code this:
                    Vector2d bullet_velo =
                        new Vector2d(TileX * Math.Cos(_AimAngle), Math.Sin (_AimAngle));
                    //bullet_velo.Normalize();

                    bullet_velo.Y *= _AnimationCurrent == AnimationAimGunFwdCrouch ? 0.0 : 1.0;
                    bullet_velo *= 1000;

                    double shot_offset_x = (SizeX + 3) * TileX;
                    double shot_offset_y = SizeY * (Crouching ? -0.1 :
                        _AnimationCurrent == AnimationAimGunFwdDown ? -0.4 :
                        _AnimationCurrent == AnimationAimGunFwdUp ? 0.8 : 0.25);

                    var bullet = new BasicBullet (this._RenderSet.Scene,
                                                 this.PositionX + shot_offset_x,
                                                  this.PositionY + shot_offset_y,
                                                  bullet_velo.X, bullet_velo.Y);
                    GunStowTimer.Restart ();
                    return true;
                };
                Program.MainGame.AddUpdateEventHandler (this, late);
            } else if (e.Key == Configuration.KeyDown) {
                _WouldCrouch = false;
            }
            return true;
        }