2023-11-24 17:48:50 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
2023-11-23 23:59:03 +03:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2023-11-24 15:50:23 +03:00
|
|
|
|
using Pong.Behaviours;
|
2023-11-23 23:59:03 +03:00
|
|
|
|
using Syntriax.Engine.Core;
|
2023-11-24 15:50:23 +03:00
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
2023-11-27 10:38:02 +03:00
|
|
|
|
using Syntriax.Engine.Graphics.TwoDimensional;
|
2023-11-24 15:50:23 +03:00
|
|
|
|
using Syntriax.Engine.Input;
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
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();
|
2023-11-24 15:50:23 +03:00
|
|
|
|
|
2023-11-23 23:59:03 +03:00
|
|
|
|
// TODO: Add your initialization logic here
|
2023-11-24 15:50:23 +03:00
|
|
|
|
gameManager.Initialize();
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadContent()
|
|
|
|
|
{
|
|
|
|
|
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
|
|
|
|
2023-11-27 11:49:05 +03:00
|
|
|
|
Sprite spriteBox = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Pixel") };
|
|
|
|
|
Sprite spriteBall = new Sprite() { Texture2D = Content.Load<Texture2D>("Sprites/Circle") };
|
|
|
|
|
|
2023-11-27 13:46:21 +03:00
|
|
|
|
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;
|
|
|
|
|
|
2023-11-27 11:49:05 +03:00
|
|
|
|
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);
|
2023-11-27 12:00:25 +03:00
|
|
|
|
gameObjectBall.BehaviourController.AddBehaviour<MovementBallBehaviour>(new Vector2(.1f, .1f), 100f);
|
2023-11-27 11:49:05 +03:00
|
|
|
|
gameObjectBall.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBall);
|
2023-11-24 23:38:08 +03:00
|
|
|
|
|
2023-11-27 11:00:34 +03:00
|
|
|
|
IGameObject gameObjectLeft = gameManager.InstantiateGameObject<GameObject>();
|
2023-11-24 17:48:50 +03:00
|
|
|
|
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<KeyboardInputsBehaviour>();
|
2023-11-27 13:46:21 +03:00
|
|
|
|
gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 200f);
|
2023-11-27 11:49:05 +03:00
|
|
|
|
gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
2023-11-24 17:48:50 +03:00
|
|
|
|
|
2023-11-27 11:00:34 +03:00
|
|
|
|
IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
|
2023-11-24 17:48:50 +03:00
|
|
|
|
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<KeyboardInputsBehaviour>();
|
2023-11-27 13:46:21 +03:00
|
|
|
|
gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 200f);
|
2023-11-27 11:49:05 +03:00
|
|
|
|
gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
|
2023-11-23 23:59:03 +03:00
|
|
|
|
// 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();
|
2023-11-24 17:48:50 +03:00
|
|
|
|
|
2023-11-24 15:50:23 +03:00
|
|
|
|
if (Keyboard.GetState().IsKeyDown(Keys.F))
|
|
|
|
|
{
|
|
|
|
|
_graphics.PreferMultiSampling = false;
|
2023-11-27 13:46:21 +03:00
|
|
|
|
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
|
|
|
|
|
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
|
2023-11-24 15:50:23 +03:00
|
|
|
|
_graphics.IsFullScreen = true;
|
|
|
|
|
_graphics.ApplyChanges();
|
2023-11-27 13:46:21 +03:00
|
|
|
|
gameManager.Camera.Viewport = GraphicsDevice.Viewport;
|
2023-11-24 15:50:23 +03:00
|
|
|
|
}
|
2023-11-27 13:46:21 +03:00
|
|
|
|
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;
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
// TODO: Add your update logic here
|
2023-11-24 15:50:23 +03:00
|
|
|
|
gameManager.Update(gameTime);
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
|
{
|
2023-11-24 15:50:23 +03:00
|
|
|
|
GraphicsDevice.Clear(new Color() { R = 32, G = 32, B = 32 });
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
// TODO: Add your drawing code here
|
2023-11-24 15:50:23 +03:00
|
|
|
|
gameManager.PreDraw(gameTime);
|
2023-11-27 13:46:21 +03:00
|
|
|
|
gameManager.Camera.Update();
|
2023-11-24 15:50:23 +03:00
|
|
|
|
gameManager.Draw(_spriteBatch);
|
2023-11-23 23:59:03 +03:00
|
|
|
|
|
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
}
|
|
|
|
|
}
|