Ejemplo n.º 1
0
        public Game(Context ctx)
        {
            this.ctx = ctx;

            state = GameState.UNDEFINED;

            systems = new GameSystems();
            systems.Add(new AnimSystem());
            systems.Add(new MovementSystem());
            systems.Add(new MapSystem(ctx.config.Get <MapSystemConfig>()));
            systems.Add(new CameraSystem());
            systems.Add(new EntitySystem());

            systems.Init(systems, ctx);

            ActionSystem actionSys = new ActionSystem(assemblyNames: "Game");

            actionSys.OnActionSystemRegistered += iActionSystem => {
                if (iActionSystem is IGameSystem gs)
                {
                    gs.Init(systems, ctx);
                }
            };
            actionSys.RegisterSystems();

            MapSystem mapSystem = systems.Get <MapSystem>();

            mapSystem.Load(new[] {
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xB, 0xB, 0xB, 0x1000A, 0xB, 0xB, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0x1, 0x1, 0x1,
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
            }, 12, "Entrance");

            player = systems.Get <EntitySystem>().CreatePlayer("Player");
            int spawnpoint = mapSystem.Map.Spawnpoint;

            player.SetLocalPosition(mapSystem.Map.IndexToWorldPos(spawnpoint));

            ctx.eventPump.Dispatch();
            // systems.Get<CameraSystem>().SetTarget(player.transform);
        }
Ejemplo n.º 2
0
        public override void Init()
        {
            var mapSystem = new MapSystem();

            AddSystems(
                new RenderingSystem(Matrix.Identity),
                new TransformSystem(),
                new CameraSystem(),
                new PhysicsSystem(),
                new InputSystem(),
                new SkyBoxSystem(),
                mapSystem

                );

            base.Init();
            // Camera entity
            int camera = AddEntity();

            AddComponent(camera, new CCamera());
            AddComponent(camera, new CInput());
            AddComponent(camera, new CTransform()
            {
                Position = new Vector3(0, -6, 1), Orientation = Quaternion.CreateFromRotationMatrix(Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 6, 0), Vector3.Up)), Scale = Vector3.One
            });

            // Heightmap entity
            int id = AddEntity();

            AddComponent <C3DRenderable>(id, new CHeightmap()
            {
                Image = Game1.Inst.Content.Load <Texture2D>("Textures/HeightMap")
            });
            AddComponent(id, new CTransform()
            {
                Position    = new Vector3(-590, -900, -590) * 0.01f,
                Orientation = Quaternion.Identity,
                Scale       = new Vector3(0.01f)
            });
            //hangar
            int hangar = AddEntity();

            AddComponent <C3DRenderable>(hangar, new CImportedModel()
            {
                model = Game1.Inst.Content.Load <Model>("resources/House1Smooth")
            });
            AddComponent(hangar, new CTransform()
            {
                Position    = new Vector3(0, -855, 0) * 0.01f,
                Orientation = Quaternion.CreateFromRotationMatrix(Matrix.CreateRotationY(MathHelper.PiOver4 * 2)),
                Scale       = new Vector3(0.005f)
            });

            //chopper
            int chopper = AddEntity();

            AddComponent <C3DRenderable>(chopper, new CImportedModel()
            {
                model          = Game1.Inst.Content.Load <Model>("Textures/sphere_mapped"),
                effect         = Game1.Inst.Content.Load <Effect>("Fx/Shader"),
                texture        = Game1.Inst.Content.Load <Texture2D>("Textures/setts"),
                normalMap      = Game1.Inst.Content.Load <Texture2D>("Textures/water-normal-map"),
                environmentMap = new TextureCube(Game1.Inst.GraphicsDevice, 256, true, SurfaceFormat.Color)
            });
            AddComponent(chopper, new CTransform()
            {
                Position    = new Vector3(0, -700, 0) * 0.01f,
                Orientation = Quaternion.CreateFromRotationMatrix(Matrix.CreateRotationY(MathHelper.PiOver4 * 2)),
                Scale       = new Vector3(0.5f)
            });

            // manually start loading all heightmap components, should be moved/automated
            mapSystem.Load();

            Log.Get().Debug("TestScene initialized.");
        }
        public override void Init()
        {
            var mapSystem  = new MapSystem();
            var waterSys   = new WaterSystem();
            var physicsSys = new PhysicsSystem();

            AddSystems(
                new FpsCounterSystem(updatesPerSec: 10),
                new SkyBoxSystem(),
                new RenderingSystem(),
                new CameraSystem(),
                physicsSys,
                mapSystem,
                new InputSystem(mapSystem),
                waterSys,
                new Rendering2DSystem()

                );

#if DEBUG
            AddSystem(new DebugOverlay());
#endif

            base.Init();
            // Camera entity
            int   camera      = AddEntity();
            float fieldofview = MathHelper.PiOver2;
            float nearplane   = 0.1f;
            float farplane    = 1000f;

            int player = AddEntity();
            AddComponent(player, new CBody()
            {
                Radius = 1, Aabb = new BoundingBox(-1 * Vector3.One, 1 * Vector3.One)
            });
            AddComponent(player, new CInput());
            AddComponent(player, new CTransform()
            {
                Position = new Vector3(0, -40, 0), Scale = new Vector3(1f)
            });
            AddComponent <C3DRenderable>(player, new CImportedModel()
            {
                model = Game1.Inst.Content.Load <Model>("Models/tree")
            });

            /*
             * int ball = AddEntity();
             * AddComponent(ball, new CBody() { Position = new Vector3(10f, 0, 10f), Radius = 1, Aabb = new BoundingBox(-1 * Vector3.One, 1 * Vector3.One) } );
             * AddComponent(ball, new CTransform() { Scale = new Vector3(1) } );
             * AddComponent<C3DRenderable>(ball, new CImportedModel() { model = Game1.Inst.Content.Load<Model>("Models/DummySphere") });
             */

            AddComponent(camera, new CCamera(-5, 5)
            {
                Projection       = Matrix.CreatePerspectiveFieldOfView(fieldofview, Game1.Inst.GraphicsDevice.Viewport.AspectRatio, nearplane, farplane)
                , ClipProjection = Matrix.CreatePerspectiveFieldOfView(fieldofview * 1.2f, Game1.Inst.GraphicsDevice.Viewport.AspectRatio, nearplane * 0.5f, farplane * 1.2f)
            });
            AddComponent(camera, new CInput());
            AddComponent(camera, new CTransform()
            {
                Position = new Vector3(-5, 5, 0), Rotation = Matrix.Identity, Scale = Vector3.One
            });

            /*
             * int eid = AddEntity();
             * AddComponent<C2DRenderable>(eid, new CFPS
             * {
             *  font = Game1.Inst.Content.Load<SpriteFont>("Fonts/sector034"),
             *  format = "Sap my Low-Poly Game",
             *  color = Color.White,
             *  position = new Vector2(300, 20),
             *  origin = Vector2.Zero// Game1.Inst.Content.Load<SpriteFont>("Fonts/sector034").MeasureString("Sap my Low-Poly Game") / 2
             * });
             * eid = AddEntity();
             * AddComponent<C2DRenderable>(eid, new CSprite
             * {
             *  texture = Game1.Inst.Content.Load<Texture2D>("Textures/clubbing"),
             *  position = new Vector2(300, 300),
             *  color = Color.White
             * });
             */
            // Tree model entity

            /*int id = AddEntity();
             * AddComponent<C3DRenderable>(id, new CImportedModel() { model = Game1.Inst.Content.Load<Model>("Models/tree") });
             * AddComponent(id, new CTransform() { Position = new Vector3(0, 0, 0), Rotation = Matrix.Identity, Scale = Vector3.One });*/


            // Heightmap entity
            int id = AddEntity();
            AddComponent <C3DRenderable>(id, new CHeightmap()
            {
                Image = Game1.Inst.Content.Load <Texture2D>("Textures/HeightMap")
            });
            AddComponent(id, new CTransform()
            {
                Position = new Vector3(-590, -255, -590), Rotation = Matrix.Identity, Scale = new Vector3(1)
            });
            // manually start loading all heightmap components, should be moved/automated
            mapSystem.Load();
            waterSys.Load();
            physicsSys.MapSystem = mapSystem;

            Log.Get().Debug("TestScene initialized.");
        }