using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Pong.Behaviours; using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Graphics.TwoDimensional; using Syntriax.Engine.Input; namespace Pong; public class Game1 : Game { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private GameManager gameManager = null!; public Game1() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void Initialize() { gameManager = new(); // TODO: Add your initialization logic here gameManager.Initialize(); base.Initialize(); } protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); Sprite spriteBox = new Sprite() { Texture2D = Content.Load("Sprites/Pixel") }; Sprite spriteBall = new Sprite() { Texture2D = Content.Load("Sprites/Circle") }; IGameObject gameObjectCamera = gameManager.InstantiateGameObject(); gameObjectCamera.Name = "Camera"; gameObjectCamera.Transform.Position = new Vector2(Window.ClientBounds.Width * .5f, Window.ClientBounds.Height * .5f); gameManager.Camera = gameObjectCamera.BehaviourController.AddBehaviour(); gameManager.Camera.Viewport = GraphicsDevice.Viewport; IGameObject gameObjectBall = gameManager.InstantiateGameObject(); 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(new Vector2(.1f, .1f), 100f); gameObjectBall.BehaviourController.AddBehaviour().Assign(spriteBall); IGameObject gameObjectLeft = gameManager.InstantiateGameObject(); 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.BehaviourController.AddBehaviour(); gameObjectLeft.BehaviourController.AddBehaviour(Keys.W, Keys.S, 200f); gameObjectLeft.BehaviourController.AddBehaviour().Assign(spriteBox); IGameObject gameObjectRight = gameManager.InstantiateGameObject(); 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.BehaviourController.AddBehaviour(); gameObjectRight.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 200f); gameObjectRight.BehaviourController.AddBehaviour().Assign(spriteBox); // TODO: use this.Content to load your game content here } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); if (Keyboard.GetState().IsKeyDown(Keys.F)) { _graphics.PreferMultiSampling = false; _graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width; _graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height; _graphics.IsFullScreen = true; _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 gameManager.Update(gameTime); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(new Color() { R = 32, G = 32, B = 32 }); // TODO: Add your drawing code here gameManager.PreDraw(gameTime); gameManager.Camera.Update(); gameManager.Draw(_spriteBatch); base.Draw(gameTime); } }