示例#1
0
文件: Arrow.cs 项目: pquinn/time-sink
        public void Fire(UserControlledCharacter character, EngineGame world, GameTime gameTime, double holdTime, bool charged)
        {
            Arrow arrow = new Arrow(
                new Vector2(character.Physics.Position.X,// + UserControlledCharacter.X_OFFSET,
                            character.Physics.Position.Y + UserControlledCharacter.Y_OFFSET));

            world.LevelManager.RegisterEntity(arrow);

            character.InHold = false;

            var elapsedTime = Math.Min(gameTime.TotalGameTime.TotalSeconds - holdTime, MAX_ARROW_HOLD);
            // linear interp: y = 500 + (x - 0)(1300 - 500)/(MAX_HOLD-0) x = elapsedTime
            float speed =
                MIN_ARROW_INIT_SPEED + (MAX_ARROW_INIT_SPEED - MIN_ARROW_INIT_SPEED) /
                                       MAX_ARROW_HOLD *
                                       (float)elapsedTime;

            Vector2 initialVelocity = PhysicsConstants.PixelsToMeters(speed * character.Direction);
            if (character.Direction.Y == 0)
            {
                var rotation = (float)Math.PI / 32;
                rotation *= character.Direction.X > 0
                    ? -1
                    : 1;
                initialVelocity = Vector2.Transform(initialVelocity, Matrix.CreateRotationZ(rotation));
                arrow.Physics.Rotation = rotation;
            }
            arrow.Physics.LinearVelocity += initialVelocity;
        }
示例#2
0
文件: Enemy.cs 项目: pquinn/time-sink
 protected virtual bool OnCollidedWith(Fixture f, Arrow arrow, Fixture af, Contact info)
 {
     health -= 100;
     return true;
 }