Exemplo n.º 1
0
        GameWorld(GameSession session)
        {
            Session     = session;
            Entities    = new List <Entity>(512);
            EntityQueue = new List <Entity>(64);

            // Particles
            Particles = new List <Particle>(8192);

            // Load lighting
            Lighting = new LightingManager(session.Game);

            // Physics
            Physics = new World(new Vector2(0, 0))
            {
                Tag = this
            };

            // Physical engine debug view
            DebugView = new DebugView(Physics)
            {
                Enabled = true
            };
            DebugView.LoadContent(Game.GraphicsDevice, Game.Content);

            // Default camera
            _camera = new Camera(Game);

            PrepareRenderData((int)Game.Resolution.X, (int)Game.Resolution.Y);
            Game.OnResolutionChange += PrepareRenderData;
        }
Exemplo n.º 2
0
        public override void LoadContent()
        {
            if (World == null)
            {
                World = new World(Vector2.Zero);
                World.JointRemoved += JointRemoved;
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugView(World);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(Framework.GraphicsDevice, Framework.Content);
            }

            DebugView.Flags = _flags;
            _flagsChanged   = false;

            if (Camera == null)
            {
                Camera = new Camera2D(Framework.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            base.LoadContent();
        }
Exemplo n.º 3
0
        public virtual void Initialize()
        {
            DebugView = new DebugView(World);
            DebugView.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);

            this.WorldMouseTestUtility = new WorldMouseTestUtility(World, GameInstance);
        }
Exemplo n.º 4
0
 public void SetUpCamera()
 {
     debugView = new DebugView(world);
     debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.PolygonPoints);
     debugView.LoadContent(GraphicsDevice, Content);
     viewport = GraphicsDevice.Viewport;
     camera   = new Camera(viewport);
 }
Exemplo n.º 5
0
        public void LoadContent(GraphicsDevice graphics, ContentManager content)
        {
            this.font = content.Load <SpriteFont>("DiagnosticsFont");

            device = graphics;
            _debugView.LoadContent(graphics, content);
            camera = new Camera(graphics.Viewport, new Rectangle(0, 0, 2400, 1600));
            camera.SetViewTarget(player.controller);
        }
Exemplo n.º 6
0
        public void createGame()
        {
            //CREATE GRAVITY
            world = new World(new Vector2(0, -9.8f));

            spriteBatch        = new SpriteBatch(GraphicsDevice);
            _spriteBatchEffect = new BasicEffect(graphics.GraphicsDevice);
            _spriteBatchEffect.TextureEnabled = true;

            //LOAD TEXTURES
            roadTexture      = Content.Load <Texture2D>("spaceplatform");
            playerTexture    = Content.Load <Texture2D>("Astronaut");
            obstacleTextureJ = Content.Load <Texture2D>("drone");
            obstacleTextureC = Content.Load <Texture2D>("alien3");
            font             = Content.Load <SpriteFont>("8bitletters");

            //CREATE ROADS
            RoadManager = new Road(roadTexture);
            _road1      = new List <Road>();
            _road1      = RoadManager.CreateRoad(_road1, 1, world);

            _road2 = new List <Road>();
            _road2 = RoadManager.CreateRoad(_road2, 2, world);

            _road3 = new List <Road>();
            _road3 = RoadManager.CreateRoad(_road3, 3, world);

            //CREATE PLAYER
            _player = new Player(playerTexture);
            _player.SetPlayerPhysics(world);

            _cameraPosition = new Vector3(_player.getBody().Position.X + 20f, _player.getBody().Position.Y, 0);

            //CREATE OBSTACLES
            ObstacleManagerJ  = new Obstacle(obstacleTextureJ);
            _jumpObstacles1   = new List <Obstacle>();
            _jumpObstacles2   = new List <Obstacle>();
            _jumpObstacles3   = new List <Obstacle>();
            ObstacleManagerC  = new Obstacle(obstacleTextureC);
            _crouchObstacles1 = new List <Obstacle>();
            _crouchObstacles2 = new List <Obstacle>();
            _crouchObstacles3 = new List <Obstacle>();

            _jumpObstacles1   = ObstacleManagerJ.IntializeObstacles(_jumpObstacles1, _road1, true, world);
            _crouchObstacles1 = ObstacleManagerC.IntializeObstacles(_crouchObstacles1, _road1, false, world);
            _jumpObstacles2   = ObstacleManagerJ.IntializeObstacles(_jumpObstacles2, _road2, true, world);
            _crouchObstacles2 = ObstacleManagerC.IntializeObstacles(_crouchObstacles2, _road2, false, world);
            _jumpObstacles3   = ObstacleManagerJ.IntializeObstacles(_jumpObstacles3, _road3, true, world);
            _crouchObstacles3 = ObstacleManagerC.IntializeObstacles(_crouchObstacles3, _road3, false, world);

            //CREATE DEBUGGER
            debugView = new DebugView(world);
            debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.PolygonPoints);
            debugView.LoadContent(GraphicsDevice, Content);
        }
        public override void Initialize()
        {
            base.Initialize();

            debugView2 = new Diagnostics.DebugView(world2);
            debugView3 = new Diagnostics.DebugView(world3);
            debugView4 = new Diagnostics.DebugView(world4);
            debugView2.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);
            debugView3.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);
            debugView4.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Inicializace všech objektů nutných pro existenci scény.
 /// </summary>
 public virtual void Load()
 {
     if (DebugView == null)
     {
         DebugView = new DebugView(Demo.World3D.World2D);
         DebugView.RemoveFlags(DebugViewFlags.Shape);
         DebugView.RemoveFlags(DebugViewFlags.Joint);
         DebugView.DefaultShapeColor  = Color.White;
         DebugView.SleepingShapeColor = Color.LightGray;
         DebugView.TextColor          = Color.Black;
         DebugView.LoadContent(Demo.GraphicsDevice, Demo.Content);
     }
 }
        public override void LoadContent()
        {
            base.LoadContent();

            if (World == null)
            {
                World = new World(Vector2.Zero);
                World.JointRemoved += JointRemoved;
            }
            else
            {
                World.Clear();
            }

            // enable multithreading
            World.ContactManager.VelocityConstraintsMultithreadThreshold = 256;
            World.ContactManager.PositionConstraintsMultithreadThreshold = 256;
            World.ContactManager.CollideMultithreadThreshold             = 256;

            if (DebugView == null)
            {
                DebugView = new DebugView(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }

            if (Camera == null)
            {
                Camera = new Camera2D(ScreenManager.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            HiddenBody = World.CreateBody(Vector2.Zero);

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Exemplo n.º 10
0
        public void LoadContent(ContentManager contentManager)
        {
            CollisionWorld = new World(new Vector2(0, 10));
            debugView      = new DebugView(CollisionWorld);
            debugView.LoadContent(DemoGame.graphics.GraphicsDevice, contentManager);

            foreach (var layer in Layers)
            {
                layer.level = this;
                layer.LoadContent(contentManager);

                if (layer.Name == "Mountains")
                {
                    layer._postProcessors.Add(new WaterReflectionPostProcessor(context));
                }

                foreach (var item in layer.Items)
                {
                    if (item is SpriteObject sprite)
                    {
                        sprite.context = context;
                    }
                    item.layer = layer;
                    item.LoadContent(contentManager);
                    item.Initialize();
                }
            }

            render_target = new RenderTarget2D(context.graphics, context.graphics.Viewport.Width, context.graphics.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

            this._postProcessors.Add(new FogPostProcessor(context));

            context.camera.Bounds = LevelBounds;

            LevelBounds.Inflate((int)(0.05 * LevelBounds.Width), (int)(0.05 * LevelBounds.Height));

            var song = "level" + Rand.GetRandomInt(1, 4);

            AudioManager.PlaySoundTrack(song, true, false);
            AudioManager.MusicVolume = 0.1f;
        }
Exemplo n.º 11
0
        public override void LoadContent()
        {
            if (World == null)
            {
                World = new World(Vector2.Zero);
                World.JointRemoved += JointRemoved;

                // enable multithreading
                World.ContactManager.VelocityConstraintsMultithreadThreshold = 256;
                World.ContactManager.PositionConstraintsMultithreadThreshold = 256;
                World.ContactManager.CollideMultithreadThreshold             = 256;
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugView(World);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(Framework.GraphicsDevice, Framework.Content);
            }

            DebugView.Flags = _flags;
            _flagsChanged   = false;

            if (Camera == null)
            {
                Camera = new Camera2D(Framework.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            base.LoadContent();
        }
Exemplo n.º 12
0
        protected override void Initialize()
        {
            World     = new World(Vector2.UnitY * -10 * PhysicsScale);
            DebugView = new DebugView(World);
            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);
            if (Debug.DISPLAY_COLLIDERS)
            {
                DebugView.AppendFlags(DebugViewFlags.DebugPanel);
            }

            ScreenManager = new ScreenManager(this, new GameScreen[] { new Background(), new MainMenu() });
            Components.Add(ScreenManager);

            PhysicsProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, DisplayWidth, DisplayHeight, 0, 0, -100) *
                                      Matrix.CreateScale(PhysicsScale, -PhysicsScale, 1) *
                                      Matrix.CreateTranslation(PhysicsScale, PhysicsScale, 0);
            StandardTransformMatrix = Matrix.CreateTranslation(DisplayWidth / 2, -DisplayHeight / 2, 0) * Matrix.CreateScale(1, -1f, 1);
            ViewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);

            base.Initialize();
        }
Exemplo n.º 13
0
        protected override void Initialize()
        {
            base.Initialize();
            Graphics = GraphicsDevice;

            //Initialize physics
            tainicom.Aether.Physics2D.Settings.MaxPolygonVertices = 16;
            world     = new World(Vector2.Zero);
            debugView = new DebugView(world);
            debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.PolygonPoints);
            debugView.LoadContent(GraphicsDevice, Content);

            //Create player
            player = new Player(Content, CarType.SPORT, world, adjustedSpeed);
            player.DodgeCompleteCallback = DodgeCompleted;
            player.CoinGetCallback       = CoinGet;

            //Create objects
            environment    = new EnvironmentManager(Content, world);
            trafficManager = new TrafficManager(Content, world);

            //Setup graphics
            Lighting.Initialize();
            effect        = Content.Load <Effect>("effect");
            postProcessor = new PostProcessor(spriteBatch, Content.Load <Effect>("desaturate"));

            //Setup GUI
            scoreUI     = new ScoreUI();
            gameOverUI  = new GameOverUI();
            fpsUI       = new FPSUI();
            countdownUI = new CountdownUI();
            titleUI     = new TitleUI();

            //Setup input
            InputManager.Initialize();
        }
Exemplo n.º 14
0
 public virtual void Initialize()
 {
     DebugView = new DebugView(World);
     DebugView.LoadContent(GameInstance.GraphicsDevice, GameInstance.Content);
 }
Exemplo n.º 15
0
        public void LoadContent()
        {
            _world = new World();

            // enable multithreading
            _world.ContactManager.VelocityConstraintsMultithreadThreshold = 256;
            _world.ContactManager.PositionConstraintsMultithreadThreshold = 256;
            _world.ContactManager.CollideMultithreadThreshold             = 256;

            var entities = Scene.GetEntities(_ => MatchActiveEntitiesAndComponents(_));

            for (int i = 0; i < entities.Count; i++)
            {
                var     entity        = entities[i];
                var     bodyComponent = entity.GetComponent <BodyComponent>();
                Fixture fixture       = null;

                switch (bodyComponent.EntityShape)
                {
                case EntityShape.Circle:
                    fixture = bodyComponent.CreateCircle(bodyComponent.Radius, bodyComponent.Density, Vector2.Zero);
                    break;

                case EntityShape.Ellipse:
                    fixture = bodyComponent.CreateEllipse(bodyComponent.Size.X * 0.5f, bodyComponent.Size.Y * 0.5f, 8, bodyComponent.Density);
                    break;

                case EntityShape.Rectangle:
                    fixture = bodyComponent.CreateRectangle(bodyComponent.Size.X, bodyComponent.Size.Y, bodyComponent.Density, Vector2.Zero);
                    break;

                case EntityShape.Polygon:
                    var vertices = new Vertices(bodyComponent.Vertices);
                    fixture = bodyComponent.CreatePolygon(vertices, bodyComponent.Density);
                    break;
                }

                _world.Add(bodyComponent);

                bodyComponent.Tag      = entity.UniqueId;
                bodyComponent.Position = entity.Position;
                bodyComponent.Rotation = entity.Rotation;

                if (fixture != null)
                {
                    fixture.Restitution = bodyComponent.Restitution;
                    fixture.Friction    = bodyComponent.Friction;
                }
            }
            ;

            if (Scene.GameCore.DebugActive && entities.Any())
            {
                _debugView = new DebugView(_world);
                _debugView.AppendFlags(DebugViewFlags.Shape);
                _debugView.AppendFlags(DebugViewFlags.Joint);
                _debugView.AppendFlags(DebugViewFlags.PerformanceGraph);
                _debugView.AppendFlags(DebugViewFlags.DebugPanel);
                _debugView.DefaultShapeColor  = Color.Orange;
                _debugView.SleepingShapeColor = Color.DodgerBlue;
                _debugView.TextColor          = Color.Black;
                _debugView.StaticShapeColor   = Color.Red;

                _debugView.LoadContent(Scene.GameCore.GraphicsDevice, Scene.GameCore.Content);
            }
        }