Exemple #1
0
        public void Input(TileMap tiles)
        {
            if (!m_moving)
            {
                //Get Keyboard state
                KeyboardState state = Keyboard.GetState();

                if (state.IsKeyDown(Keys.LeftShift))
                {
                    if (m_isRunning == false)
                    {
                        m_isRunning = true;
                    }
                    else
                    {
                        m_isRunning = false;
                    }
                    //Console.WriteLine("Running = ", m_isRunning);
                }


                //Get 2D position of player
                Vector2 position = tiles.ConvertTo2D(m_pos);

                bool pressed = false;

                if (state.IsKeyDown(Keys.Left))
                {
                    position = Move(DIR.Left, position);
                    pressed  = true;
                }
                if (state.IsKeyDown(Keys.Right))
                {
                    position = Move(DIR.Right, position);
                    pressed  = true;
                }
                if (state.IsKeyDown(Keys.Up))
                {
                    position = Move(DIR.Up, position);
                    pressed  = true;
                }
                if (state.IsKeyDown(Keys.Down))
                {
                    position = Move(DIR.Down, position);
                    pressed  = true;
                }

                if (pressed == true)
                {
                    //Check if movement it allowed before moving
                    if (tiles.CheckMap(position))
                    {
                        m_timeSoFar = 0.0f;
                        m_moving    = true;
                        m_posNew    = tiles.ConvertTo1D(Convert.ToInt32(position.X), Convert.ToInt32(position.Y));
                        //Sound
                        int tileType = tiles.CheckTileAt(m_pos);
                        switch (tileType)
                        {
                        case 0:     //Grass
                            m_musicMan.playMoveSound("grass01");
                            Console.WriteLine("Playing Sound: grass01");
                            break;

                        case 1:     //Sand
                            m_musicMan.playMoveSound("sand01");
                            Console.WriteLine("Playing Sound: sand01");
                            break;

                        case 2:     //Tree
                            //m_musicMan.playMoveSound("");
                            break;

                        case 3:     //Water
                            //m_musicMan.playMoveSound("");
                            break;

                        case 4:     //Grass
                            //m_musicMan.playMoveSound("");
                            break;
                        }

                        //testing sounds
                    }
                    //else
                    //Console.WriteLine(tiles.CheckMap(position));
                }

                //Console.WriteLine("Player is on tileNo : " + m_pos);
            }
        }
Exemple #2
0
        public void Input(TileMap tiles, Vector2 plrPos)
        {
            if (!m_moving)
            {
                Vector2 position = tiles.ConvertTo2D(m_pos);


                Vector2 PosLeft   = Move(DIR.Left, position);
                Vector2 PosRight  = Move(DIR.Right, position);
                Vector2 PosTop    = Move(DIR.Up, position);
                Vector2 PosBottom = Move(DIR.Down, position);

                if (PosLeft == position)
                {
                    PosLeft = new Vector2(9999, 9999);
                }
                if (PosRight == position)
                {
                    PosRight = new Vector2(9999, 9999);
                }
                if (PosTop == position)
                {
                    PosTop = new Vector2(9999, 9999);
                }
                if (PosBottom == position)
                {
                    PosBottom = new Vector2(9999, 9999);
                }

                double[] Directions = new double[4] {
                    CalcDistance(plrPos, PosLeft), CalcDistance(plrPos, PosRight), CalcDistance(plrPos, PosTop), CalcDistance(plrPos, PosBottom)
                };



                int LowestI = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (Directions[LowestI] > Directions[i])
                    {
                        LowestI = i;
                    }
                }
                Vector2 MoveDirection = position;
                if (CalcDistance(position, plrPos) > m_rangeAwayFromPlr)
                {
                    m_atRange = false;

                    switch (LowestI)
                    {
                    case 0:
                        MoveDirection = PosLeft;
                        break;

                    case 1:
                        MoveDirection = PosRight;
                        break;

                    case 2:
                        MoveDirection = PosTop;
                        break;

                    case 3:
                        MoveDirection = PosBottom;
                        break;
                    }



                    //Check if movement it allowed before moving
                    if (tiles.CheckMap(MoveDirection))
                    {
                        m_timeSoFar = 0.0f;
                        m_moving    = true;
                        m_posNew    = tiles.ConvertTo1D(Convert.ToInt32(MoveDirection.X), Convert.ToInt32(MoveDirection.Y));
                        Console.WriteLine("Enemy: " + LowestI);
                    }
                    else
                    {
                        Console.WriteLine("Enemy: " + tiles.CheckMap(MoveDirection));
                    }
                }
                else
                {
                    m_atRange = true;
                }
            }
        }