コード例 #1
0
ファイル: Enemy.cs プロジェクト: EddieBrazier/clusterpunks
        public void Update(KeyboardState kbState, KeyboardState PrevkbState, GameTime time, PlayerChar[] Units)
        {
            //initialize playerParty
            playerParty = Units;

            //enemy only takes action if it has health
            if (this.Health > 0)
            {
                //enemy starts their attack timer
                atk.Length = atk.Length - time.ElapsedGameTime.TotalSeconds;

                //if the position of the attacked party member is swapped,
                //inform the player that the swapped-in member is being attacked
                if (playerParty[attackedPlayer] != currentTarget)
                {
                    //add info to the combat log
                    BattleLog.ChangeEnemyTarget(this.name, playerParty[attackedPlayer].Name);

                    //set current target to the new attacked player
                    currentTarget = playerParty[attackedPlayer];

                    //set target icon to target player
                    targetIcon = currentTarget.Icon;
                }

                //execute attack when timer runs down
                if (atk.Length <= 0)
                {
                    this.Atk.EndEnemyAttack(this, playerParty, attackedPlayer);
                }
            }
        }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: EddieBrazier/clusterpunks
        public void CoolDown(GameTime time, PlayerChar[] Units)
        {
            //initialize playerParty
            playerParty = Units;

            //enemy attacks periodically until it dies

            //start the enemy on a cooldown of 15 seconds
            cooldown = cooldown - time.ElapsedGameTime.TotalSeconds;

            if (cooldown <= 0)
            {
                cooldown = 15;
                atk.ResetAttack(this, "Enemy");
                isAttacking = true;

                //roll for a randomly attacked player
                attackedPlayer = Config.GetRandom(0, 3);

                //set current target to the player in the spot that was rolled
                currentTarget = playerParty[attackedPlayer];

                //set target icon to target player
                targetIcon = currentTarget.Icon;

                //inform the user which player is being attacked
                BattleLog.AddEnemyAttack(this.name, playerParty[attackedPlayer].Name);
            }
        }
コード例 #3
0
        public void EnterEncounter()
        {
            //set inEncounter to true
            inEncounter = true;

            //send in enemy's encounter text
            BattleLog.EnemySpawn(enemy.Name);
        }
コード例 #4
0
ファイル: Attack.cs プロジェクト: EddieBrazier/clusterpunks
        public void EndPlayerAttack(Enemy attackTarget, PlayerChar attacker)
        {
            //may require an attack timer class and pause/unpause enums

            //damage the enemy
            attackTarget.Health = attackTarget.Health - attacker.Atk.damage;

            //set isAttacking to false
            attacker.IsAttacking = false;

            //add attack information to the battle log
            BattleLog.AddPlayerAttackEnd(attacker.Name, attackTarget.Name, attacker.Atk.damage);

            //reset attack timer
            ResetAttack(attacker, "Player");
        }
コード例 #5
0
ファイル: Attack.cs プロジェクト: EddieBrazier/clusterpunks
        public void EndEnemyAttack(Enemy enemy, PlayerChar[] playerParty, int playerNumber)
        {
            //set attacked player to the passed-in player number
            int attackedPlayer = playerNumber;

            //damage the chosen player
            playerParty[attackedPlayer].Health = playerParty[attackedPlayer].Health - enemy.Atk.Damage;

            //add info to battle log about the enemy's attack
            BattleLog.AddEnemyAttackEnd(enemy.Name, playerParty[attackedPlayer].Name, enemy.Atk.damage);

            //set enemy's isAttacking to false
            enemy.IsAttacking = false;

            //reset enemy attack
            enemy.Atk.ResetAttack(enemy, "Enemy");
        }
コード例 #6
0
        /// <summary>
        /// send in two craftitems and outputs a third from the craffting, order does not matter, level two items can be combined, combining an item that is already contained causes no changes
        /// </summary>
        /// <param name="item1">the first item</param>
        /// <param name="item2">the second item</param>
        public CraftItem(CraftItem item1, CraftItem item2)
        {
            //add components to the item only if the component isn't empty
            foreach (Item i in item1.Components)
            {
                if (i != Item.Empty && Components.IndexOf(i) == -1)
                {
                    Components.Add(i);
                }
            }
            foreach (Item i in item2.Components)
            {
                if (i != Item.Empty && Components.IndexOf(i) == -1)
                {
                    Components.Add(i);
                }
            }
            //store the items components

            if (Components.Count() == 0)
            {
                CraftItem temp = new CraftItem(Item.Empty);
                dmg      = temp.dmg;
                itemType = temp.ItemType;
                itemInfo = temp.ItemInfo;
            }

            Components.Sort();

            //loop through all of the items
            foreach (CraftItem i in Config.AllItems)
            {
                //if the items have the same component as the new item
                if (Components.Except(i.Components).ToList <Item>().Count() == 0 && i.Components.Except(Components).ToList <Item>().Count() == 0)
                {
                    //finish the creation of the item
                    dmg      = i.dmg;
                    itemType = i.itemType;
                    duration = i.Duration;
                    itemInfo = i.itemInfo;

                    //add crafting notification to battle log
                    BattleLog.AddCraft(this);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.SkyBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();

            //switch statement to determine which state the game is in and run draw methods accordingly
            switch (gameState)
            {
            case GameState.Menu:
                spriteBatch.Draw(TitleImage, new Vector2(0, 0), Color.White);
                for (int j = 0; j < titleButtons.Count; j++)
                {
                    titleButtons[j].Draw(spriteBatch);
                }



                break;

            case GameState.RoomSelect:
                spriteBatch.Draw(MapBackground, new Vector2(0, 0), Color.White);
                mainDungeon.Draw(spriteBatch);
                break;

            case GameState.Combat:

                //draw background
                spriteBatch.Draw(
                    UI.GameUI[7],
                    new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height),
                    Color.DarkGray                             //Changed to Dark Gray to make the UI and Characters stand out more
                    );

                //draw characters and combat UI
                current.Handler.Draw(spriteBatch);

                //draw the enemy
                current.EnemyDraw(this, spriteBatch, 0);

                //update battlelog and draw it to the screen
                BattleLog.Draw(this, spriteBatch, menuFont);

                break;

            case GameState.GameOver:

                //temporary game over screen that informs the player to press enter to return to the menu
                spriteBatch.Draw(Defeat, new Rectangle(0, 0, 800, 480), Color.White);

                break;

            case GameState.ControlMenu:

                spriteBatch.Draw(ControlsSheet[controlspage], new Rectangle(0, 0, 800, 480), Color.White);
                titleButtons[2].Draw(spriteBatch);
                foreach (Button b in controlsIncrementer)
                {
                    b.Draw(spriteBatch);
                }
                break;

            case GameState.Win:
                spriteBatch.Draw(Victory, new Rectangle(0, 0, 800, 480), Color.White);
                break;
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
コード例 #8
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            kbState = Keyboard.GetState();
            mState  = Mouse.GetState();
            ;
            //switch statement to determine which state the game is in and run update methods accordingly
            switch (gameState)
            {
            case GameState.Menu:

                for (int j = 0; j < titleButtons.Count; j++)
                {
                    if (titleButtons[j].Update(mState))
                    {
                        switch (j)
                        {
                        case 0:
                            mainDungeon = new Dungeon(this);
                            gameState   = GameState.RoomSelect;
                            break;

                        case 1:
                            gameState = GameState.ControlMenu;
                            break;

                        case 2:
                            Exit();
                            break;
                        }
                    }
                }

                //start game when the player presses enter
                if (Config.SingleKeyPress(Keys.Enter, kbState, PrevkbState) == true)
                {
                    gameState = GameState.RoomSelect;
                }

                break;

            case GameState.RoomSelect:
                //Lets Player select a room to go to
                current = mainDungeon.Update(mState, prevMsState);

                if (current != null)
                {
                    gameState       = GameState.Combat;
                    current.Handler = handler;
                }
                break;

            case GameState.Combat:

                //Initiates combat in the current room, with the encounter generated
                current.CombatEncounter(this, kbState, PrevkbState, mState, prevMsState, gameTime);
                for (int i = 0; i < handler.PlayerParty.Length; i++)
                {
                    handler.PlayerParty[i].Update(kbState, PrevkbState, gameTime);
                }
                //check party's health and enter GameOver state if it equals zero
                int partyHealth = current.CombatHandler.PartyHealth();
                if (partyHealth == 0)
                {
                    MediaPlayer.Stop();
                    gameState = GameState.GameOver;
                }

                //checks enemy's health. when it hits zero, drops loot and returns to room select
                int enemyHealth = current.CombatHandler.EnemyHealth();
                if (enemyHealth <= 0)
                {
                    if (mainDungeon.GameWin())
                    {
                        gameState = GameState.Win;
                        handler   = new PlayerHandler(Content.Load <SpriteFont>("Arial-12"), this);
                    }
                    else
                    {
                        gameState = GameState.RoomSelect;
                        current.Handler.PlayerInv.DropItems(0, 10);
                        current.Handler.EndEncounter();
                        BattleLog.ClearLog();
                    }
                }

                break;

            case GameState.GameOver:

                //return to menu when player presses Enter
                if (Config.SingleKeyPress(Keys.Enter, kbState, PrevkbState) == true)
                {
                    gameState = GameState.Menu;

                    foreach (Button b in titleButtons)
                    {
                        b.Deselect();
                    }
                }

                break;

            case GameState.ControlMenu:

                if (controlsIncrementer[0].Update(mState))
                {
                    controlsIncrementer[0].Deselect();
                    controlspage++;
                    if (controlspage == 3)
                    {
                        controlspage = 0;
                    }
                }
                else if (controlsIncrementer[1].Update(mState))
                {
                    controlsIncrementer[1].Deselect();
                    controlspage--;
                    if (controlspage == -1)
                    {
                        controlspage = 2;
                    }
                }


                if (titleButtons[2].Update(mState))
                {
                    for (int j = 0; j < titleButtons.Count; j++)
                    {
                        titleButtons[j].Deselect();
                    }
                    gameState = GameState.Menu;
                }
                break;

            case GameState.Win:
                if (Config.SingleKeyPress(Keys.Enter, kbState, PrevkbState))
                {
                    gameState = GameState.Menu;
                    foreach (Button b in titleButtons)
                    {
                        b.Deselect();
                    }
                }
                break;
            }

            PrevkbState = kbState; //stores the previous keyboard state
            prevMsState = mState;  //stores previous mouse state

            base.Update(gameTime);
        }
コード例 #9
0
        public void Update(KeyboardState kbState, KeyboardState PrevkbState, MouseState mState, MouseState prevMsState, PlayerChar[] Units)
        {
            Boolean madeSelection = false;

            //--Temporary--//
            //refills the players inventory
            if (Config.SingleKeyPress(Keys.Down, kbState, PrevkbState))
            {
                DropItems(5, 8);
            }


            switch (selected)
            {
            case SelectedState.deselected:

                #region player keyboard controls
                //First characters inventory
                //cannot access when attacking
                if (Config.SingleKeyPress(Keys.Q, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    SelectedItemX = 0;
                    SelectedItemY = 0;
                    madeSelection = true;

                    selected = SelectedState.selected;
                }
                else if (Config.SingleKeyPress(Keys.W, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    SelectedItemX = 0;
                    SelectedItemY = 1;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.A, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    SelectedItemX = 0;
                    SelectedItemY = 2;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.S, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    SelectedItemX = 0;
                    SelectedItemY = 3;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                //second characters inventory
                //cannot access while attacking
                else if (Config.SingleKeyPress(Keys.E, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    SelectedItemX = 1;
                    SelectedItemY = 0;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.R, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    SelectedItemX = 1;
                    SelectedItemY = 1;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.D, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    SelectedItemX = 1;
                    SelectedItemY = 2;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.F, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    SelectedItemX = 1;
                    SelectedItemY = 3;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                //third characters inventory
                //cannot access while attacking
                else if (Config.SingleKeyPress(Keys.T, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    SelectedItemX = 2;
                    SelectedItemY = 0;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.Y, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    SelectedItemX = 2;
                    SelectedItemY = 1;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.G, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    SelectedItemX = 2;
                    SelectedItemY = 2;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }
                else if (Config.SingleKeyPress(Keys.H, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    SelectedItemX = 2;
                    SelectedItemY = 3;
                    selected      = SelectedState.selected;
                    madeSelection = true;
                }

                if (madeSelection)
                {
                    invButtons[SelectedItemX, SelectedItemY].Select();
                }
                #endregion

                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        if (!Units[j].IsAttacking && invButtons[j, k].Update(mState) == true && Units[j].Health > 0)                                 //player inv is locked when attacking
                        {
                            selected      = SelectedState.selected;
                            SelectedItemX = j;
                            SelectedItemY = k;
                        }
                    }
                }

                if (selected == SelectedState.deselected)
                {
                    foreach (Button button in invButtons)
                    {
                        button.Deselect();
                    }
                }


                //dont call update for craft button because it cannot be used unless you have already selected an item

                break;

            case SelectedState.selected:

                #region Player Keyboard Controls
                //first char inv
                if (Config.SingleKeyPress(Keys.Q, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    Swap(0, 0);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.W, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    Swap(0, 1);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.A, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    Swap(0, 2);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.S, kbState, PrevkbState) && Units[0].IsAttacking == false && Units[0].Health > 0)
                {
                    Swap(0, 3);
                    selected = SelectedState.deselected;
                }


                //second char inv
                else if (Config.SingleKeyPress(Keys.E, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    Swap(1, 0);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.R, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    Swap(1, 1);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.D, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    Swap(1, 2);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.F, kbState, PrevkbState) && Units[1].IsAttacking == false && Units[1].Health > 0)
                {
                    Swap(1, 3);
                    selected = SelectedState.deselected;
                }

                //third char inv

                else if (Config.SingleKeyPress(Keys.T, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    Swap(2, 0);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.Y, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    Swap(2, 1);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.G, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    Swap(2, 2);
                    selected = SelectedState.deselected;
                }
                else if (Config.SingleKeyPress(Keys.H, kbState, PrevkbState) && Units[2].IsAttacking == false && Units[2].Health > 0)
                {
                    Swap(2, 3);
                    selected = SelectedState.deselected;
                }
                #endregion

                //deselects any selected items?
                if (Config.SingleKeyPress(Keys.Tab, kbState, PrevkbState))
                {
                    invButtons[SelectedItemX, SelectedItemY].Deselect();     //player inv is locked when attacking
                    selected = SelectedState.deselected;
                    foreach (Button b in invButtons)
                    {
                        b.Deselect();
                    }
                }


                //initiate an attack with a selected item if the space bar is pressed
                //or if the right mouse button is clicked
                if (Config.SingleKeyPress(Keys.Space, kbState, PrevkbState) || Config.SingleRightMouseClick(mState, prevMsState) || AttackButton.Update(mState))
                {
                    //create an item object to send to a given character's attack method
                    CraftItem usedItem = items[SelectedItemX, SelectedItemY];

                    //deselect the item so the slot isn't selected after an attack executes
                    invButtons[SelectedItemX, SelectedItemY].Deselect();
                    selected = SelectedState.deselected;

                    //party member attacks based on the selected item's x value
                    //start the party member's attack and set isAttacking to true
                    Units[SelectedItemX].IsAttacking = Units[SelectedItemX].Atk.StartAttack(items, usedItem, SelectedItemX, SelectedItemY);

                    //send info for attack initiation to battle log
                    BattleLog.AddPlayerAttackStart(Units[SelectedItemX]);
                    AttackButton.Deselect();
                }

                //handles mouse controls
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        if (Units[j].IsAttacking == false)
                        {
                            if (invButtons[j, k].Update(mState) == true)
                            {
                                invButtons[j, k].Deselect();
                                invButtons[SelectedItemX, SelectedItemY].Deselect();
                                selected = SelectedState.deselected;
                                Swap(j, k);
                            }
                        }
                    }
                }

                //Handles crafting controls
                if (SelectedItemX != -1 && SelectedItemY != -1 && items[SelectedItemX, SelectedItemY].ItemType != Item.Empty && (craftButton.Update(mState) || Config.SingleKeyPress(Keys.LeftShift, kbState, PrevkbState) || Config.SingleKeyPress(Keys.RightShift, kbState, PrevkbState)))
                {
                    switch (craftState)
                    {
                    case SelectedState.deselected:
                        selectedToCraft = items[SelectedItemX, SelectedItemY];
                        items[SelectedItemX, SelectedItemY] = new CraftItem(Item.Empty);

                        craftState = SelectedState.selected;
                        craftButton.Deselect();

                        break;

                    case SelectedState.selected:
                        items[SelectedItemX, SelectedItemY] = new CraftItem(items[SelectedItemX, SelectedItemY], selectedToCraft);
                        craftState = SelectedState.deselected;
                        craftButton.Deselect();

                        break;
                    }
                    selected = SelectedState.deselected;
                    invButtons[SelectedItemX, SelectedItemY].Deselect();
                }


                break;
            }
        }