Ejemplo n.º 1
0
 public void Die()
 {
     IsDead = true;
     if (this is Unit)
     {
         UnitAnimation a = new UnitAnimation((Unit)this, Width, .5f, true, Unit.Explosion1Textures);
         a.Start();
     }
 }
Ejemplo n.º 2
0
        public static void UpdateAll()
        {
            for (int i = 0; i < UnitAnimations.Count; i++)
            {
                UnitAnimation a = UnitAnimations[i];

                a.Update();

                if (!a.IsRunning || (!a.StayAfterDeath && a.Unit.IsDead))
                {
                    UnitAnimations.Remove(a);
                    i--;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Die()
        {
            base.Die();

            if (!UnderConstruction)
            {
                Player.Players[Team].MaxSupply -= type.Supply;
            }

            foreach (Structure structure in Structures)
            {
                structure.HasMoved = true;
            }

            UnitAnimation a = new UnitAnimation(this, Width, .5f, true, Structure.Explosion1Textures);

            a.Start();

            foreach (PathNode node in OccupiedPathNodes)
            {
                node.Blocked = false;
                node.Blocker = null;
            }

            if (Builder != null)
            {
                releaseBuilder();
                ((Rts)Game1.Game.CurrentGameState).CheckForResetCommandCardWhenStructureCompletes(this);
                CogWheel = null;
            }

            Player.Players[Team].StructureIDsToSetNull.Add(new KeyValuePair <short, float>(ID, Rts.GameClock));

            NetOutgoingMessage msg = Rts.netPeer.CreateMessage();

            msg.Write(MessageID.STRUCTURE_DEATH);
            msg.Write(ID);
            msg.Write(Team);
            Rts.netPeer.SendMessage(msg, Rts.connection, NetDeliveryMethod.ReliableUnordered);
        }
Ejemplo n.º 4
0
        void rightClick()
        {
            if (SelectedUnits.Count == 0)
                return;

            //magicBoxMaxSize = SelectedUnits.Count * 5;

            Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
            if (minimap.Contains(mouseState.X, mouseState.Y))
            {
                //mousePosition = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY);

                Vector2 minimapCenterPoint = new Vector2(minimap.X + minimap.Width / 2f, minimap.Y + minimap.Height / 2f);

                float distance = Vector2.Distance(mousePosition, minimapCenterPoint);
                float angle = (float)Math.Atan2(mousePosition.Y - minimapCenterPoint.Y, mousePosition.X - minimapCenterPoint.X);

                mousePosition = new Vector2(minimapCenterPoint.X + distance * (float)Math.Cos(angle - camera.Rotation), minimapCenterPoint.Y + distance * (float)Math.Sin(angle - camera.Rotation));

                mousePosition = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY);
            }
            else if (mouseState.Y > worldViewport.Height)
            {
                //return;
                mousePosition = Vector2.Transform(new Vector2(mousePosition.X, worldViewport.Height), Matrix.Invert(camera.get_transformation(worldViewport)));
            }
            else
                mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(worldViewport)));

            // follow a unit
            /*foreach (Unit unit in Unit.Units)
            {
                if (unit.Contains(mousePosition))
                {
                    foreach (Unit u in SelectedUnits)
                    {
                        if (u != unit)
                            u.FollowTarget = unit;
                        else if (SelectedUnits.Count == 1)
                            u.MoveTarget = mousePosition;
                    }
                    return;
                }
            }*/

            // set rally point if active type is rallyable
            setRallyPoint(mousePosition);

            if (giveHarvestCommand(mousePosition))
                return;

            bool attacking = false;
            // attack enemy
            foreach (RtsObject o in RtsObject.RtsObjects)
            {
                if (!o.Visible)
                    continue;

                if (o.Contains(mousePosition) && o.Team != Player.Me.Team)
                {
                    List<ScheduledUnitCommand> scheduledUnitCommands = new List<ScheduledUnitCommand>();

                    foreach (RtsObject ob in SelectedUnits)
                    {
                        if (ob.Team != Player.Me.Team)
                            break;

                        Unit u = ob as Unit;
                        if (u == null)
                            continue;

                        scheduledUnitCommands.Add(new ScheduledUnitCommand(currentScheduleTime, new AttackCommand(u, o, false, false), usingShift));
                        attacking = true;
                        //if (u.Team != o.Team)
                        //{
                        /*if (!usingShift)
                        {
                            AttackCommand command = new AttackCommand(u, o, false, false);
                            u.GiveCommand(command);
                            attacking = true;
                            //Rts.pathFinder.AddHighPriorityPathFindRequest(u, command, u.CurrentPathNode, (int)Vector2.DistanceSquared(u.CenterPoint, command.Destination), false);
                        }
                        else
                            u.QueueCommand(new AttackCommand(u, o, false, false));*/
                        //}
                    }

                    if (attacking)
                    {
                        if (scheduledUnitCommands.Count > 0)
                        {
                            scheduleAttackCommands(scheduledUnitCommands, o);

                            UnitAnimation redCircleAnimation = new UnitAnimation(o, o.Width, .75f, 8, false, redCircleTexture, transparentTexture);
                            redCircleAnimation.Start();
                        }
                    }
                    else
                    {
                        // give move command to units
                        giveMoveCommand(mousePosition);
                    }

                    return;
                }
            }

            // give move command to units
            giveMoveCommand(mousePosition);
        }
Ejemplo n.º 5
0
        void giveAttackCommand(Vector2 mousePosition)
        {
            foreach (RtsObject o in RtsObject.RtsObjects)
            {
                if (!o.Visible)
                    continue;

                if (o.Contains(mousePosition))
                {
                    List<ScheduledUnitCommand> scheduledUnitCommands = new List<ScheduledUnitCommand>();

                    foreach (RtsObject u in SelectedUnits)
                    {
                        if (u.Team != Player.Me.Team)
                            break;

                        Unit unit = u as Unit;
                        if (unit != null && unit != o)
                        {
                            /*if (!usingShift)
                            {
                                AttackCommand command = new AttackCommand(unit, o, false, false);
                                unit.GiveCommand(command);
                            }
                            else
                                unit.QueueCommand(new AttackCommand(unit, o, false, false));*/

                            scheduledUnitCommands.Add(new ScheduledUnitCommand(currentScheduleTime, new AttackCommand(unit, o, false, false), usingShift));
                        }
                    }

                    if (scheduledUnitCommands.Count > 0)
                    {
                        scheduleAttackCommands(scheduledUnitCommands, o);

                        UnitAnimation redCircleAnimation = new UnitAnimation(o, o.Width, .75f, 8, false, redCircleTexture, transparentTexture);
                        redCircleAnimation.Start();
                    }

                    return;
                }
            }

            //giveMoveCommand(mousePosition);
            giveAttackMoveCommand(mousePosition);
        }
Ejemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            int i = Player.Me.UnitArray.Length;

            // check for exit

            /*if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
             *  Game1.Game.Exit();
             * if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
             * {
             *  //Graphics.ToggleFullScreen();
             *  cleanup();
             *  returnControl("exit");
             *  return;
             * }*/

            //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size);
            Rts.gameTime = gameTime;

            if (!waitingForMessage)
            {
                GameClock += (float)gameTime.ElapsedGameTime.TotalSeconds * GameSpeed;
            }

            // count down
            if (doCountDown())
            {
                return;
            }

            // send time sync message if server
            checkToSync(gameTime);
            // just checkup if not server
            checkToCheckup(gameTime);

            // receive and process network messages
            receiveData(gameTime);

            // mute check
            checkForMute();

            // update mouse and keyboard state
            mouseState    = Mouse.GetState();
            keyboardState = Keyboard.GetState();

            // pause check

            /*if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.P))
             *  allowPause = true;
             * if (allowPause && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P))
             * {
             *  paused ^= true;
             *  allowPause = false;
             *  if (paused)
             *  {
             *      MediaPlayer.Volume /= 4;
             *      //GameTimer.Stop();
             *  }
             *  else
             *  {
             *      MediaPlayer.Volume *= 4;
             *      //GameTimer.Start();
             *  }
             * }*/

            // do cleanup of player unit/structure arrays
            Player.SetNullIDS();

            // pathfinding performance info
            if (Game1.DEBUG)
            {
                timeForPathFindingProfiling += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timeForPathFindingProfiling >= 500)
                {
                    double pathFindingTime;
                    lock (Rts.pathFinder.TimeSpentPathFindingLock)
                    {
                        pathFindingTime = Rts.pathFinder.TimeSpentPathFinding.TotalMilliseconds;
                        Rts.pathFinder.TimeSpentPathFinding = TimeSpan.Zero;
                    }
                    pathFindingPercentage       = pathFindingTime / timeForPathFindingProfiling * 100;
                    timeForPathFindingProfiling = 0;

                    lock (PathFindRequest.HighPriorityPathFindRequests)
                    {
                        pathFindQueueSize = PathFindRequest.HighPriorityPathFindRequests.Count;
                    }
                }
            }

            //update fps
            fpsElapsedTime += gameTime.ElapsedGameTime;
            if (fpsElapsedTime > TimeSpan.FromSeconds(1))
            {
                //Game1.Game.Window.Title = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL");
                fpsMessage = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL");
                if (Game1.DEBUG)
                {
                    fpsMessage += " - Unit count: " + Unit.Units.Count;
                }
                fpsElapsedTime -= TimeSpan.FromSeconds(1);
                frameCounter    = 0;
            }

            // do nothing else if paused
            if (paused)
            {
                return;
            }

            // input processing
            checkForShift(gameTime);
            checkForCommands();
            SimpleButton.UpdateAll(mouseState, keyboardState);
            checkHotKeyGroups(gameTime);

            checkForLeftClick(gameTime);
            checkForRightClick();
            checkForTab();

            checkForMouseCameraScroll(gameTime);
            checkForCameraZoom(gameTime);
            checkForCameraRotate(gameTime);
            if (keyboardState.IsKeyDown(Keys.Space))
            {
                centerCameraOnSelectedUnits();
            }
            clampCameraToMap();

            updatePlacingStructure();
            updatePlacedStructures();

            if (!placingStructure)
            {
                SelectBox.Update(worldViewport, camera);
            }

            Shrinker.UpdateShrinkers(gameTime);

            // do nothing else if waiting for message
            if (waitingForMessage)
            {
                return;
            }

            doScheduledActions();

            checkForUnitStatusUpdates(gameTime);
            checkForStructureStatusUpdates(gameTime);

            //update stats
            updateStats(gameTime);

            map.UpdateBoundingBoxes();

            updateCogWheels(gameTime);

            RtsBullet.UpdateAll(gameTime);

            Resource.UpdateResources(gameTime);
            Structure.UpdateStructures(gameTime);
            Unit.UpdateUnits(gameTime, netPeer, connection);
            UnitAnimation.UpdateAll(gameTime);

            removeDeadUnitsFromSelections();

            applyVisibilityToMap();
        }
Ejemplo n.º 7
0
        public override void Die()
        {
            base.Die();

            Player.Players[Team].CurrentSupply -= type.SupplyCost;

            UnitAnimation a = new UnitAnimation(this, Width, .5f, true, Unit.Explosion1Textures);
            a.Start();

            CurrentPathNode.UnitsContained.Remove(this);
            foreach (PathNode pathNode in OccupiedPathNodes)
                pathNode.UnitsContained.Remove(this);

            clearCommands();

            //Player.Players[Team].UnitArray[ID] = null;
            Player.Players[Team].UnitIDsToSetNull.Add(new KeyValuePair<short, float>(ID, Rts.GameClock));

            NetOutgoingMessage msg = Rts.netPeer.CreateMessage();
            msg.Write(MessageID.UNIT_DEATH);
            msg.Write(ID);
            msg.Write(Team);
            Rts.netPeer.SendMessage(msg, Rts.connection, NetDeliveryMethod.ReliableUnordered);
        }
Ejemplo n.º 8
0
 public void Die()
 {
     IsDead = true;
     if (this is Unit)
     {
         UnitAnimation a = new UnitAnimation((Unit)this, Width, .5f, true, Unit.Explosion1Textures);
         a.Start();
     }
 }
Ejemplo n.º 9
0
        public override void Die()
        {
            base.Die();

            if (!UnderConstruction)
                Player.Players[Team].MaxSupply -= type.Supply;

            foreach (Structure structure in Structures)
                structure.HasMoved = true;

            UnitAnimation a = new UnitAnimation(this, Width, .5f, true, Structure.Explosion1Textures);
            a.Start();

            foreach (PathNode node in OccupiedPathNodes)
            {
                node.Blocked = false;
                node.Blocker = null;
            }

            if (Builder != null)
            {
                releaseBuilder();
                ((Rts)Game1.Game.CurrentGameState).CheckForResetCommandCardWhenStructureCompletes(this);
                CogWheel = null;
            }

            Player.Players[Team].StructureIDsToSetNull.Add(new KeyValuePair<short, float>(ID, Rts.GameClock));

            NetOutgoingMessage msg = Rts.netPeer.CreateMessage();
            msg.Write(MessageID.STRUCTURE_DEATH);
            msg.Write(ID);
            msg.Write(Team);
            Rts.netPeer.SendMessage(msg, Rts.connection, NetDeliveryMethod.ReliableUnordered);
        }
Ejemplo n.º 10
0
Archivo: Rts.cs Proyecto: nubington/rts
        void giveAttackCommand(Vector2 mousePosition)
        {
            foreach (Unit unit in Unit.Units)
            {
                if (unit.Contains(mousePosition))
                {
                    UnitAnimation redCircleAnimation = new UnitAnimation(unit, unit.Width, .75f, 8, false, redCircleTexture, transparentTexture);
                    redCircleAnimation.Start();

                    foreach (Unit u in SelectedUnits)
                    {
                        if (u != unit)
                        {
                            if (keyboardState.IsKeyUp(Keys.LeftShift))
                            {
                                AttackCommand command = new AttackCommand(unit);
                                u.GiveCommand(command);
                                Unit.PathFinder.AddHighPriorityPathFindRequest(u, command, u.CurrentPathNode, (int)Vector2.DistanceSquared(u.CenterPoint, command.Destination), false);
                                //u.GiveCommand(new AttackCommand(unit));
                            }
                            else
                                u.QueueCommand(new AttackCommand(unit));
                        }
                    }
                    return;
                }
            }

            giveMoveCommand(mousePosition);
        }