Beispiel #1
0
 //creates a new player to a given (x,y) position
 public Player(int x, int y, int width, int height, string n, Map m, bool computer, int aiLevel, Pills pills)
 {
     position = new Rectangle(x, y, 32, 32);
     startPosition = position;
     direction = new Vector2(x, y);
     map = m;
     name = n;
     screenWidth = width;
     screenHeight = height;
     score = 0;
     speed = 8;
     stuckTimer = 0;
     inputEnabled = true;
     towardsOneWay = false;
     playerIsAI = computer;
     ai = new AI(aiLevel, pills);
 }
Beispiel #2
0
        //creates given amount of new pills to random positions, requires also screen size and pill texture's size
        public Pills(Map map, int numberOfPills, int screenWidth, int screenHeight, int pillSize)
        {
            list = new List<Pill>();
            Random random = new Random();
            int maxWidth = screenWidth - pillSize;
            int maxHeight = screenHeight - pillSize;
            Rectangle position;

            for (int i = 0; i < numberOfPills; i++)
                {
                position = new Rectangle(random.Next(maxWidth), random.Next(maxHeight), pillSize, pillSize);
                while (map.intersectsWithAWall(position, ""))
                    {
                    position = new Rectangle(random.Next(maxWidth), random.Next(maxHeight), pillSize, pillSize);
                    }
                list.Add(new Pill(position));
                }
        }
        //creates a new gameplay screen
        public GameplayScreen(string player1Name, string player2Name, string nameOfTheMap, 
            bool player1IsAI, bool player2IsAI, int player1AILevel, int player2AILevel)
        {
            //times for the transition
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            //sets the escape-key as the pause button and enter as the restart game button
            pauseAction = new InputAction(new Keys[] { Keys.Escape }, true);
            endGameAction = new InputAction(new Keys[] { Keys.Enter }, true);

            screenWidth = 1024;
            screenHeight = 768;

            p1name = player1Name;
            p2name = player2Name;
            mapName = nameOfTheMap;
            p1ai = player1IsAI;
            p2ai = player2IsAI;
            p1aiLevel = player1AILevel;
            p2aiLevel = player2AILevel;

            clock = new Timer(20.0f);
            //fps = new FPS(screenWidth);
            map = new Map(mapName);
            pills = new Pills(map, 100, screenWidth, screenHeight, 32);
            player1 = new Player(0, 0, screenWidth, screenHeight, p1name, map, p1ai, p1aiLevel, pills);
            player2 = new Player(screenWidth - 32, screenHeight - 32, screenWidth, screenHeight, p2name, map, p2ai, p2aiLevel, pills);
            scores = new Scores(screenWidth);
            controls = new PlayerControls();
            gameEnds = false;
        }