Exemplo n.º 1
0
 public Creature(CreatureStats stats,
     string allies,
     PlanService planService,
     Faction faction,
     Physics parent,
     ChunkManager chunks,
     GraphicsDevice graphics,
     ContentManager content,
     string name)
     : base(parent.Manager, name, parent, stats.MaxHealth, 0.0f, stats.MaxHealth)
 {
     Buffs = new List<Buff>();
     IsOnGround = true;
     Physics = parent;
     Stats = stats;
     Chunks = chunks;
     Graphics = graphics;
     Content = content;
     Faction = faction;
     PlanService = planService;
     Allies = allies;
     Controller = new PIDController(Stats.MaxAcceleration, Stats.StoppingForce * 2, 0.0f);
     JumpTimer = new Timer(0.2f, true);
     Status = new CreatureStatus();
     IsHeadClear = true;
     NoiseMaker = new NoiseMaker();
     OverrideCharacterMode = false;
     SelectionCircle = new SelectionCircle(Manager, Physics)
     {
         IsVisible = false
     };
 }
Exemplo n.º 2
0
 public Snake(string sprites, Vector3 position, ComponentManager manager, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, string name)
     : base(new CreatureStats
         {
             Dexterity = 12,
             Constitution = 6,
             Strength = 3,
             Wisdom = 2,
             Charisma = 1,
             Intelligence = 3,
             Size = 3
         },
         "Herbivore",
         PlayState.PlanService,
         manager.Factions.Factions["Herbivore"],
         new Physics
         (
             "snake",
             manager.RootComponent,
             Matrix.CreateTranslation(position),
             new Vector3(1, .3f, .5f),
             new Vector3(0, 0, 0),
             1.0f, 1.0f, 0.999f, 0.999f,
             new Vector3(0, -10, 0)
         ),
         chunks, graphics, content, name)
 {
     Tail = new Physics[5];
     for (int i = 0; i < 5; ++i)
     {
         Tail[i] = new Physics
         (
             "snaketail",
             manager.RootComponent,
             Matrix.CreateTranslation(position),
             new Vector3(2, 1.5f, .7f),
             new Vector3(0, 0, 0),
             1.0f, 1.0f, 0.995f, 0.999f,
             new Vector3(0, -10, 0)
         );
     }
     Initialize(new SpriteSheet(sprites));
 }
Exemplo n.º 3
0
        private void WalkUpdate(DwarfTime time, ChunkManager chunks)
        {
            MouseState mouse = Mouse.GetState();
            KeyboardState keys = Keyboard.GetState();

            if (PhysicsObject == null)
            {
                PhysicsObject = new Physics("CameraPhysics", PlayState.ComponentManager.RootComponent, Matrix.CreateTranslation(Target), new Vector3(0.5f, 0.5f, 0.5f), Vector3.Zero, 1.0f, 1.0f, 0.999f, 1.0f, Vector3.Down * 10);
                PhysicsObject.IsSleeping = false;
                PhysicsObject.Velocity = Vector3.Down*0.01f;
            }

            bool stateChanged = false;
            float dt = (float)time.ElapsedGameTime.TotalSeconds;

            if (KeyManager.RotationEnabled())
            {
                if (!shiftPressed)
                {
                    shiftPressed = true;

                    mouse = Mouse.GetState();
                    stateChanged = true;
                }
                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                    stateChanged = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                    stateChanged = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }

                if (stateChanged)
                {
                    Mouse.SetPosition(GameState.Game.GraphicsDevice.Viewport.Width / 2, GameState.Game.GraphicsDevice.Viewport.Height / 2);
                    mouse = Mouse.GetState();
                }

                float diffX = mouse.X - GameState.Game.GraphicsDevice.Viewport.Width / 2;
                float diffY = mouse.Y - GameState.Game.GraphicsDevice.Viewport.Height / 2;

                float filterDiffX = (float)(diffX * dt);
                float filterDiffY = (float)(diffY * dt);
                if (Math.Abs(filterDiffX) > 1.0f)
                {
                    filterDiffX = 1.0f * Math.Sign(filterDiffX);
                }

                if (Math.Abs(filterDiffY) > 1.0f)
                {
                    filterDiffY = 1.0f * Math.Sign(filterDiffY);
                }

                targetTheta = Theta - (filterDiffX);
                targetPhi = Phi - (filterDiffY);
                Theta = targetTheta * 0.5f + Theta * 0.5f;
                Phi = targetPhi * 0.5f + Phi * 0.5f;

                if (Phi < -1.5f)
                {
                    Phi = -1.5f;
                }
                else if (Phi > 1.5f)
                {
                    Phi = 1.5f;
                }
            }
            else
            {
                shiftPressed = false;
            }

            Vector3 velocityToSet = Vector3.Zero;
            if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();

                velocityToSet += forward * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                velocityToSet += -forward * CameraMoveSpeed * dt;
            }

            if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                velocityToSet += -right * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                velocityToSet += right * CameraMoveSpeed * dt;
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                Velocity = Velocity * 0.5f + velocityToSet * 0.5f;
            }

            LastWheel = mouse.ScrollWheelValue;

            Velocity = new Vector3(Velocity.X, 0, Velocity.Z);

            if (keys.IsKeyDown(Keys.Space))
            {
                Velocity += Vector3.Up;
            }

            //CollidesWithChunks(PlayState.ChunkManager, Target, true);
            PhysicsObject.ApplyForce(Velocity * 20, dt);

            Target = PhysicsObject.GlobalTransform.Translation + Vector3.Up * 0.5f;
            Velocity *= 0.8f;
            UpdateBasisVectors();
        }