public override void Update(GameTime gameTime) { selectedSize.Update(Game.Instance.GlobalClock.ContinuousMilliseconds); unselectedSize.Update(Game.Instance.GlobalClock.ContinuousMilliseconds); double at = gameTime.TotalGameTime.TotalMilliseconds; GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); KeyboardState keyboardState = Keyboard.GetState(); if (at > menu.buttonPressedAt + Menu.ButtonRepeatTimeout) { if ((gamePadState.Buttons.A == ButtonState.Pressed && menu.lastGPState.Buttons.A == ButtonState.Released) || (keyboardState.IsKeyDown(Keys.Enter) && menu.lastKBState.IsKeyUp(Keys.Enter))) { SelectedItem.PerformAction(); menu.buttonPressedAt = at; } } base.Update(gameTime); }
public override void Update(GameTime gameTime) { double at = gameTime.TotalGameTime.TotalMilliseconds; playerBoxSize.Update(at); if (at > menu.buttonPressedAt + Menu.ButtonRepeatTimeout && ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed && menu.lastGPState.Buttons.A == ButtonState.Released) || GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || (Keyboard.GetState().IsKeyDown(Keys.Enter) && menu.lastKBState.IsKeyUp(Keys.Enter)))) { List <Entity> players = new List <Entity>(MaxPlayers); for (int i = 0; i < MaxPlayers; i++) { if (playerActive[i]) { Entity player = new Entity("player" + (players.Count + 1)); player.AddIntAttribute(CommonNames.GamePadIndex, i); player.AddStringAttribute("robot_entity", Game.Instance.Robots[robotSelected[i]].Entity); player.AddStringAttribute(CommonNames.PlayerName, Game.Instance.Robots[robotSelected[i]].Name); players.Add(player); } } Game.Instance.AddPlayers(players.ToArray <Entity>()); menu.Close(); return; } for (int i = 0; i < MaxPlayers; i++) { GamePadState gamePadState = GamePad.GetState((PlayerIndex)i); if (i > 0 && // don't allow player1 do deactivate gamePadState.Buttons.Start == ButtonState.Pressed && previousState[i].Buttons.Start == ButtonState.Released && at > playerButtonPressedAt[i] + Menu.ButtonRepeatTimeout) { playerActive[i] = !playerActive[i]; playerButtonPressedAt[i] = at; } if (at > menu.elementSelectedAt + Menu.StickRepeatTimeout) { int oldRobotSelected = robotSelected[i]; if (Vector2.Dot(gamePadState.ThumbSticks.Left, Vector2.UnitY) > Menu.StickDirectionSelectionMin || gamePadState.DPad.Up == ButtonState.Pressed) { // select prev robot robotSelected[i]--; if (robotSelected[i] < 0) { robotSelected[i] = Game.Instance.Robots.Count - 1; } menu.elementSelectedAt = at; } else if (Vector2.Dot(gamePadState.ThumbSticks.Left, Vector2.UnitY) < -Menu.StickDirectionSelectionMin || gamePadState.DPad.Down == ButtonState.Pressed) { // select next robot robotSelected[i]++; if (robotSelected[i] == Game.Instance.Robots.Count) { robotSelected[i] = 0; } menu.elementSelectedAt = at; } for (int j = 0; j < MaxPlayers; ++j) { if (robotSelected[j] == robotSelected[i] && i != j) { if (playerActive[j]) { robotSelected[i] = oldRobotSelected; } else { robotSelected[j] = oldRobotSelected; } } } } previousState[i] = gamePadState; } for (int i = 0; i < MaxPlayers; ++i) { // load templates LevelData levelData = Game.Instance.ContentManager.Load <LevelData>("Level/Common/RobotTemplates"); EntityData entityData = levelData.entities[Game.Instance.Robots[robotSelected[i]].Entity]; List <AttributeData> attributes = entityData.CollectAttributes(levelData); List <PropertyData> properties = entityData.CollectProperties(levelData); // create a dummy entity Entity entity = new Entity(entityData.name); foreach (AttributeData attributeData in attributes) { entity.AddAttribute(attributeData.name, attributeData.template, attributeData.value); } Vector3 color1 = entity.GetVector3(CommonNames.Color1); Vector3 color2 = entity.GetVector3(CommonNames.Color2); RenderTargetBinding[] oldRenderTarget = Game.Instance.GraphicsDevice.GetRenderTargets(); Game.Instance.GraphicsDevice.SetRenderTargets(playerPreview[i]); Game.Instance.GraphicsDevice.Clear(new Color(0, 0, 0, 0)); ////////playerModel.Meshes[0].Draw(); playerMesh.Effects[0].CurrentTechnique = playerMesh.Effects[0].Techniques["AnimatedPlayer"]; playerMesh.Effects[0].Parameters["Local"].SetValue(Matrix.Identity); playerMesh.Effects[0].Parameters["World"].SetValue(Matrix.Identity * 0.8f); playerMesh.Effects[0].Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(3, 3, 3), new Vector3(0, 2.0f, -3), Vector3.Up)); ////////playerMesh.Effects[0].Parameters["View"].SetValue(Matrix.CreateLookAt(new); playerMesh.Effects[0].Parameters["Projection"].SetValue(Matrix.CreateOrthographic(8.5f, 8.5f, 0.001f, 1000) * Matrix.CreateTranslation(Vector3.UnitX * 0.36f)); playerMesh.Effects[0].Parameters["DiffuseTexture"].SetValue(playerTexture); playerMesh.Effects[0].Parameters["SpecularTexture"].SetValue(specularTexture); playerMesh.Effects[0].Parameters["DiffuseColor"].SetValue(Vector3.One * 1.0f); playerMesh.Effects[0].Parameters["SpecularColor"].SetValue(Vector3.One); playerMesh.Effects[0].Parameters["SpecularPower"].SetValue(16f); playerMesh.Effects[0].Parameters["EmissiveColor"].SetValue(Vector3.One * 0.2f); playerMesh.Effects[0].Parameters["ToneColor"].SetValue(entity.GetVector3(CommonNames.Color1)); playerMesh.Effects[0].Parameters["DirLight0Direction"].SetValue(-Vector3.One); playerMesh.Effects[0].Parameters["DirLight0DiffuseColor"].SetValue(entity.GetVector3(CommonNames.Color1) * 0.5f); playerMesh.Effects[0].Parameters["DirLight0SpecularColor"].SetValue(Vector3.One / 3); playerMesh.Effects[0].Parameters["DirLight1Direction"].SetValue(new Vector3(-1, 1, -1)); playerMesh.Effects[0].Parameters["DirLight1DiffuseColor"].SetValue(new Vector3(1, 1, 1) * 0.75f); playerMesh.Effects[0].Parameters["DirLight1SpecularColor"].SetValue(Vector3.One / 3); playerMesh.Effects[0].Parameters["DirLight2Direction"].SetValue(new Vector3(-1, -1, 1)); playerMesh.Effects[0].Parameters["DirLight2DiffuseColor"].SetValue(entity.GetVector3(CommonNames.Color2) * 0.75f); playerMesh.Effects[0].Parameters["DirLight2SpecularColor"].SetValue(Vector3.One / 3); Viewport oldViewport = Game.Instance.GraphicsDevice.Viewport; double now = Game.Instance.GlobalClock.ContinuousMilliseconds; GameTime myGameTime = new GameTime( new TimeSpan((long)(now * 10000d)), new TimeSpan((long)((now - last) * 10000d)) /*, * new TimeSpan((long)(now * 10000d)), * new TimeSpan((long)((now - last) * 10000d))*/); last = now; animator.World = Matrix.Identity; walkController.Update(myGameTime); animator.Update(); animator.Draw(); playerMesh.Draw(); Game.Instance.GraphicsDevice.SetRenderTargets(oldRenderTarget); } }