Exemple #1
0
 public RtsBullet(Unit shooter, RtsObject target, Vector2 position, int size, float speed)
     : base(new Rectangle(0, 0, size, size), new Vector2(speed, speed))
 {
     this.shooter = shooter;
     this.target = target;
     CenterPoint = position;
     RtsBullets.Add(this);
 }
Exemple #2
0
 public UnitAnimation(Unit unit, int size, float duration, float fps, bool stayAfterDeath, Texture2D spriteSheet, int frameWidth, int frameHeight)
     : base(duration, fps, Util.SplitTexture(spriteSheet, frameWidth, frameHeight))
 {
     Unit = unit;
     Rectangle = new Rectangle(0, 0, size, size);
     Rectangle.Location = new Point((int)Unit.CenterPoint.X - Rectangle.Width / 2, (int)Unit.CenterPoint.Y - Rectangle.Height / 2);
     Rotation = Unit.Rotation;
     StayAfterDeath = stayAfterDeath;
     UnitAnimations.Add(this);
 }
Exemple #3
0
 public UnitAnimation(Unit unit, int size, float duration, float fps, bool stayAfterDeath, params Texture2D[] textures)
     : base(duration, fps, textures)
 {
     Unit = unit;
     Rectangle = new Rectangle(0, 0, size, size);
     Rectangle.Location = new Point((int)Unit.CenterPoint.X - Rectangle.Width / 2, (int)Unit.CenterPoint.Y - Rectangle.Height / 2);
     Rotation = Unit.Rotation;
     StayAfterDeath = stayAfterDeath;
     UnitAnimations.Add(this);
 }
Exemple #4
0
        public void Push(Unit pusher, float angle, float force)
        {
            pushCount++;
            float angleX = (float)Math.Cos(angle);
            float angleY = (float)Math.Sin(angle);

            CenterPoint += new Vector2(force * angleX, force * angleY);

            checkForWallHit();

            //if (isFollowing)
            //    return;

            lock (PotentialCollisionsLock)
            {
                foreach (Unit unit in PotentialCollisions)
                {
                    if (unit.pushCount < 1 && Intersects(unit))
                    {
                        angle = (float)Math.Atan2(unit.centerPoint.Y - centerPoint.Y, unit.centerPoint.X - centerPoint.X);

                        unit.Push(this, angle, force);
                        //unit.Push(this, angle, force * .1f);
                        //Push(unit, angle + (float)Math.PI, force * .9f);
                    }
                }
            }
        }
Exemple #5
0
 public bool Intersects(Unit u)
 {
     //if (radius == u.radius)
     //    return Vector2.DistanceSquared(centerPoint, u.centerPoint) < (radiusTimesTwoSquared);
     //else
         return Vector2.Distance(centerPoint, u.centerPoint) < (this.Radius + u.Radius);
 }
Exemple #6
0
 public static void RemoveUnit(Unit u)
 {
     lock (UnitsLock)
     {
         units.Remove(u);
     }
     lock (UnitsSortedLock)
     {
         unitsSorted.Remove(u);
     }
 }
Exemple #7
0
 public static void AddUnit(Unit u)
 {
     lock (UnitsLock)
     {
         units.Add(u);
     }
     lock (UnitsSortedLock)
     {
         unitsSorted.Add(u);
     }
 }
Exemple #8
0
 //public Object WayPointsLock = new Object();
 public PathFindRequest(Unit unit, MoveCommand command, PathNode startNode, bool avoidUnits)
 {
     Unit = unit;
     Command = command;
     StartNode = startNode;
     AvoidUnits = avoidUnits;
 }
Exemple #9
0
 public void NextWayPoint(Unit unit, PathFinder pathFinder)
 {
     WayPoints.RemoveAt(0);
     pathFinder.SmoothPath(WayPoints, unit);
 }
Exemple #10
0
        void drawSelectionRing(Unit unit, SpriteBatch spriteBatch, Color color)
        {
            selectionRingLine.Colour = color;

            selectionRingLine.Position = unit.CenterPoint;
            selectionRingLine.CreateCircle(unit.Radius, (int)Math.Round(unit.Radius * 2));
            selectionRingLine.Render(spriteBatch);
        }
Exemple #11
0
 void drawSelectingRing(Unit unit, SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(brownGuySelectingTexture, new Rectangle((int)unit.CenterPoint.X, (int)unit.CenterPoint.Y, unit.Width, unit.Height), null, Color.White, unit.Rotation, unit.TextureCenterOrigin, SpriteEffects.None, 0f);
 }
Exemple #12
0
        public override void Update(GameTime gameTime)
        {
            // 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("title");
                return;
            }

            // mute check
            checkForMute();

            // 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;
                else
                    MediaPlayer.Volume *= 4;
            }

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

            checkForCameraZoom();
            checkForCameraRotate();

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

            //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");
                fpsMessage += " - Unit count: " + Unit.Units.Count;
                fpsElapsedTime -= TimeSpan.FromSeconds(1);
                frameCounter = 0;
            }

            if (button1.Rectangle.Contains(mouseState.X, mouseState.Y) && mouseState.LeftButton == ButtonState.Pressed)
            {
                Unit brownGuy;
                brownGuy = new Unit(1, new Vector2(worldViewport.Width * .25f, worldViewport.Height / 2), ISAACSIZE, ISAACSPEED);
                brownGuy.Texture = brownGuyTexture;
                //brownGuy.AddWayPoint(new Vector2(Graphics.GraphicsDevice.Viewport.Width * .75f, Graphics.GraphicsDevice.Viewport.Height / 2));
                brownGuy.GiveCommand(new MoveCommand(new Vector2(worldViewport.Width * .75f, worldViewport.Height / 2), 1));
            }
            else if (button2.Rectangle.Contains(mouseState.X, mouseState.Y) && mouseState.LeftButton == ButtonState.Pressed)
            {
                for (int i = 0; i < 10; i++)
                {
                    Unit brownGuy;
                    brownGuy = new Unit(1, new Vector2(worldViewport.Width * .25f, worldViewport.Height / 2), ISAACSIZE, ISAACSPEED);
                    brownGuy.Texture = brownGuyTexture;
                    //brownGuy.AddWayPoint(new Vector2(Graphics.GraphicsDevice.Viewport.Width * .75f, Graphics.GraphicsDevice.Viewport.Height / 2));
                    brownGuy.GiveCommand(new MoveCommand(new Vector2(worldViewport.Width * .75f, worldViewport.Height / 2), 1));
                }
            }
            else if (button3.Rectangle.Contains(mouseState.X, mouseState.Y) && mouseState.LeftButton == ButtonState.Pressed)
            {
                Graphics.ToggleFullScreen();
                uiViewport = GraphicsDevice.Viewport;
                worldViewport = GraphicsDevice.Viewport;
                worldViewport.Height -= (minimapSize + minimapBorderSize * 2);
                GraphicsDevice.Viewport = worldViewport;
                initializeMinimap();
            }

            if (SelectedUnits.Count == 1)
            {
                Game1.Game.Window.Title = "idle: " + SelectedUnits[0].IsIdle + " hp: " + SelectedUnits[0].Hp + "/" +  SelectedUnits[0].MaxHp + ". position " + SelectedUnits[0].CenterPoint;
            }

            timeForPathFindingProfiling += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timeForPathFindingProfiling >= 1000)
            {
                double pathFindingTime;
                lock (Unit.PathFinder.TimeSpentPathFindingLock)
                {
                    pathFindingTime = Unit.PathFinder.TimeSpentPathFinding.TotalMilliseconds;
                    Unit.PathFinder.TimeSpentPathFinding = TimeSpan.Zero;
                }
                pathFindingPercentage = pathFindingTime / timeForPathFindingProfiling * 100;
                timeForPathFindingProfiling = 0;
            }

            checkForAttackCommand();

            Shrinker.UpdateShrinkers(gameTime);

            checkHotKeyGroups(gameTime);

            SelectBox.Update(worldViewport, camera);

            checkForLeftClick(gameTime);

            checkForRightClick();

            checkForStop();

            RtsBullet.UpdateAll(gameTime);

            Unit.UpdateUnits(gameTime);
            UnitAnimation.UpdateAll();

            removeDeadUnitsFromSelections();

            checkForMouseCameraScroll(gameTime);
            if (keyboardState.IsKeyDown(Keys.Space))
                centerCameraOnSelectedUnits();
            clampCameraToMap();
        }
Exemple #13
0
        void SelectUnits(GameTime gameTime)
        {
            //SelectBox.Box.CalculateCorners();

            int selectingUnitsCount = SelectingUnits.Count;
            SelectingUnits.Clear();

            timeSinceLastSimpleClick += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            bool simpleClick = (SelectBox.Box.GreaterOfWidthAndHeight <= simpleClickSize);

            if (SelectBox.IsSelecting)
            {
                selecting = true;
                unitsSelected = false;
                foreach (Unit unit in Unit.Units)
                {
                    if ((simpleClick && unit.Contains(Vector2.Transform(new Vector2(mouseState.X, mouseState.Y), Matrix.Invert(camera.get_transformation(worldViewport))))) ||
                            (!simpleClick && SelectBox.Box.Rectangle.Intersects(unit.Rectangle)))
                        SelectingUnits.Add(unit);
                }
            }
            else if (unitsSelected == false)
            {
                selecting = false;
                unitsSelected = true;

                // holding shift
                if (keyboardState.IsKeyDown(Keys.LeftShift))
                {
                    foreach (Unit unit in Unit.Units)
                    {
                        if ((simpleClick && unit.Contains(Vector2.Transform(new Vector2(mouseState.X, mouseState.Y), Matrix.Invert(camera.get_transformation(worldViewport))))) ||
                            (!simpleClick && SelectBox.Box.Rectangle.Intersects(unit.Rectangle)))
                        {
                            // holding ctrl or double click
                            if ((simpleClick && lastUnitClicked == unit && timeSinceLastSimpleClick <= doubleClickDelay) ||
                                (simpleClick && keyboardState.IsKeyDown(Keys.LeftControl)))
                            {
                                timeSinceLastSimpleClick = 0;

                                foreach (Unit u in Unit.Units)
                                    if (u.Type == unit.Type && !u.IsOffScreen(worldViewport, camera))
                                        SelectedUnits.Add(u);
                            }
                            // not holding ctrl or double click
                            else
                            {
                                if (!SelectedUnits.Contains(unit))
                                    SelectedUnits.Add(unit);
                                else if (simpleClick)
                                    SelectedUnits.Remove(unit);
                            }
                            lastUnitClicked = unit;
                        }
                    }
                }
                // not holding shift
                else
                {
                    SelectedUnits.Clear();

                    foreach (Unit unit in Unit.Units)
                    {
                        if ((simpleClick && unit.Contains(Vector2.Transform(new Vector2(mouseState.X, mouseState.Y), Matrix.Invert(camera.get_transformation(worldViewport))))) ||
                            (!simpleClick && SelectBox.Box.Rectangle.Intersects(unit.Rectangle)))
                        {
                            // holding ctrl or double click
                            if ((simpleClick && lastUnitClicked == unit && timeSinceLastSimpleClick <= doubleClickDelay) ||
                                (simpleClick && keyboardState.IsKeyDown(Keys.LeftControl)))
                            {
                                timeSinceLastSimpleClick = 0;

                                foreach (Unit u in Unit.Units)
                                    if (u.Type == unit.Type && !u.IsOffScreen(worldViewport, camera))
                                        SelectedUnits.Add(u);
                            }
                            // not holding ctrl or double click
                            else
                                SelectedUnits.Add(unit);

                            lastUnitClicked = unit;
                        }
                    }
                }
                if (simpleClick)
                    timeSinceLastSimpleClick = 0;
            }
        }
Exemple #14
0
 public bool IntersectsUnit(Unit u)
 {
     return Vector2.Distance(centerPoint, u.CenterPoint) < (collisionRadius + u.Radius);
 }