Example #1
0
        public Building(Game game, Player player, BuildingType type, Vector3 position, float scale = 1.0f, bool selectable = false, Vector3 rotation = default(Vector3))
            : base(game, player, type.Model)
        {
            timer = 5;
            Souls = 50;
            produktywnosc = 600;
            this.player = player;
            this.Position = position;
            this.Rotation = rotation;
            this.Scale = scale;
            this.type = (BuildingType)type.Clone();
            this.messages = new List<Message>();
            this.meshBoundingBoxes = new List<BoundingBox>();
            maxHP = this.type.maxhp;
            HP = maxHP;
            this.selectable = selectable;
            buildtime = this.type.buildtime;
            this.game = game;

            Matrix[] modelTransforms = new Matrix[currentModel.Model.Bones.Count];
            currentModel.Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
            foreach (ModelMesh mesh in currentModel.Model.Meshes)
            {
                List<Vector3> meshVertices = new List<Vector3>();
                Matrix transformations = modelTransforms[mesh.ParentBone.Index] * GetWorldMatrix();
                VertexHelper.ExtractModelMeshData(mesh, ref transformations, meshVertices);
                meshBoundingBoxes.Add(BoundingBox.CreateFromPoints(meshVertices));
            }

            ModelExtra modelExtra1 = currentModel.Model.Tag as ModelExtra;
            BoundingSphere originalSphere2 = modelExtra1.boundingSphere;
            boundingBox = BoundingBox.CreateFromSphere(XNAUtils.TransformBoundingSphere(originalSphere2, GetWorldMatrix()));
        }
Example #2
0
        public Unit(Game game, Player player, UnitType type, Vector3 position, float scale = 1.0f, Vector3 rotation = default(Vector3))
            : base(game, player, type.model)
        {
            Souls_owned = 0;
            this.player = player;
            this.Position = position;
            this.Rotation = rotation;
            this.Scale = scale;
            this.type = (UnitType)type.Clone();

            if (this.type.name.Contains("Worker"))
            {
                this.budowniczy = true;
            }

            this.maxHP = this.type.maxhp;
            this.HP = this.maxHP;
            this.lastHP = this.HP;
            setIdle();
            this.damage = this.type.damage;
            this.range = this.type.range;
            this.ratio = this.type.ratio;

            this.pathFiding = new ZnajdzSciezke();
            this.pathFiding.mapaUstaw();
            ModelExtra modelExtra = currentModel.Model.Tag as ModelExtra;
            originalSphere1 = modelExtra.boundingSphere;
        }
Example #3
0
        public GameObject(Game game, Player player, String path)
        {
            this.player = player;
            this.messages = new List<Message>();

            this.game = game;
            currentModel = new AnimatedModel(path);
            currentModel.LoadContent(game.Content);
        }
Example #4
0
 public static void Initialize(ContentManager content, Player Player)
 {
     width = 100;
     height = 50;
     iconHeight = 32;
     iconWidth = 32;
     player = Player;
     sourcesButton = content.Load<Texture2D>("GUI/button");
     sourcesIcon = content.Load<Texture2D>("GUI/soul");
     font = content.Load<SpriteFont>("Georgia");
 }
Example #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("Georgia");
            defferedRenderer = new DefferedRenderer(device, Content, spriteBatch, font, this);
            objects = new List<GameObject>();

            UnitTypes = Content.Load<UnitType[]>("ObjectTypes/UnitTypes").ToDictionary(t => t.name);
            BuildingTypes = Content.Load<BuildingType[]>("ObjectTypes/BuildingTypes").ToDictionary(t => t.Name);

            player = new Player(this, UnitTypes, BuildingTypes);
            enemy = new Player(this, UnitTypes, BuildingTypes);

            sounds = new SoundEffect[1];
            sounds[0] = Content.Load<SoundEffect>("Sounds/Shot");
            video = Content.Load<Video>("Video/Intro");

            LoadMap(@"Mapa\Objects.xml");

            player.Initialize();
            enemy.Initialize();

            Laikos.PathFiding.Map.loadMap(Content.Load<Texture2D>("Models/Terrain/Heightmaps/heightmap4"), decorations);

            InitializeMapAfterLoad();

            Minimap.LoadMiniMap(Content);
            SelectingGUI.Init(device, graphics, this, player.UnitList, player.BuildingList, enemy.UnitList, enemy.BuildingList);
            GUI.Initialize(device, spriteBatch, Content, player);
        }
Example #6
0
        private static void SelectSingle(Player player, GraphicsDevice device)
        {
            bool object_clicked;
            Vector2 pointerPos = new Vector2(currentMouseState.X, currentMouseState.Y);
            Ray pointerRay = Collisions.GetPointerRay(pointerPos, device);
            Ray clippedRay = Collisions.ClipRay(pointerRay, 60, 0);

            DeselectAll(player);

            for (int i = 0; i < player.UnitList.Count; i++)
            {
                object_clicked = Collisions.RayModelCollision(clippedRay, player.UnitList[i].currentModel.Model, player.UnitList[i].GetWorldMatrix());
                if (object_clicked)
                {
                    EventManager.CreateMessage(new Message((int)EventManager.Events.Selected, null, player.UnitList[i], null));
                    break;
                }
            }

            for (int i = 0; i < player.BuildingList.Count; i++)
            {
                object_clicked = Collisions.RayModelCollision(clippedRay, player.BuildingList[i].currentModel.Model, player.BuildingList[i].GetWorldMatrix());
                if (object_clicked)
                {
                    EventManager.CreateMessage(new Message((int)EventManager.Events.Selected, null, player.BuildingList[i], null));
                    break;
                }
            }
        }
Example #7
0
        private static void SelectInWindow(Player player, Vector2 startDrag, Vector2 stopDrag, GraphicsDevice device)
        {
            DeselectAll(player);

            MathUtils.SafeSquare(ref startDrag, ref stopDrag);

            for (int i = 0; i < player.UnitList.Count; i++)
            {
                Vector3 pos = device.Viewport.Project(player.UnitList[i].Position, Camera.projectionMatrix,
                                                                       Camera.viewMatrix,
                                                                       Matrix.CreateTranslation(Vector3.Zero));
                if (pos.X >= startDrag.X && pos.X <= stopDrag.X && pos.Y >= startDrag.Y &&
                    pos.Y <= stopDrag.Y)
                {
                    EventManager.CreateMessage(new Message((int)EventManager.Events.Selected, null, player.UnitList[i], null));
                }

            }
        }
Example #8
0
        private static void DeselectAll(Player player)
        {
            foreach (Unit unit in player.UnitList)
                EventManager.CreateMessage(new Message((int)EventManager.Events.Unselected, null, unit, null));

            foreach (Building building in player.BuildingList)
                EventManager.CreateMessage(new Message((int)EventManager.Events.Unselected, null, building, null));
        }
Example #9
0
        /// <summary>
        /// Handling Inputs: Camera Movement, Keyboard, Mouse Buttons 
        /// </summary>
        public static void Update(Game game, GameTime gameTime, GraphicsDevice device, Camera camera, Player player, List<Decoration> decorationlist)
        {
            currentKeyboardState = Keyboard.GetState();
            currentMouseState = Mouse.GetState();

            HandleCamera(gameTime, camera);
            HandleMouse(player, game, decorationlist, device);
            HandleKeyboard(player, game, device);

            oldMouseState = currentMouseState;
            oldKeyboardState = currentKeyboardState;
        }
Example #10
0
        /// <summary>
        /// Handles mouse Left click and Right Click actions
        /// </summary>
        public static void HandleMouse(Player player, Game game, List<Decoration> decorationlist, GraphicsDevice device)
        {
            #region Left Click

            #region SelectionBox
            if (currentMouseState.LeftButton == ButtonState.Pressed &&
                oldMouseState.LeftButton == ButtonState.Pressed)
            {
                if (!SelectingGUI.GUIClicked(currentMouseState.X, currentMouseState.Y))
                {
                    selectionbox = true;

                    if (startDrag.X < 0)
                    {
                        startDrag.X = currentMouseState.X;
                        startDrag.Y = currentMouseState.Y;

                        SelectingGUI.selectionbox = true;
                        SelectingGUI.startDrag.X = SelectingGUI.stopDrag.X = currentMouseState.X;
                        SelectingGUI.startDrag.Y = SelectingGUI.stopDrag.Y = currentMouseState.Y;
                    }
                    else
                    {
                        SelectingGUI.startDrag.X = startDrag.X;
                        SelectingGUI.startDrag.Y = startDrag.Y;

                        SelectingGUI.stopDrag.X = currentMouseState.X;
                        SelectingGUI.stopDrag.Y = currentMouseState.Y;
                    }
                }
            }
            #endregion

            else if (currentMouseState.LeftButton == ButtonState.Released &&
                   oldMouseState.LeftButton == ButtonState.Pressed)
            {
                #region Building
                if (building_mode == true)
                {
                    next_build.position = GetPointerCoord(device);
                    foreach (Unit unit in player.UnitList)
                        if (unit.selected == true && unit.budowniczy == true)
                        {
                            EventManager.CreateMessage(new Message((int)EventManager.Events.MoveToBuild, null, unit, next_build)); //zamiast ostatniego nulla trzeba przeslac co i gdzie ma zbudowac
                            // unit.setWalk();
                        }
                    building_mode = false;
                }
                #endregion
                #region Selections
                else if (selectionbox && (!SelectingGUI.GUIClicked(currentMouseState.X, currentMouseState.Y)))
                {
                    if ((Math.Abs(startDrag.X - currentMouseState.X) * Math.Abs(startDrag.Y - currentMouseState.Y)) >
                        100)
                    {
                        var stopwatch = System.Diagnostics.Stopwatch.StartNew();
                        SelectInWindow(player, startDrag,
                            new Vector2(currentMouseState.X, currentMouseState.Y), device);
                        stopwatch.Stop();
                        Console.WriteLine("SelectMultipleUnits(...) : {0}", stopwatch.Elapsed);
                    }
                    else
                    {
                        var stopwatch = System.Diagnostics.Stopwatch.StartNew();

                        SelectSingle(player, device);

                        stopwatch.Stop();
                        Console.WriteLine("SelectSingleUnit(...) : {0}", stopwatch.Elapsed);

                    }
                    SelectingGUI.selectionbox = selectionbox = false;
                    startDrag.X = -9999;
                    startDrag.Y = -9999;
                }
                #endregion
            }

            GUI.ProcessInput((Game1)game);

            #endregion

            #region Right Click
            if (currentMouseState.RightButton == ButtonState.Pressed &&
               oldMouseState.RightButton == ButtonState.Released)
            {
                var stopwatch = System.Diagnostics.Stopwatch.StartNew();

                Vector2 pointerPos = new Vector2(currentMouseState.X, currentMouseState.Y);
                Ray pointerRay = Collisions.GetPointerRay(pointerPos, device);
                Ray clippedRay = Collisions.ClipRay(pointerRay, 60, 0);
                Ray shorterRay = Collisions.LinearSearch(clippedRay);
                Vector3 pointerPosition = Collisions.BinarySearch(shorterRay);

                Object clicked = WhatClicked((Game1)game, clippedRay);

                if (clicked is Unit || clicked is Building)
                {
                    if
                            (
                                ((clicked is Unit) && (IsEnemy((Unit)clicked, (Game1)game)))
                                ||
                                ((clicked is Building) && (IsEnemy((Building)clicked, (Game1)game)))
                            )
                    {
                        foreach (Unit _unit in player.UnitList)
                        {
                            if (_unit.selected)
                            {
                                EventManager.CreateMessage(new Message((int)EventManager.Events.MoveToAttack, null, _unit, clicked));
                                Console.WriteLine("AttackCommand(...) : {0}", stopwatch.Elapsed);
                            }
                        }
                    }
                    else
                    {
                        EventManager.CreateMessage(new Message((int)EventManager.Events.Interaction, null, clicked, null));
                        Console.WriteLine("InteractionCommand(...) : {0}", stopwatch.Elapsed);
                    }
                }
                else if (clicked is Decoration)
                {

                }
                else
                {
                    foreach (Unit unit in player.UnitList)
                    {
                        if (unit.selected)
                        {
                            foreach (Message _msg in unit.messages)
                            {
                                if
                                (
                                    (
                                        (_msg.Type == (int)EventManager.Events.Attack)
                                        ||
                                        (_msg.Type == (int)EventManager.Events.MoveToAttack)
                                    )
                                    &&
                                    (!_msg.Done))
                                {
                                    _msg.Done = true;
                                }
                            }

                            unit.destinyPoints = null;
                            EventManager.CreateMessage(new Message((int)EventManager.Events.MoveUnit, null, unit, pointerPosition));
                            stopwatch.Stop();
                            Console.WriteLine("MoveCommand(...) : {0}", stopwatch.Elapsed);
                        }
                    }
                }
            }
            #endregion
        }
Example #11
0
        /// <summary>
        /// Handle Keyboard - temporary unit WSAD movement and Animation swap
        /// </summary>
        public static void HandleKeyboard(Player player, Game game, GraphicsDevice device)
        {
            foreach (Unit unit in player.UnitList)
            {
                unit.lastPosition = unit.Position;

                if (unit.selected)
                {
                    if (currentKeyboardState.IsKeyDown(Keys.W))
                    {

                        unit.Position.Z -= 0.1f;
                        unit.Rotation.Y = MathHelper.ToRadians(180);
                    }
                    if (currentKeyboardState.IsKeyDown(Keys.S))
                    {

                        unit.Position.Z += 0.1f;
                        unit.Rotation.Y = MathHelper.ToRadians(360);
                    }
                    if (currentKeyboardState.IsKeyDown(Keys.A))
                    {

                        unit.Position.X -= 0.1f;
                        unit.Rotation.Y = MathHelper.ToRadians(270);
                    }
                    if (currentKeyboardState.IsKeyDown(Keys.D))
                    {
                        unit.Position.X += 0.1f;
                        unit.Rotation.Y = MathHelper.ToRadians(90);
                    }
                    if (currentKeyboardState.IsKeyDown(Keys.Z))
                    {
                        player.Souls += 100;
                    }

                }
                // Allows the game to exit
                if (currentKeyboardState.IsKeyDown(Keys.Escape) && oldKeyboardState.IsKeyUp(Keys.Escape))
                    game.Exit();

                if (currentKeyboardState.IsKeyDown(Keys.F1))
                {
                    DefferedRenderer.lightIntensity += 0.01f;
                }
                if (currentKeyboardState.IsKeyDown(Keys.F2))
                {
                    DefferedRenderer.lightIntensity -= 0.01f;
                }
            }
        }
Example #12
0
 public static void Initialize(GraphicsDevice Device, SpriteBatch SpriteBatch, ContentManager content, Player player)
 {
     block = false;
     screenWidth = Device.PresentationParameters.BackBufferWidth;
     screenHeight = Device.PresentationParameters.BackBufferHeight;
     spriteBatch = SpriteBatch;
     font2 = content.Load<SpriteFont>("INTRO");
     font = content.Load<SpriteFont>("DESC");
     messages = new List<Message>();
     MinimapBackground.Initialize(content);
     UpperBackground.Initialize(content);
     UnitBackground.Initialize(content);
     LowerBackground.Initialize(content);
     SourcesButton.Initialize(content, player);
     LowerOptionPanel.Initialize(content);
     game = player.game;
     typing = new StringTypingEffect(game,spriteBatch);
 }