Example #1
0
        public void findClosestCreep(GameTime gameTime, Tower tower, Game1 game)
        {
            //search the path and choose the closest creep to the towers position
            int xDiff = 1000;
            int yDiff = 1000;
            int tempX = 0;
            int tempY = 0;
            int crPos = 0;
            if (gameTime.TotalGameTime.TotalSeconds > tower.seconds)
            {

                for (int x = 0; x < game.Creeps.Count; x++)
                {
                    tempX = Math.Abs((int)(tower.pos.X - game.Creeps.ElementAt(x).pos.X));
                    tempY = Math.Abs((int)(tower.pos.Y - game.Creeps.ElementAt(x).pos.Y));
                    if ((tempX <= xDiff) && (tempY <= yDiff))
                    {
                        xDiff = tempX;
                        yDiff = tempY;
                        crPos = x;
                        System.Diagnostics.Debug.WriteLine("JONO!");
                        System.Diagnostics.Debug.WriteLine(tempX);
                        System.Diagnostics.Debug.WriteLine(tempY);
                    }

                }
                tower.seconds = (int)(gameTime.TotalGameTime.TotalSeconds + tower.Speed);
                Shoot(game.Creeps.ElementAt(crPos), game, tower);

            }
        }
Example #2
0
        public void HandleInput(float dt, GameTime gameTime)
        {
            Game1 game = Game as Game1;
            if (game.Creeps.Count > 0)
            {
                moveCreep(gameTime, game);
                for (int x=0;x<game.Towers.Count;x++)
                {
                    findClosestCreep(gameTime,game.Towers.ElementAt(x), game);
                }
            }
            if (this.count < 1)
            {
                drawRandomTiles(game);
                this.count++;
                //create practuse creep at start of path

            }
            vec = new Vector2(game.Path.ElementAt(0).X, game.Path.ElementAt(0).Y);
            spawnCreep(gameTime, vec, game);

            KeyboardState keyboardState = game.keyboardState;
            MouseState mouseState = game.mouseState;

            float xDifference = mouseState.X - 200;
            float yDifference = mouseState.Y - 200;

            //Mouse.SetPosition(200, 200);

            #region 1-5 key binds

            //Ball Selected
            if (keyboardState.IsKeyDown(Keys.D1))
            {
                game.towerType = 1;
            }
            //Handgun Selected
            if (keyboardState.IsKeyDown(Keys.D2))
            {
                game.towerType = 2;
            }

            #endregion

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                if (allowedToClick)
                {
                    mPressed = true;
                }

            }

            newState = Keyboard.GetState();
            //pressed = KeypressTest(Keys.LeftAlt);
            //if left alt key pressed
             if (newState.IsKeyUp(Keys.LeftAlt) && oldState.IsKeyDown(Keys.LeftAlt))
             {
                 if (isTower)
                 {
                     isTower = false;
                     isTile = true;
                 }
                 else if (isTile)
                 {
                     isTile = false;
                     isTower = true;
                 }
             }
             oldState = newState;

            Vector2 tempMouse;
            Tower tower;
            //Tile tile ;
            bool valid = false;
            int count = 0;
            if (mouseState.LeftButton == ButtonState.Released)
            {
                if (mPressed == true)
                {
                    if (isTower || isTile)
                    {
                        //Box toAdd = new Box(camera.position, 1, 1, 1, 1);
                        mPressed = false;
                        tempMouse = new Vector2(mouseState.X - mouseState.X % Game1.SCALE, mouseState.Y - mouseState.Y % Game1.SCALE);

                        foreach (Tower t in game.Towers)
                        {
                            if (t.pos.Equals(tempMouse))
                                valid = true;
                            count++;

                        }
                        if (!valid)
                        {
                            foreach (Tile tt in game.Tiles)
                            {
                                if (tt.pos.Equals(tempMouse))
                                    valid = true;
                                count++;

                            }
                        }
                        //game.test = new Tower(new Vector2(mouseState.X, mouseState.Y), game.tex, game);

                        //TODO
                        //check if tower not already in same place / if NOT on path
                        if (!valid)
                        {
                            if (isTower)
                            {
                                tower = new Tower(tempMouse, game.texTower, game);
                                if (game.money >= 50)
                                {
                                    game.Towers.Add(tower);
                                    game.money -= 50;
                                }
                            }
                            if (isTile)
                            {
                                this.tile = new Tile(tempMouse, game.texTile, game);
                                if (game.money >= 50)
                                {
                                    game.Tiles.Add(this.tile);
                                    game.money -= 50;
                                }
                            }

                        }
                        allowedToClick = false;
                        timer = 0f;
                    }

                }
            }

                //Scoot the camera around depending on what keys are pressed.

                /*
                if (keyboardState.IsKeyDown(Keys.W))
                    camera.MoveForward(dt);
                if (keyboardState.IsKeyDown(Keys.S))
                    camera.MoveForward(-dt);
                if (keyboardState.IsKeyDown(Keys.D))
                    camera.MoveRight(dt);
                if (keyboardState.IsKeyDown(Keys.A))
                    camera.MoveRight(-dt);
                if (keyboardState.IsKeyDown(Keys.Space))
                    camera.MoveUp(dt);
                if (keyboardState.IsKeyDown(Keys.C))
                    camera.MoveUp(-dt);
                */
        }
Example #3
0
 public void Shoot(Creep cr,Game1 game,Tower tower)
 {
     System.Diagnostics.Debug.WriteLine("HERE!");
     Projectile p = new Projectile(tower.pos, game.texProj, game);
     //p.Damage = this.Damage;
     //p.Speed = this.Speed;
     p.Damage = 5;
     p.Speed = 2;
     p.setCreep(cr);
     game.Projs.Add(p);
 }
Example #4
0
 public void DrawT(Tower x)
 {
 }