Update() public method

public Update ( ) : void
return void
Esempio n. 1
0
        public void Update()
        {
            var spy = new ActionSpy();
            var a   = new Actor(null, null);

            a.AddAction(spy);
            Assert.AreEqual(0, spy.PerformedCount);
            Assert.IsFalse(spy.IsComplete);
            a.Update(Duration.Epsilon);
            Assert.AreEqual(1, spy.PerformedCount);
            Assert.IsTrue(spy.IsComplete);
            a.Update(Duration.Epsilon);
            Assert.AreEqual(1, spy.PerformedCount);
        }
        public void Add(ActorViewModel actorVm)
        {
            var moviesIds = actorVm.FilmographyIds;
            var actor     = new Actor();
            var movies    = new List <Movie>();

            actor.Update(actorVm);

            foreach (var movieId in moviesIds)
            {
                var movie = _repository.SearchForMovies(x => x.MovieId == movieId).First();
                movies.Add(movie);
            }

            if (movies.Any())
            {
                movies.ForEach(x => _repository.Add(new ActorMovie()
                {
                    Movie = x, Actor = actor
                }));
            }
            else
            {
                _repository.AddActor(actor);
            }
        }
Esempio n. 3
0
 public void Update(DeviceContext context, FrameUpdateParameters updateParameters)
 {
     menu.Update(context);
     renderModelRenderer.Update(updateParameters);
     iblEnvironment.Predraw(context);
     floor.Update(context);
     actor.Update(context, updateParameters, iblEnvironment);
 }
Esempio n. 4
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="time"></param>
        public void Update(GameTime time)
        {
            // Count the number of monster
            MonsterCount = 0;
            if (Monsters[0] != null)
            {
                MonsterCount++;
            }
            if (Monsters[1] != null)
            {
                MonsterCount++;
            }
            if (Monsters[2] != null)
            {
                MonsterCount++;
            }
            if (Monsters[3] != null)
            {
                MonsterCount++;
            }


            // Update monsters
            if (MonsterCount > 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    Monster monster = Monsters[i];
                    if (monster == null)
                    {
                        continue;
                    }


                    // Monster is dead
                    if (monster.IsDead)
                    {
                        monster.OnDeath();
                        Monsters[i] = null;
                    }
                    else
                    {
                        monster.Update(time);
                    }
                }
            }

            // Actor
            if (Actor != null)
            {
                Actor.Update(time);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            InputHandler.Update(gameTime);
            player.HandleInput(gameTime);
            player.Update(gameTime);
            effectsManager.Update(gameTime);
            eventManager.Update(gameTime);
            particleManager.Update(gameTime);
            base.Update(gameTime);
        }
Esempio n. 6
0
 // Update is called once per frame
 void Update()
 {
     // Wait for the user to input something.
     if (cycleTurns)
     {
         if (currentActor.Update())
         {
             cycleTurns = false;
         }
     }
     // Once the user has input something, move on to the next user.
     else
     {
         currentActor = actionCycle.Dequeue();
         actionCycle.Enqueue(currentActor);
         cycleTurns = true;
     }
 }
Esempio n. 7
0
        public void Update()
        {
            if (mActorSet == null)
            {
                return;
            }

            int actorCount = mActorSet.Count;
            int index      = 0;

            using (var enumerator = mActorSet.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    var cur = enumerator.Current;
                    var k   = cur.Key;

                    if (index >= mActorKeys.Count)
                    {
                        mActorKeys.Add(k);
                    }
                    else
                    {
                        mActorKeys[index] = k;
                    }
                    index++;
                }
            }

            for (int i = 0; i < actorCount; ++i)
            {
                Actor actor = null;
                if (mActorSet.TryGetValue(mActorKeys[i], out actor))
                {
                    if (actor != null && actor.NoUpdate == false)
                    {
                        actor.Update();
                        actor.LateUpdate();
                    }
                }
            }

            // 检查是否有因为正在加载模型而没有销毁的角色
            if (mRemoveWaitList.Count > 0)
            {
                // mRemoveWaitList 在迭代的过程中可能发生改变,因此需要添加到wait_actor_list中
                List <Actor> wait_actor_list = Pool <Actor> .List.New(mRemoveWaitList.Count);

                List <Actor> remove_actor_list = Pool <Actor> .List.New();

                foreach (var actor in mRemoveWaitList)
                {
                    wait_actor_list.Add(actor);
                }

                foreach (var actor in wait_actor_list)
                {
                    if (actor.mAvatarCtrl == null || actor.mAvatarCtrl.IsProcessingModel == false)
                    {
                        actor.Destroy();
                        remove_actor_list.Add(actor);
                    }
                }
                Pool <Actor> .List.Free(wait_actor_list);

                foreach (var actor in remove_actor_list)
                {
                    mRemoveWaitList.Remove(actor);
                }
                Pool <Actor> .List.Free(remove_actor_list);
            }
        }
Esempio n. 8
0
    void Update()
    {
        if (heroActor != null)
        {
            heroActor.Update(Time.deltaTime);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (navigation.area < navigation.lastArea)
            {
                navigation.EnableNextArea();
                areaGameObjects[navigation.area].SetActive(false);
            }
        }
        var miniCameraScale = miniCameraSize / Screen.height;
        var miniCameraZ     = miniMapSize - miniCameraSize;

        if (miniCameraTransform != null)
        {
            var miniCameraX = Screen.width * miniCameraScale;
            var position    = miniCameraTransform.position;
            if (position.x != miniCameraX || position.z != miniCameraZ)
            {
                position.x = miniCameraX;
                position.z = miniCameraZ;
                miniCameraTransform.position = position;
            }
        }
        var mouseTowardsActive = false;
        var mouseX             = Input.mousePosition.x;
        var mouseY             = Input.mousePosition.y;
        var x = mouseX * miniCameraScale * 2;
        var z = mouseY * miniCameraScale * 2 + miniCameraZ - miniCameraSize;

        if (x >= miniMinX && x <= miniMaxX && z >= miniMinZ && z <= miniMaxZ)
        {
            if (!mousePointTransform.gameObject.activeSelf)
            {
                mousePointTransform.gameObject.SetActive(true);
            }
            mousePointTransform.position = new Vector3(x, 50, z);
            if (heroActor != null)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    heroActor.AttackAt(x, z);
                }
            }
            var face = navigation.FindFaceAt(x, z);
            if (navigation.GetFaceWalkable(face))
            {
                var position = navigation.GetPosition(face, x, z);
                if (heroActor == null)
                {
                    mousePointMaterial.color = Color.cyan;
                    if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
                    {
                        heroActor = new Actor(position, 0);
                        heroActor.SetAvatar("yihu", 0, 0, 2);
                        heroActor.PlayAnimation("win");
                        cameraDistance = Vector3.Distance(heroActor.transform.position, cameraTransform.position);
                        cameraPosition = cameraTransform.position + cameraTransform.forward * cameraDistance;
                        cameraRotation = cameraTransform.eulerAngles;
                        if (navigation.area < navigation.lastArea)
                        {
                            navigation.EnableNextArea();
                            areaGameObjects[navigation.area].SetActive(false);
                        }
                    }
                }
                else
                {
                    if (navigation.FindShortestPath(heroActor.position, position))
                    {
                        mousePointMaterial.color = Color.green;
                    }
                    else
                    {
                        mousePointMaterial.color = Color.magenta;
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        heroActor.MoveTo(position);
                    }
                }
            }
            else
            {
                mousePointMaterial.color = Color.red;
            }
        }
        else
        {
            if (mousePointTransform.gameObject.activeSelf)
            {
                mousePointTransform.gameObject.SetActive(false);
            }
            if (heroActor != null)
            {
                var   ray   = cameraObject.ScreenPointToRay(Input.mousePosition);
                var   plane = new Plane(Vector3.up, heroActor.transform.position);
                float enter;
                if (plane.Raycast(ray, out enter))
                {
                    var position0 = heroActor.transform.position;
                    var position1 = ray.GetPoint(enter);
                    var deltaX    = position1.x - position0.x;
                    var deltaZ    = position1.z - position0.z;
                    if (deltaX != 0 || deltaZ != 0)
                    {
                        mouseTowardsActive = true;
                        mouseTowardsLine.SetPosition(0, position0);
                        mouseTowardsLine.SetPosition(1, position1);
                        var distance = Vector3.Distance(position0, position1);
                        var rotation = 90.0f - Mathf.Rad2Deg * Mathf.Atan2(deltaZ, deltaX);
                        if (Input.GetMouseButtonDown(0))
                        {
                            heroActor.MoveTowards(rotation, distance);
                        }
                        if (Input.GetMouseButtonDown(1))
                        {
                            heroActor.DashTowards(rotation, distance);
                        }
                    }
                }
            }
        }
        if (mouseTowardsLine.gameObject.activeSelf != mouseTowardsActive)
        {
            mouseTowardsLine.gameObject.SetActive(mouseTowardsActive);
        }
        if (heroActor != null)
        {
            if (Input.GetMouseButtonDown(2))
            {
                cameraDragEnabled = true;
                cameraDragMouseX  = mouseX;
                cameraDragMouseY  = mouseY;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                heroActor.SetAvatarBody(1);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                heroActor.SetAvatarBody(2);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                heroActor.SetAvatarBody(0);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                heroActor.SetAvatarWeapon(1);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                heroActor.SetAvatarWeapon(2);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                heroActor.SetAvatarWeapon(0);
            }
            var moveRotation = -1;
            if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
            {
                moveRotation = 45;
            }
            else if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.S))
            {
                moveRotation = 135;
            }
            else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A))
            {
                moveRotation = 225;
            }
            else if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.W))
            {
                moveRotation = 315;
            }
            else if (Input.GetKey(KeyCode.W))
            {
                moveRotation = 0;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                moveRotation = 90;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                moveRotation = 180;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                moveRotation = 270;
            }
            if (moveRotation >= 0)
            {
                heroActor.MoveTowards(moveRotation, heroActor.moveSpeed * 0.1f);
            }
        }
        if (cameraDragEnabled)
        {
            if (Input.GetMouseButton(2))
            {
                targetRotation.y += (mouseX - cameraDragMouseX) * 0.5f;
                targetRotation.x -= (mouseY - cameraDragMouseY) * 0.1f;
                if (targetRotation.x < 0)
                {
                    targetRotation.x = 0;
                }
                else if (targetRotation.x > 90)
                {
                    targetRotation.x = 90;
                }
                cameraDragMouseX = mouseX;
                cameraDragMouseY = mouseY;
            }
            else
            {
                cameraDragEnabled = false;
            }
        }
        if (Input.mouseScrollDelta.y < 0)
        {
            if (targetDistance < 50)
            {
                targetDistance++;
            }
        }
        else if (Input.mouseScrollDelta.y > 0)
        {
            if (targetDistance > 5)
            {
                targetDistance--;
            }
        }
        if (heroActor != null)
        {
            targetPosition = heroActor.transform.position;
            var dirtyRotation = cameraRotation != targetRotation;
            var dirtyPosition = cameraPosition != targetPosition;
            var dirtyDistance = cameraDistance != targetDistance;
            if (dirtyRotation)
            {
                var deltaRotation = targetRotation - cameraRotation;
                if (deltaRotation.sqrMagnitude > 1f)
                {
                    cameraRotation += deltaRotation * 0.2f;
                }
                else
                {
                    cameraRotation = targetRotation;
                }
                cameraTransform.eulerAngles = cameraRotation;
            }
            if (dirtyPosition)
            {
                var deltaPosition = targetPosition - cameraPosition;
                if (deltaPosition.sqrMagnitude > 0.1f)
                {
                    cameraPosition += deltaPosition * 0.2f;
                }
                else
                {
                    cameraPosition = targetPosition;
                }
            }
            if (dirtyDistance)
            {
                var deltaDistance = targetDistance - cameraDistance;
                if (deltaDistance < -0.1f || deltaDistance > 0.1f)
                {
                    cameraDistance += deltaDistance * 0.2f;
                }
                else
                {
                    cameraDistance = targetDistance;
                }
            }
            if (dirtyRotation || dirtyPosition || dirtyDistance)
            {
                cameraTransform.position = cameraPosition - cameraTransform.forward * cameraDistance;
            }
        }
    }
Esempio n. 9
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            physicsWorld.Step(gameTime, 5, 5);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
            for (int i = 0; i < actors.Count; i++)
            {
                if (!actors[i].IsValid())
                {
                    actors.RemoveAt(i);
                }
            }
            for (int i = 0; i < actors.Count; i++)
            {
                actors[i].HandleInput(Keyboard.GetState().GetPressedKeys());
                actors[i].Update(gameTime);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.OemPlus))
            {
                camPosition.Z += 0.1f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.OemMinus))
            {
                camPosition.Z -= 0.1f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                camPosition.X -= 0.1f;
                camTarget.X   -= 0.1f;
                //body.ApplyImpulse(new Vec2(-10.0f/physicsScaleX, 0.0f), body.GetLocalCenter());
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                camPosition.X += 0.1f;
                camTarget.X   += 0.1f;
                //body.ApplyImpulse(new Vec2(10.0f / physicsScaleX, 0.0f), body.GetLocalCenter());
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                camPosition.Y -= 0.1f;
                camTarget.Y   -= 0.1f;
                //body.ApplyImpulse(new Vec2(0.0f, -10.0f / physicsScaleY), body.GetLocalCenter());
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                camPosition.Y += 0.1f;
                camTarget.Y   += 0.1f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.OemTilde))
            {
                if (!tildePressed)
                {
                    console.ToggleVisibility();
                    //console.Draw(_desktop);
                    tildePressed = true;
                }
            }

            if (Keyboard.GetState().IsKeyUp(Keys.OemTilde))
            {
                tildePressed = false;
            }

            mouseDisplayActor.HandleInput(Keyboard.GetState().GetPressedKeys());
            mouseDisplayActor.Update(gameTime);

            //GetActorByName("player").location = new Vector3(body.GetPosition().X * physicsScaleX, body.GetPosition().Y * physicsScaleY, 0);
            //System.Diagnostics.Debug.WriteLine(new Vector3(body.GetPosition().X, body.GetPosition().Y, 0));
            if (GetActorByName("player") != null)
            {
                GetActorByName("player").GetMatrix();
                soundPlayer.Set3DListenerAttributes((GetActorByName("player") as Player).playerId, GetActorByName("player").location, new Vector3(0, 0, 0), GetActorByName("player").GetMatrix().Forward, GetActorByName("player").GetMatrix().Up);
                soundPlayer.Update(gameTime);
            }
            console.Update();
        }
Esempio n. 10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();
            GamePadState  currentGamepadState  = GamePad.GetState(PlayerIndex.One);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || currentKeyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;// difference in elapsed game time since last call

            switch (gameState)
            {
            case GameState.Menu:
                currentKeyboardState = Keyboard.GetState();

                if (currentKeyboardState.IsKeyDown(Keys.Enter))
                {
                    if (menuOption == MenuOption.Quit)
                    {
                        this.Exit();
                    }
                    else if (menuOption == MenuOption.Start)
                    {
                        gameState = GameState.Playing;
                    }
                }
                // move to the next option
                // doing modulus by the number of options lets us wrap back around to the first option
                // this also allows us to easily add / remove options later
                else if (currentKeyboardState.IsKeyDown(Keys.Up) &&
                         lastKeyboardState.IsKeyUp(Keys.Up))
                {
                    // up takes the absolute value in case it causes menuOption to go negative
                    menuOption = (MenuOption)Math.Abs((int)(menuOption - 1) % NUM_MENU_OPTIONS);
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Down) &&
                         lastKeyboardState.IsKeyUp(Keys.Down))
                {
                    menuOption = (MenuOption)((int)(menuOption + 1) % NUM_MENU_OPTIONS);
                }

                break;

            case GameState.Playing:
                //gamePadState = GamePad.GetState(bike.PlayerIndex);
                currentKeyboardState = Keyboard.GetState();

                for (int i = Actor.Actors.Count - 1; i >= 0; i--)
                {
                    Actor actor = Actor.Actors[i];
                    actor.Update(gameTime);

                    Bike bike = actor as Bike;
                    if (bike != null)
                    {
                        if (currentKeyboardState.IsKeyDown(GetKey(bike.PlayerIndex, Direction.Up)))
                        {
                            bike.ChangeDirection(Direction.Up);
                        }
                        else if (currentKeyboardState.IsKeyDown(GetKey(bike.PlayerIndex, Direction.Down)))
                        {
                            bike.ChangeDirection(Direction.Down);
                        }
                        else if (currentKeyboardState.IsKeyDown(GetKey(bike.PlayerIndex, Direction.Left)))
                        {
                            bike.ChangeDirection(Direction.Left);
                        }
                        else if (currentKeyboardState.IsKeyDown(GetKey(bike.PlayerIndex, Direction.Right)))
                        {
                            bike.ChangeDirection(Direction.Right);
                        }

                        //double speedRange = BikeStopThreshold - BikeMoveInterval;
                        //bike.MoveInterval = gamePadState.Triggers.Right * speedRange + BikeMoveInterval;
                    }
                }

                if (currentKeyboardState.IsKeyDown(Keys.P) &&
                    lastKeyboardState.IsKeyUp(Keys.P))
                {
                    gameState = GameState.Paused;
                }

                break;

            case GameState.Collision:
                currentKeyboardState = Keyboard.GetState();
                timeSinceCollision  += dt;

                if (timeSinceCollision < EXPLOSION_TIME)
                {
                    UpdateExplosions(dt);
                }

                // ENTER restarts the game
                if (currentKeyboardState.IsKeyDown(Keys.Enter))
                {
                    timeSinceCollision = 0f;
                    CreateScene();
                    gameState = GameState.Playing;
                }
                break;

            case GameState.Paused:
                currentKeyboardState = Keyboard.GetState();

                if (currentKeyboardState.IsKeyDown(Keys.P) &&
                    lastKeyboardState.IsKeyUp(Keys.P))
                {
                    gameState = GameState.Playing;
                }

                break;
            }

            currentGamepadState = GamePad.GetState(PlayerIndex.One);
            lastKeyboardState   = currentKeyboardState;

            base.Update(gameTime);
        }
Esempio n. 11
0
        //-----------------------------------------------------------

        //-----------------------------------------------------------
        //  Update
        //  Updates the screen
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            base.Update(gameTime);

            if (_gameState == GameState.Playing)
            {
                if (keyboardState.IsKeyDown(Keys.Escape) && _prevKeyboardState.IsKeyUp(Keys.Escape))
                {
                    //  Pause the game
                    _gameState = GameState.Paused;
                }
                else
                {
                    _player.Update(gameTime);

                    UpdateActors(gameTime);

                    CheckForCollisions(gameTime);
                }
            }
            else if (_gameState == GameState.Paused)
            {
                if (keyboardState.IsKeyDown(Keys.Escape) && _prevKeyboardState.IsKeyUp(Keys.Escape))
                {
                    //  Unpause Game
                    _gameState = GameState.Playing;
                }
                else
                {
                    _pauseMenu.Update(gameTime);
                }
            }
            else if (_gameState == GameState.GameOver)
            {
                _gameOverMenu.Update(gameTime);
            }
            else if (_gameState == GameState.Waiting)
            {
                CheckForMouseClick(mouseState);
            }
            else if (_gameState == GameState.Introduction)
            {
                switch (_introductionTrigger)
                {
                case IntroductionTriggers.ClickPlayer:
                    if (_introductionPlayerClicked)
                    {
                        _introductionTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _helperLabel.UpdateText($"Click player circle and move mouse around ({(5.0f - _introductionTimer):00.0})");
                        if (_introductionTimer >= 5.0f)
                        {
                            _introductionTrigger = IntroductionTriggers.None;
                        }
                        _player.Update(gameTime);
                    }
                    else
                    {
                        CheckForMouseClick(mouseState);
                    }
                    break;

                case IntroductionTriggers.ConsumeFood:
                    _player.Update(gameTime);
                    CheckForCollisions(gameTime);
                    _introductionActor.Update(gameTime);
                    break;

                case IntroductionTriggers.ColorSwitch:
                    if (_colorSwitchCount >= 2)
                    {
                        _introductionTrigger = IntroductionTriggers.None;
                    }
                    if (_player.DidScolorSwitch)
                    {
                        _colorSwitchCount++;
                    }
                    _player.Update(gameTime);
                    break;

                case IntroductionTriggers.Start:
                    _gameState = GameState.Waiting;
                    break;

                default:
                    _helperLabel.UpdateText("");
                    _messageBox.Update(gameTime);
                    break;
                }
            }


            _prevKeyboardState = keyboardState;
            _prevMouseState    = mouseState;
        }