Exemple #1
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>

        public Player(Level level, Vector2 start, ReplayData replay)
        {
            this.replayData = new ReplayData();

            int positionsToCreate = (replay == null ? 0 : replay.StreamCount);

            this.ghostData = replay;
            for (int i = 0; i <= positionsToCreate; i++)
            {
                this.sprites.Add(new AnimationPlayer());
                this.playerPositions.Add(Vector2.Zero);
                this.playerVelocities.Add(Vector2.Zero);
                this.isOnGround.Add(true);
                this.previousBottom.Add(0.0f);
                this.jumpTime.Add(0.0f);
                this.isJumping.Add(false);
                this.wasJumping.Add(false);
                this.movement.Add(0.0f);
                this.flips.Add(true);
                this.playerStates.Add(PlayerState.Alive);
            }

            this.level = level;

            LoadContent();

            Reset(null, start);
        }
Exemple #2
0
        private static void downloader_DoWork(object sender, DoWorkEventArgs e)
        {
            int levelId = (int)e.Argument;

            SaveFileFromURL(String.Format(BEST_REPLAY_URL, levelId),
                            String.Format("{0}.replay", levelId.ToString("D4")), 5);



            String fileName = levelId.ToString("D4") + ".replay";

            if (File.Exists(fileName))
            {
                JsonSerializer serializer = new JsonSerializer();
                using (FileStream fs = new FileStream(fileName, FileMode.Open))
                {
                    using (GZipStream compressionStream = new GZipStream(fs, CompressionMode.Decompress))
                    {
                        using (BsonReader reader = new BsonReader(compressionStream))
                        {
                            ReplayData result = serializer.Deserialize <ReplayData>(reader);
                            result.nextPlayerCursors = new List <int>(result.PlayerHistory.Count);
                            result.lastResults       = new List <PlayerGhostData>(result.PlayerHistory.Count);

                            for (int i = 0; i < result.PlayerHistory.Count; i++)
                            {
                                result.nextPlayerCursors.Add(0);
                                result.lastResults.Add(PlayerGhostData.NoMovement);
                            }
                            e.Result = result;
                        }
                    }
                }
            }
            else
            {
                e.Result = null;
            }
        }
Exemple #3
0
        public Level(IServiceProvider serviceProvider, LevelData levelData)
        {
            LevelData = levelData;

            IsLoading = true;


            // Create a new content manager to load content used just by this level.
            content = new ContentManager(serviceProvider, "Content");

            // Load background layer textures. For now, all levels must
            // use the same backgrounds and only use the left-most part of them.
            // this is needed while loading so lead ahead
            layers = new Texture2D[3];
            for (int i = 0; i < layers.Length; ++i)
            {
                // Choose a random segment if each background layer for level variety.
                int segmentIndex = (levelData.Id - 1) % 3; // we only have 3 backgrounds
                layers[i] = Content.Load <Texture2D>("Backgrounds/Layer" + i + "_" + segmentIndex);
            }

            // this is needed while loading...
            loadingOverlay = Content.Load <Texture2D>("Overlays/loading");

            // Load sounds.
            exitReachedSound = Content.Load <SoundEffect>("Sounds/ExitReached");

            // try to download and then load the replay data, asynchronously
            ReplayData.DownloadAndLoadRecordedDataAsync(this.LevelData.Id, (sender, e) =>
            {
                replayData = (ReplayData)e.Result;
                // load the level and instantiate the player with replay data
                LoadTiles(LevelData.Content);
                IsLoading = false;
            });

            timeRemaining = TimeSpan.FromSeconds(25);
        }