Example #1
0
        public int targeting(Turret[] targets)
        {
            double gap = distance(this.location,targets[0].location);
            double temp;
            int finalTarget = 0;
            for(int i = 0; i < targets.Length ; i++)
            {
                temp = distance(this.location, targets[i].location);

                if(temp < gap)
                {
                    gap = temp;
                    finalTarget = i;
                }
            }

            return finalTarget;
        }
Example #2
0
        //-----------------------------=Key examples=---------------------------
        /*
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            KeyboardState ks = Keyboard.GetState();
            //Player movement
            if (ks.IsKeyDown(Keys.Left))
                playerPosition.X--;

            if (ks.IsKeyDown(Keys.Right))
                playerPosition.X++;

            if (ks.IsKeyDown(Keys.Down))
                playerPosition.Y++;

            if (ks.IsKeyDown(Keys.Up))
                playerPosition.Y--;

            UpdateFogOfWar();

            //keyboard movements for map panning
            if (ks.IsKeyDown(Keys.Left))
            {
                Camera.Move(new Vector2(-2, 0));
            }

            if (ks.IsKeyDown(Keys.Right))
            {
                Camera.Move(new Vector2(2, 0));
            }

            if (ks.IsKeyDown(Keys.Up))
            {
                Camera.Move(new Vector2(0, -2));
            }

            if (ks.IsKeyDown(Keys.Down))
            {
                Camera.Move(new Vector2(0, 2));
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
             */
        /// <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.CornflowerBlue);

            // TODO: Add your drawing code here
            int squaresAcross = 18;
            int squaresDown = 38;

            // determines the order of view, with the "Painters algorithm"
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

            Vector2 firstSquare = new Vector2(Camera.Location.X / Tile.TileWidth, Camera.Location.Y / Tile.TileHeight);
            int firstX = (int)firstSquare.X;
            int firstY = (int)firstSquare.Y;

            Vector2 squareOffset = new Vector2(Camera.Location.X % Tile.TileWidth, Camera.Location.Y % Tile.TileHeight);
            int offsetX = (int)squareOffset.X;
            int offsetY = (int)squareOffset.Y;

            float maxdepth = ((myMap.MapWidth + 1) + ((myMap.MapHeight + 1) * Tile.TileWidth)) * 10;
            float depthOffset;
            //Drawing vlad behind terrain
            Point vladMapPoint = myMap.WorldToMapCell(new Point((int)vlad.Position.X, (int)vlad.Position.Y));

            //The draw of Base, then Height, THEN topper tiles
            for (int y = 0; y < squaresDown; y++)
            {
                int rowOffset = 0;
                if ((firstY + y) % 2 == 1)
                    rowOffset = Tile.OddRowXOffset;

                for (int x = 0; x < squaresAcross; x++)
                {
                    int mapx = (firstX + x);
                    int mapy = (firstY + y);
                    depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth);

                    if ((mapx >= myMap.MapWidth) || (mapy >= myMap.MapHeight))
                        continue;
                    //Base Tiles
                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].BaseTiles)
                    {
                        spriteBatch.Draw(

                            Tile.TileSetTexture,
                            Camera.WorldToScreen(

                                new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            1.0f,
                            SpriteEffects.None,
                            1.0f);
                    }
                    int heightRow = 0;
                    //Height Tiles
                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].HeightTiles)
                    {
                        spriteBatch.Draw(
                            Tile.TileSetTexture,
                            Camera.WorldToScreen(
                                new Vector2(
                                    (mapx * Tile.TileStepX) + rowOffset,
                                    mapy * Tile.TileStepY - (heightRow * Tile.HeightTileOffset))),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            1.0f,
                            SpriteEffects.None,
                            depthOffset - ((float)heightRow * heightRowDepthMod));
                        heightRow++;
                    }
                    //TOPPER TILES (RIVERS)
                    foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].TopperTiles)
                    {
                        spriteBatch.Draw(
                            Tile.TileSetTexture,
                            Camera.WorldToScreen(
                                new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            1.0f,
                            SpriteEffects.None,
                            depthOffset - ((float)heightRow * heightRowDepthMod));
                    }
                    //drawing vlad behind terrain
                    if ((mapx == vladMapPoint.X) && (mapy == vladMapPoint.Y))
                    {
                        vlad.DrawDepth = depthOffset - (float)(heightRow + 2) * heightRowDepthMod;
                    }
                    // TO DO DRAWING turrets behind terrain/people
                    //if (())
                }
            }

            //Draws character
            spriteBatch.Draw(playerTexture, playerPosition - Camera.location , Color.White);

            //Animated sprite example (keeps vlad within the screen)
            Point vladStandingOn = myMap.WorldToMapCell(new Point((int)vlad.Position.X, (int)vlad.Position.Y));
            int vladHeight = myMap.Rows[vladStandingOn.Y].Columns[vladStandingOn.X].HeightTiles.Count * Tile.HeightTileOffset;
            vlad.Draw(spriteBatch, 0, -myMap.GetOverallHeight(vlad.Position));
            zombie.Draw(spriteBatch, 0, -myMap.GetOverallHeight(zombie.Position));

            //Drawing emitted view light
            /*
            spriteBatch.Draw(lightAura,
            new Rectangle(
            (int)playerPosition.X - (lightAura.Width / 2),
            (int)playerPosition.Y - (lightAura.Height / 2),
            lightAura.Width, lightAura.Height),
            Color.White);
            */

            //necessary end to Draw section of code
            Vector2 hilightLoc = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
            Point hilightPoint = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));

            int hilightrowOffset = 0;
            if ((hilightPoint.Y) % 2 == 1)
                hilightrowOffset = Tile.OddRowXOffset;

            spriteBatch.Draw(
                            hilight,
                            Camera.WorldToScreen(
                                new Vector2(
                                    (hilightPoint.X * Tile.TileStepX) + hilightrowOffset,

                                    (hilightPoint.Y + 2) * Tile.TileStepY)),
                            new Rectangle(0, 0, 64, 32),
                            Color.White * 0.3f,
                            0.0f,
                            Vector2.Zero,
                            1.0f,
                            SpriteEffects.None,
                            0.0f);

            //----------------------------------=Sprite Generation=--------------------------------------
            //adding a new turret if click
            if(mouseStateCurrent.LeftButton == ButtonState.Pressed)
            {
                Vector2 location = Camera.WorldToScreen(
                                new Vector2(
                                    (hilightPoint.X * Tile.TileStepX) + hilightrowOffset + 15, (hilightPoint.Y + 2) * Tile.TileStepY - 10));

                myMap.GetCellAtWorldPoint(new Vector2(location.X + (Tile.TileStepX * 1), location.Y + (Tile.TileStepY * 6))).Walkable = false;

                defenses[defense_index] = new Turret(location);

                defense_index++;
            }

            //------------------------------------=DRAWING=----------------------------------------------
            //drawing turrets
            for (int i = 0; i < defenses.Length; i++ )
            {
                if(defenses[i] != null)
                {
                    spriteBatch.Draw(spotlight, defenses[i].location - Camera.location, Color.White);
                }
            }

            /*
            for (int i = 0; i < monsters.Length; i++ )
            {
                if(monsters[i] != null)
                {
                    spriteBatch.Draw(zombie, monsters[i].location - Camera.location, Color.White);

                }
            }
            */

                // doubling max amount of turrets if capacity is reached
                if (defense_index == defenses.Length)
                {
                    Turret[] temp = new Turret[defenses.Length * 2];
                    for (int i = 0; i < defenses.Length; i++)
                    {
                        temp[i] = defenses[i];
                    }
                    defenses = temp;
                }

            spriteBatch.End();

            base.Draw(gameTime);
        }