Example #1
0
        public override void Draw(GameTimer gameTimer)
        {
            var playerRect = EntityUtility.GetEntityDrawRect(Player);

            Systems.RenderBackground(DrawableBackgroundGroup, Camera);

            SpriteBatch.Begin(SamplerType.Point, Camera.GetViewMatrix());
            Systems.Render(DrawableGroup, SpriteBatch);
            SpriteBatch.End();

            Systems.RenderMask(DrawableMaskGroup, Camera);
            Systems.RenderOverlay(DrawableOverlayGroup, Camera);

            SpriteBatch.Begin(SamplerType.Point);
            //SpriteBatch.DrawText(Font, playerRect.Location.ToString(), new Vector2(25), Veldrid.RgbaByte.White, 32, 1);
            SpriteBatch.End();

            if (ShowDebug)
            {
                DebugManager.Draw();
            }
        }
Example #2
0
        public override void Update(GameTimer gameTimer)
        {
            Systems.Physics(PhysicsGroup, ColliderGroup, gameTimer, GRAVITY, MOVE_STEP, DeathHeight);
            Systems.ColliderEvents(ColliderEventGroup);
            Systems.Death(DeathGroup);
            Systems.StartMovement(StartMovementGroup);
            Systems.StopMovement(StopMovementGroup);
            Systems.SpriteAnimation(SpriteAnimationGroup, gameTimer);
            Systems.PlayerAnimation(PlayerAnimationGroup);
            Systems.MovingPlatforms(MovingPlatformGroup, gameTimer);
            Systems.Recordings(RecordingsGroup, Player, this);

            // process removal queues for entities and components
            Registry.SystemsFinished();

            var playerRect = EntityUtility.GetEntityDrawRect(Player);

            Camera.Center(playerRect.Center);

            if (ShowDebug)
            {
                DebugManager.Update(gameTimer);
            }
        }
Example #3
0
        public static void GenerateLevel(GameStatePlay gameState)
        {
            var rng = new Random();
            var platformsPerRecording = 10;
            var platforms             = (platformsPerRecording * Recordings.Count) + platformsPerRecording;
            var jumpHeight            = 100;
            var jumpLength            = 200;
            var recordingIndex        = 0;

            var prevPlatformPosition = Vector2.Zero;
            var nextPlatformPosition = new Vector2(25, 500);
            var prevMovingPlatform   = false;

            for (var i = 0; i < platforms; i++)
            {
                var     platform = EntityBuilder.CreatePlatform(nextPlatformPosition, PlatformType.Normal);
                ref var drawable = ref platform.GetComponent <DrawableMaskComponent>();

                var drawRect = EntityUtility.GetEntityDrawRect(platform);
                if (drawRect.Bottom > gameState.DeathHeight)
                {
                    gameState.DeathHeight = drawRect.Bottom;
                }

                var platformSize      = drawable.AtlasRect.SizeF * drawable.Scale;
                var verticalDirection = rng.Next(0, 10) < 5 ? -1 : 1;
                var platformOffset    = new Vector2(platformSize.X + jumpLength, verticalDirection * (platformSize.Y + jumpHeight));
                var recordingPlatform = false;

                if (i > 0 && i % platformsPerRecording == 0 && recordingIndex < Recordings.Count)
                {
                    var data      = Recordings[recordingIndex];
                    var recording = EntityBuilder.CreateRecording(data.Asset, drawRect.LocationF, drawRect.LocationF + new Vector2(drawRect.Width / 2 - 200, -450f), recordingIndex == Recordings.Count - 1, recordingIndex == Recordings.Count - 2);
                    recordingIndex   += 1;
                    drawable.Color    = Veldrid.RgbaFloat.Green;
                    recordingPlatform = true;
                }

                if (i > 3 && rng.Next(0, 10) < 3)
                {
                    var secondVerticalDirection = prevPlatformPosition.Y < nextPlatformPosition.Y ? 1 : -1;

                    var secondPlatformPosition = prevPlatformPosition
                                                 + new Vector2(
                        (platformSize.X + jumpLength) / 2,
                        ((platformSize.Y + jumpHeight) / 2) * secondVerticalDirection);

                    EntityBuilder.CreatePlatform(secondPlatformPosition, PlatformType.Death);
                    prevMovingPlatform = false;
                }
                else if (i > 3 && rng.Next(0, 10) < 3 && !prevMovingPlatform && !recordingPlatform)
                {
                    var endPosition = nextPlatformPosition + new Vector2(platformOffset.X * 2f, 0);

                    platform.TryAddComponent(new MovingPlatformComponent()
                    {
                        StartPosition = nextPlatformPosition,
                        EndPosition   = endPosition,
                        Destination   = endPosition,
                        MoveSpeed     = 200,
                        BaseCooldown  = 2f,
                        Cooldown      = 2f,
                    });

                    ref var collider = ref platform.GetComponent <ColliderComponent>();
                    collider.EventType = ColliderEventType.MovingPlatform;

                    nextPlatformPosition = endPosition;
                    prevMovingPlatform   = true;
                }