Ejemplo n.º 1
0
        public void scaled_position_assignment()
        {
            var gameCanvas  = new GameViewport(new Point(800, 600), ResizeBehavior.KeepAspectRatio);
            var sceneLayers = new SceneLayers(gameCanvas);
            var scene       = sceneLayers.AddNewScene();

            scene.camera.Zoom = 2.6f;

            scene.camera.ScaledPosition = new Point(scene.camera.ScaledPosition.X, 237);

            scene.camera.ScaledPosition.Y.Should().Be(237);
        }
Ejemplo n.º 2
0
 private void formSetup(Form f)
 {
     gameViewport        = new GameViewport(75, null);
     this.containingForm = f;
     f.ClientSize        = new Size(600, 450);
     f.FormBorderStyle   = FormBorderStyle.Sizable;
     f.MaximizeBox       = false;
     f.MinimizeBox       = false;
     f.MaximumSize       = new Size(1200, 900);
     f.MinimumSize       = new Size(480, 320);
     f.Text            = "K2D 0.0.b";
     f.Resize         += f_Resized;
     f.FormClosing    += f_FormClosing;
     gameViewport.Dock = DockStyle.Fill;
     f.Controls.Add(gameViewport);
     f.Show();
 }
Ejemplo n.º 3
0
        public void game_canvas_maintain_desired_resolution_pinning()
        {
            var desiredSize            = new Point(300, 200);
            var gameCanvas             = new GameViewport(desiredSize, ResizeBehavior.KeepAspectRatio);
            var windowSizeBeforeResize = gameCanvas.WindowSize;
            var canvasRectBeforeResize = gameCanvas.CanvasRect;
            var newSize = new Point(500, 500);

            gameCanvas.SetWindowSize(newSize);

            Assert.Equal(desiredSize, windowSizeBeforeResize); // Window size matches desired size before resize
            Assert.Equal(newSize, gameCanvas.WindowSize);      // Window size is new size after resize
            Assert.Equal(1.6666666f, gameCanvas.ScaleFactor);  // Scale factor adjusts to new window size
            Assert.Equal(windowSizeBeforeResize,
                         canvasRectBeforeResize.Size);         // Canvas size before resize matches window size
            Assert.Equal(new Rectangle(0, 83, 500, 333), gameCanvas.CanvasRect);
        }
Ejemplo n.º 4
0
        public void mouse_position_transform_integration()
        {
            var gameCanvas  = new GameViewport(new Point(800, 600), ResizeBehavior.KeepAspectRatio);
            var sceneLayers = new SceneLayers(gameCanvas);
            var scene       = sceneLayers.AddNewScene();

            scene.camera.ScaledPosition = new Point(120, 240);
            scene.camera.Zoom           = 2.6f;

            var savedPosition      = Vector2.Zero;
            var savedPositionDelta = Vector2.Zero;
            var savedRawDelta      = Vector2.Zero;

            new MouseHarnessComponent(scene.AddActor("Mouse Harness"), (currentPosition, positionDelta, rawDelta) =>
            {
                savedPosition      = currentPosition;
                savedPositionDelta = positionDelta;
                savedRawDelta      = rawDelta;
            });

            // Resize to a huge resolution that's a different aspect ratio so we can get a worst-case transform scenario
            gameCanvas.SetWindowSize(new Point(1920, 1080));
            var prevPos    = new Point(200, 200);
            var newPos     = new Point(220, 250);
            var mouseDelta = (newPos - prevPos).ToVector2();

            sceneLayers.Update(0, Matrix.Identity,
                               new InputFrameState(KeyboardFrameState.Empty,
                                                   new MouseFrameState(MouseButtonList.None, MouseButtonList.None, new Point(200, 200), Vector2.Zero,
                                                                       0)));
            sceneLayers.Update(0, Matrix.Identity,
                               new InputFrameState(KeyboardFrameState.Empty,
                                                   new MouseFrameState(MouseButtonList.None, MouseButtonList.None, new Point(220, 250), mouseDelta,
                                                                       0)));

            Assert.Equal(new Point(115, 292), savedPosition.ToPoint());            // Mouse Position, this used to be (361, 478), but after I made the zoom/pan change it changed. I think that's on purpose
            Assert.Equal(new Vector2(4.2735047f, 10.683762f), savedPositionDelta); // Mouse Position Delta
            Assert.Equal(new Vector2(20, 50), savedRawDelta);                      // Mouse raw delta
        }
Ejemplo n.º 5
0
        public void ResetGame()
        {
            gameProgress = 0;
            elapsedTimeSinceLastPowerUp = 0.0f;
            cloudOffsets = Vector2.Zero;

            Components.Clear();

            world = new World(new Vector2(0, 25));

            staticWorldGround = BodyFactory.CreateRectangle(world, worldWidthInBlocks, 1, 1.0f, new Vector2(worldWidthInBlocks / 2.0f, 0.5f));
            staticWorldL = BodyFactory.CreateRectangle(world, 4, worldHeightInBlocks, 1.0f, new Vector2(2.0f, -worldHeightInBlocks / 2.0f));
            staticWorldR = BodyFactory.CreateRectangle(world, 1, worldHeightInBlocks, 1.0f, new Vector2(worldWidthInBlocks, -worldHeightInBlocks / 2.0f));
            staticWorldGround.BodyType = BodyType.Static;
            staticWorldL.BodyType = BodyType.Static;
            staticWorldR.BodyType = BodyType.Static;
            staticWorldGround.Friction = 100.0f;
            staticWorldL.Friction = 100.0f;
            staticWorldR.Friction = 100.0f;
            staticWorldGround.CollisionCategories = COLLISION_GROUP_STATIC_OBJECTS;
            staticWorldL.CollisionCategories = COLLISION_GROUP_LEVEL_SEPARATOR;
            staticWorldR.CollisionCategories = COLLISION_GROUP_LEVEL_SEPARATOR;

            tetris = new TetrisPlayer(this, world);
            Components.Add(tetris);

            Components.Add(platform = new PlatformPlayer(this, world));

            // Create other level components
            WaterLayer = new WaterLayer(this);
            SavePlatform = new SavePlatform(this);
            Components.Add(SavePlatform);
            Components.Add(WaterLayer);

            waveLayer = new WaveLayer(this);
            Components.Add(waveLayer);

            titleScreenLayer = new TitleScreenLayer(this);
            gameOverLayer = new GameOverLayer(this);

            tetrisViewport = new GameViewport(this, gameBlockSizeTetris);
            tetrisViewport.resize(1280, 720);
            tetris.viewportToSpawnIn = tetrisViewport;

            Components.Add(tetrisViewport);

            // Add GUI components
            StatusLayer = new GameStatusLayer(this);
            Components.Add(StatusLayer);

            MusicManager.StopMusic();
        }