Example #1
0
        /// <summary>
        /// Draws a thing
        /// </summary>
        private void DrawThing(ModelClasses.Units.Thing a_thing)
        {
            Matrix f_world = m_camera.GetWorldMatrix(a_thing.m_currentposition);

            foreach (ModelMesh mesh in a_thing.m_model.Meshes)
            {
                foreach (Effect effect in mesh.Effects)
                {
                    if (a_thing.m_thingState == ModelClasses.Units.ThingState.BeingBuilt)
                    {
                        effect.CurrentTechnique = effect.Techniques["tech_isBeingBuilt"];
                    }
                    else
                    {
                        effect.CurrentTechnique = effect.Techniques["technique0"];
                    }

                    effect.Parameters["World"].SetValue(f_world);
                    effect.Parameters["View"].SetValue(m_camera.m_view);

                    effect.Parameters["PointLight"].SetValue(m_camera.m_cameraPos);
                }

                mesh.Draw();
            }
        }
Example #2
0
        private void DrawUnitInfo(ModelClasses.Units.Thing a_thing, SpriteBatch spriteBatch, SpriteFont a_font)
        {
            //writes the info unit wpos, attack cooldown and the state of the unit
            string text = string.Format("Wpos X:{0:0.00} Y:{1:0.00} Z:{2:0.00} "
                                        + "\nState:{3} ID:{4}\n",
                                        a_thing.m_currentposition.X, a_thing.m_currentposition.Y,
                                        a_thing.m_currentposition.Z, a_thing.m_thingState, a_thing.m_ownerID);

            if (a_thing.m_attackBehavior != null)
            {
                if (a_thing.m_type == ModelClasses.Units.ThingType.C_Cube)
                {
                    ModelClasses.BehaviorInterfaces.StandardAttack f_attackBehavior = (ModelClasses.BehaviorInterfaces.StandardAttack)a_thing.m_attackBehavior;

                    text += string.Format("Atk CD: {0:0.00}", f_attackBehavior.m_cooldownTimer);
                }
            }

            spriteBatch.DrawString(a_font, text, m_unitInfoPosition, Color.Red);
        }
Example #3
0
 public static StandardAttack CreateNewStandardAttack(ModelClasses.Units.Thing a_attacker, float a_attackRate, int a_damage, float a_attackRange)
 {
     return(new StandardAttack(a_attacker, a_attackRate, a_damage, a_attackRange));
 }
Example #4
0
        private void MouseHandling(GraphicsDevice a_graphics, ModelClasses.Game a_game, ViewClasses.GameView a_gameView)
        {
            if (m_input.mouseRightClick())
            {
                //Check if Ray from right clicking hit anything
                //If it did attack that target

                //If it didn't, Move to that target
                //If Attack is active Set units to hunting towards target
                //gets a world position based on a plane, and mouse position

                //rightclicks clears pending actions
                a_gameView.m_HUD.ClearPendingButtons();
                a_game.m_player.m_tryingToBuild = false;

                Ray f_worldRay = m_input.GetWorldRay(a_graphics, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y);

                ModelClasses.Units.Thing f_target = a_game.TryToAttackOrMove(f_worldRay);

                //If didn't find any target, then move to location!
                if (f_target == null)
                {
                    //Get world pos point
                    Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y);
                    if (point.HasValue)
                    {
                        //Check if shift is down, do queue up paths
                        if (m_input.m_keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
                        {
                            a_game.TryToAddDestination(a_game.m_player, point.Value, false);
                        }
                        else
                        {
                            a_game.TryToAddDestination(a_game.m_player, point.Value, true);
                        }
                    }
                }//If it found a target from the ray
                else
                {
                    //If the target isn't owned by player, attack!!!!
                    if (f_target.m_ownerID != a_game.m_player.m_playerID)
                    {
                        a_game.m_player.SetAttackTarget(f_target);
                    }//If player owns the target, move towards!
                    else
                    {
                        //If the target is building and has standardbuild as build interface
                        if (!f_target.m_isUnit && f_target.m_buildBehavior is ModelClasses.BehaviorInterfaces.StandardBuild && f_target.m_thingState != ModelClasses.Units.ThingState.BeingBuilt)
                        {
                            //Creates the bounding box
                            BoundingBox f_box = (BoundingBox)f_target.m_model.Tag;

                            f_box.Max += f_target.m_currentposition;
                            f_box.Min += f_target.m_currentposition;

                            foreach (ModelClasses.Units.Thing selectedThing in a_game.m_player.m_selectedThings)
                            {
                                //The direction of the ray (from selectedItem -> target)
                                Vector3 f_dir = new Vector3(f_target.m_currentposition.X - selectedThing.m_currentposition.X, f_target.m_currentposition.Y - selectedThing.m_currentposition.Y, 0);

                                f_dir.Normalize();

                                //The ray from unit -> building
                                Ray f_tempRay = new Ray(new Vector3(selectedThing.m_currentposition.X, selectedThing.m_currentposition.Y, f_target.m_currentposition.Z), f_dir);

                                float?f_intersection = f_tempRay.Intersects(f_box);

                                if (f_intersection.HasValue)
                                {
                                    //Point =  Raypos + (Raydir * distanceToPoint)
                                    Vector3 point = (f_tempRay.Position + f_tempRay.Direction * f_intersection.Value);

                                    //If it finds a path
                                    //  Martin: The pathfinder IS working correctly. However there is no way to find a path to a tile which is surrounded by blocked tiles.
                                    //          A center position of a building of 3x3 size is obviously unreachable.
                                    //          Also, the pathfinder doesn't use the height when calculating a path, it only cares about if a tile is blocked or not
                                    if (a_game.m_pathFinder.FindPath(selectedThing.m_currentposition, point) == 1)
                                    {
                                        selectedThing.ChangeDestination(a_game.m_pathFinder.m_pathList);

                                        if (selectedThing.m_type == ModelClasses.Units.ThingType.C_Cube)
                                        {
                                            f_target.m_buildBehavior.AddSacrifice(selectedThing);
                                        }
                                    }
                                }
                            }
                        }//If not, move towards point!
                        else
                        {
                            //Get world pos point
                            Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y);
                            if (point.HasValue)
                            {
                                //Check if shift is down, do queue up paths
                                if (m_input.m_keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
                                {
                                    a_game.TryToAddDestination(a_game.m_player, point.Value, false);
                                }
                                else
                                {
                                    a_game.TryToAddDestination(a_game.m_player, point.Value, true);
                                }
                            }
                        }
                    }
                }
            }

            if (m_input.mouseLeftButtonDown() && !a_game.m_player.m_tryingToBuild)
            {
                BoundingBox?box = m_input.CreateBBSelection(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera);
                if (box.HasValue)
                {
                    ViewClasses.BoundingBoxBuffer.m_color = Color.White;
                    ViewClasses.GameView.DrawBoundingBox(box.Value, a_graphics, Matrix.Identity, a_gameView.m_camera);
                }
            }


            if (m_input.mouseLeftClick())
            {
                //if the focused unit does NOT have any pending buttons
                if (!a_gameView.m_HUD.HasAPendingButton())
                {
                    //If mouse hasn't moved, for eg. you clicked
                    if (m_input.m_mouse.m_mouseState.X == m_input.m_mouse.m_oldXpos && m_input.m_mouse.m_mouseState.Y == m_input.m_mouse.m_oldYpos)
                    {
                        if (m_input.m_mouse.m_mouseState.Y <= HUD.m_area.Top)
                        {
                            a_game.TryToSelect(m_input.GetWorldRay(a_graphics, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y));
                        }
                    }//If mouse moved after you pressed it
                    else
                    {
                        BoundingBox?f_mouseBox = m_input.CreateBBSelection(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera);

                        if (f_mouseBox.HasValue)
                        {
                            a_game.TryToSelect(f_mouseBox.Value);
                        }
                    }
                }
                else
                {
                    //the mouse point
                    Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y);

                    //Gotta check if it's null or not, or might get null exception
                    if (point.HasValue)
                    {
                        //check buttons
                        for (int y = 0; y < a_gameView.m_HUD.m_actionboxButtons.GetLength(1); y++)
                        {
                            for (int x = 0; x < a_gameView.m_HUD.m_actionboxButtons.GetLength(0); x++)
                            {
                                //if the button is pending
                                if (a_gameView.m_HUD.m_actionboxButtons[x, y].m_state == Button.BtnState.Pending)
                                {
                                    //use the function of the pending button
                                    a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function(a_game, point.Value);

                                    //reset the now used button
                                    a_gameView.m_HUD.m_actionboxButtons[x, y].m_state = Button.BtnState.Normal;
                                    a_game.m_player.m_tryingToBuild = false;
                                }
                            }
                        }
                    }
                }
            }
        }