Update() public method

public Update ( ) : void
return void
    // Update is called once per frame
    void Update()
    {
        //check to see if this entity is still living
        if (knockedback)
        {
            agent.Stop();
            Debug.Log("Knocked Back: " + rigidbody.velocity.magnitude);
            if (rigidbody.velocity.magnitude >= 5.0f)
            {
                knockedback        = false;
                rigidbody.velocity = Vector3.zero;
            }
            agent.Resume();
        }
        //refresh the attack cooldown
        if (Time.time >= lastAttackTime + attackCooldown)
        {
            isAttacking = false;
        }

        ai.Update(transform);
    }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                _game.ChangeState(new PauseState(_game, _graphicsDevice, _content, this));
            }

            int   x              = Mouse.GetState().X;
            int   y              = Mouse.GetState().Y;
            bool  mousePressed   = (Mouse.GetState().LeftButton == ButtonState.Pressed);
            bool  mouseOnTile    = Ship.Grid.PixelToTile(x, y, out int tileX, out int tileY);
            Point tileUnderMouse = new Point(tileX, tileY);

            _playerPowerBar.Value = ((float)Ship.Power / (float)Ship.maxPower);
            _playerPowerBar.SetText("Power: " + (int)Ship.Power + " / " + (int)Ship.maxPower);

            _tooltip.Show = false;
            switch (clicked_State)
            {
            case (Clicked_State.None):
            {
                break;
            }

            case (Clicked_State.SetAttack):
            {
                if (mouseOnTile)
                {
                    foreach (Room room in Ship.Rooms)
                    {
                        if (room.RoomType == Room.Room_Type.Weapon && room.InteriorContains(tileUnderMouse))
                        {
                            _tooltip.Show = true;
                            _tooltip.SetText("DPS: " + room.DamagePerSecond());
                        }
                    }
                }
                if (mousePressed & mouseOnTile)
                {
                    foreach (Room room in Ship.Rooms)
                    {
                        if (room.Contains(tileUnderMouse) & room.RoomType == Room.Room_Type.Weapon && !room.isBroken)
                        {
                            attackingRoom = room;
                            clicked_State = Clicked_State.Attacking;
                            _selectedRoomBox.SetPosition(room.GetInteriorArea());
                            _selectedRoomBox.Show = true;
                        }
                    }
                }
                break;
            }

            case (Clicked_State.Repair):
            {
                if (mousePressed & mouseOnTile)
                {
                    foreach (Room room in Ship.Rooms)
                    {
                        if (room.Contains(tileUnderMouse))
                        {
                            room.Repair();
                        }
                    }
                }
                break;
            }
            }

            _canvas.SetProgressButtonValue(ControlConstants.COMBATMODE_TARGETENEMYSHIP.Text, ((float)enemyAI.shipHealth / (float)enemyAI.maxShipHealth));
            _canvas.SetProgressButtonValue(ControlConstants.COMBATMODE_TARGETWEAPONS.Text, ((float)enemyAI.weaponHealth / (float)enemyAI.weaponMaxHealth));
            _canvas.SetProgressButtonValue(ControlConstants.COMBATMODE_TARGETSTORAGES.Text, ((float)enemyAI.materialStorageHealth / (float)enemyAI.materialMaxHealth));
            _canvas.SetProgressButtonValue(ControlConstants.COMBATMODE_TARGETPOWERGEN.Text, ((float)enemyAI.powerGeneratorHealth / (float)enemyAI.generatorMaxHealth));
            _canvas.SetProgressButtonValue(ControlConstants.COMBATMODE_TARGETPOWERSTORAGE.Text, ((float)enemyAI.powerStorageHealth / (float)enemyAI.powerStorageMaxHealth));


            foreach (var component in _uicomponents)
            {
                component.Update(gameTime);
            }

            enemyAI.Update(gameTime);

            foreach (var projectile in projectiles)
            {
                projectile.Update(gameTime);
                if (projectile.AtTarget == true)
                {
                    deadProjectiles.Add(projectile);
                }
            }
            foreach (var projectile in deadProjectiles)
            {
                projectiles.Remove(projectile);
            }
            foreach (Room room in Ship.Rooms)
            {
                if (_roomHealthBoxes.ContainsKey(room.RoomID))
                {
                    _roomHealthBoxes[room.RoomID].Color = new Color(ControlConstants.COMBATMODE_ROOMHEALTHCOLOR, room.GetHealthAlpha());
                }
                else
                {
                    UIBox toAdd = new UIBox(_pixelTexture);
                    toAdd.SetPosition(room.GetInteriorArea());
                    toAdd.Color = new Color(ControlConstants.COMBATMODE_ROOMHEALTHCOLOR, room.GetHealthAlpha());
                    _roomHealthBoxes.Add(room.RoomID, toAdd);
                }
            }

            Ship.Update(gameTime);
            if (Ship.CurrentHealth < 0)
            {
                LoseGame();
            }
            _playerHealthBar.Value = ((float)Ship.CurrentHealth / (float)Ship.MaxHealth);

            if (enemyAI.shipHealth <= 0)
            {
                BuildModeButton_Click(this, null);
            }
        }