feat: Added Camera

This commit is contained in:
Syntriax 2023-11-27 13:46:21 +03:00
parent e134192187
commit 06af246a5e
2 changed files with 23 additions and 5 deletions

2
Engine

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

View File

@ -40,6 +40,13 @@ public class Game1 : Game
Sprite spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") }; Sprite spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
Sprite spriteBall = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Circle") }; Sprite spriteBall = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Circle") };
IGameObject gameObjectCamera = gameManager.InstantiateGameObject<GameObject>();
gameObjectCamera.Name = "Camera";
gameObjectCamera.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f);
gameManager.Camera = gameObjectCamera.BehaviourController.AddBehaviour<CameraBehaviour>();
gameManager.Camera.Viewport = GraphicsDevice.Viewport;
IGameObject gameObjectBall = gameManager.InstantiateGameObject<GameObject>(); IGameObject gameObjectBall = gameManager.InstantiateGameObject<GameObject>();
gameObjectBall.Name = "Ball"; gameObjectBall.Name = "Ball";
gameObjectBall.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f); gameObjectBall.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f);
@ -52,7 +59,7 @@ public class Game1 : Game
gameObjectLeft.Transform.Position = new Vector2(Window.ClientBounds.Width * .1f, Window.ClientBounds.Height * .5f); 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.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f);
gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.S, Keys.W, 200f); gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 200f);
gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox); gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>(); IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
@ -60,7 +67,7 @@ public class Game1 : Game
gameObjectRight.Transform.Position = new Vector2(Window.ClientBounds.Width * .9f, Window.ClientBounds.Height * .5f); 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.Scale = new Vector2(Window.ClientBounds.Width * .02f, Window.ClientBounds.Height * .15f);
gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>(); gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Down, Keys.Up, 200f); gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 200f);
gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox); gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
// TODO: use this.Content to load your game content here // TODO: use this.Content to load your game content here
} }
@ -73,11 +80,21 @@ public class Game1 : Game
if (Keyboard.GetState().IsKeyDown(Keys.F)) if (Keyboard.GetState().IsKeyDown(Keys.F))
{ {
_graphics.PreferMultiSampling = false; _graphics.PreferMultiSampling = false;
_graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; _graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; _graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.IsFullScreen = true; _graphics.IsFullScreen = true;
_graphics.ApplyChanges(); _graphics.ApplyChanges();
gameManager.Camera.Viewport = GraphicsDevice.Viewport;
} }
if (Keyboard.GetState().IsKeyDown(Keys.U))
{
gameManager.Camera.Zoom += gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
}
if (Keyboard.GetState().IsKeyDown(Keys.Q))
gameManager.Camera.Rotation += gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
if (Keyboard.GetState().IsKeyDown(Keys.E))
gameManager.Camera.Rotation -= gameTime.ElapsedGameTime.Nanoseconds * 0.000025f;
// TODO: Add your update logic here // TODO: Add your update logic here
gameManager.Update(gameTime); gameManager.Update(gameTime);
@ -91,6 +108,7 @@ public class Game1 : Game
// TODO: Add your drawing code here // TODO: Add your drawing code here
gameManager.PreDraw(gameTime); gameManager.PreDraw(gameTime);
gameManager.Camera.Update();
gameManager.Draw(_spriteBatch); gameManager.Draw(_spriteBatch);
base.Draw(gameTime); base.Draw(gameTime);