示例#1
0
文件: Game.cs 项目: romcq/FirstGame
        public void Interactions()
        {
            map     = new MapChanges();
            player  = new Player();
            physics = new Physics();

            Width  = (MapChanges.mapWidth + 5) * 20;
            Height = (MapChanges.mapHeight + 2) * 20;


            timer1.Interval = 1;

            player.score    = 0;
            player.lives    = 10;
            scoreLabel.Text = $"Счёт: {player.score}";
            livesLabel.Text = $"Жизни: {player.lives}";
            for (int i = 0; i < MapChanges.mapHeight; i++)
            {
                for (int j = 0; j < MapChanges.mapWidth; j++)
                {
                    map.map[i, j] = 0;
                }
            }

            player.platformX = (MapChanges.mapWidth - 1) / 2 * 20;
            player.platformY = (MapChanges.mapHeight - 1) * 20;

            map.map[player.platformY / 20, player.platformX / 20]     = 9;
            map.map[player.platformY / 20, player.platformX / 20 + 1] = 99;
            map.map[player.platformY / 20, player.platformX / 20 + 2] = 999;

            player.ballY = 300;
            player.ballX = 300;

            map.map[player.ballY / 20, player.ballX / 20] = 8;

            player.directionX = 1;
            player.directionY = -1;

            GenerationOfPlatforms();

            timer1.Start();
            timer2.Start();
        }
示例#2
0
        public bool IsCollide(Player player, MapChanges map, Label scoreLabel)
        {
            var isColliding = false;

            if ((player.ballX / 20) + player.directionX > MapChanges.mapWidth - 1 || (player.ballX / 20) + player.directionX < 0)
            {
                player.directionX *= -1;
                isColliding        = true;
            }
            if ((player.ballY / 20) + player.directionY < 0)
            {
                player.directionY *= -1;
                isColliding        = true;
            }

            if (map.map[(player.ballY / 20) + player.directionY, player.ballX / 20] != 0)
            {
                var addScore = false;
                isColliding = true;

                if (map.map[(player.ballY / 20) + player.directionY, player.ballX / 20] > 10 && map.map[(player.ballY / 20) + player.directionY, player.ballX / 20] < 99)
                {
                    map.map[(player.ballY / 20) + player.directionY, player.ballX / 20]       = 0;
                    map.map[(player.ballY / 20) + player.directionY, (player.ballX / 20) - 1] = 0;
                    addScore = true;
                }
                else if (map.map[(player.ballY / 20) + player.directionY, player.ballX / 20] < 9)
                {
                    map.map[(player.ballY / 20) + player.directionY, player.ballX / 20]       = 0;
                    map.map[(player.ballY / 20) + player.directionY, (player.ballX / 20) + 1] = 0;
                    addScore = true;
                }
                if (addScore)
                {
                    player.score += 50;
                    if (player.score % 300 == 0 && player.score > 0)
                    {
                        map.AddLine();
                    }
                }
                player.directionY *= -1;
            }
            if (map.map[player.ballY / 20, (player.ballX / 20) + player.directionX] != 0)
            {
                var addScore = false;
                isColliding = true;

                if (map.map[player.ballY / 20, (player.ballX / 20) + player.directionX] > 10 && map.map[(player.ballY / 20) + player.directionY, player.ballX / 20] < 99)
                {
                    map.map[player.ballY / 20, (player.ballX / 20) + player.directionX]     = 0;
                    map.map[player.ballY / 20, (player.ballX / 20) + player.directionX - 1] = 0;
                    addScore = true;
                }
                else if (map.map[player.ballY / 20, (player.ballX / 20) + player.directionX] < 9)
                {
                    map.map[player.ballY / 20, (player.ballX / 20) + player.directionX]     = 0;
                    map.map[player.ballY / 20, (player.ballX / 20) + player.directionX + 1] = 0;
                    addScore = true;
                }
                if (addScore)
                {
                    player.score += 50;
                    if (player.score % 300 == 0 && player.score > 0)
                    {
                        map.AddLine();
                    }
                }
                player.directionX *= -1;
            }
            scoreLabel.Text = $"Счёт: {player.score}";

            return(isColliding);
        }