chore: Object Sizing And Positioning & Fullscreen

This commit is contained in:
Syntriax 2023-11-27 15:14:26 +03:00
parent 06af246a5e
commit 1c248c0e97
2 changed files with 22 additions and 14 deletions

2
Engine

@ -1 +1 @@
Subproject commit 9f4ad882e3db456d68dbc85b1e37c2a4e8bf150f
Subproject commit d2881e94df2796174795e5ef04b057ac6580bda3

View File

@ -42,32 +42,32 @@ public class Game1 : Game
IGameObject gameObjectCamera = gameManager.InstantiateGameObject<GameObject>();
gameObjectCamera.Name = "Camera";
gameObjectCamera.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f);
gameObjectCamera.Transform.Position = Vector2.Zero;
gameManager.Camera = gameObjectCamera.BehaviourController.AddBehaviour<CameraBehaviour>();
gameManager.Camera.Viewport = GraphicsDevice.Viewport;
IGameObject gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
gameObjectBall.Name = "Ball";
gameObjectBall.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f);
gameObjectBall.Transform.Scale = new Vector2(.025f, .025f);
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .1f), 100f);
gameObjectBall.Transform.Position = Vector2.Zero;
gameObjectBall.Transform.Scale = new Vector2(1f / 51.2f, 1f / 51.2f);
// gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .1f), 100f);
gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
IGameObject gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
gameObjectLeft.Name = "Left";
gameObjectLeft.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f);
gameObjectLeft.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f);
gameObjectLeft.Transform.Position = new Vector2(-350f, 0f);
gameObjectLeft.Transform.Scale = new Vector2(10f, 40f);
gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 200f);
gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 400f);
gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
gameObjectRight.Name = "Right";
gameObjectRight.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f);
gameObjectRight.Transform.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f);
gameObjectRight.Transform.Position = new Vector2(350f, 0f);
gameObjectRight.Transform.Scale = new Vector2(10f, 40f);
gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 200f);
gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 400f);
gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
// TODO: use this.Content to load your game content here
}
@ -79,17 +79,25 @@ public class Game1 : Game
if (Keyboard.GetState().IsKeyDown(Keys.F))
{
if (_graphics.IsFullScreen)
return;
_graphics.PreferMultiSampling = false;
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.IsFullScreen = true;
_graphics.ApplyChanges();
float previousScreenSize = MathF.Sqrt(MathF.Pow(gameManager.Camera.Viewport.Width, 2f) + MathF.Pow(gameManager.Camera.Viewport.Height, 2f));
float currentScreenSize = MathF.Sqrt(MathF.Pow(GraphicsDevice.Viewport.Width, 2f) + MathF.Pow(GraphicsDevice.Viewport.Height, 2f));
gameManager.Camera.Zoom /= previousScreenSize / currentScreenSize;
gameManager.Camera.Viewport = GraphicsDevice.Viewport;
}
if (Keyboard.GetState().IsKeyDown(Keys.U))
{
gameManager.Camera.Zoom += gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
}
gameManager.Camera.Zoom += gameTime.ElapsedGameTime.Nanoseconds * 0.00025f;
if (Keyboard.GetState().IsKeyDown(Keys.J))
gameManager.Camera.Zoom -= gameTime.ElapsedGameTime.Nanoseconds * 0.00025f;
if (Keyboard.GetState().IsKeyDown(Keys.Q))
gameManager.Camera.Rotation += gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;