Exemplo n.º 1
0
        public void Update(List <IEntityComponent> entityComponents, Guid entityId, GameTime gameTime)
        {
            try
            {
                MouseState      mState            = Mouse.GetState();
                MouseControlled mouseControlled   = (MouseControlled)entityComponents.Where(component => component.Name == "mouse_controlled").Single();
                Position        positionComponent = (Position)entityComponents.Where(component => component.Name == "position").Single();

                positionComponent.X = mState.Position.X;
                positionComponent.Y = mState.Position.Y;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public DemoScene(string sceneName, bool isActive)
        {
            IsActive  = isActive;
            SceneName = sceneName;

            // Setting up player entity

            // Create components; generally want to do this automatically by reading in XML or JSON data and generating your game objects
            var playerAppearanceComponent = new Appearance("player");
            var playerPositionComponent   = new Position(300, 300);
            var playerControlledComponent = new PlayerControlled();
            var velocityComponent         = new Velocity(3, new Vector2(0, -1)); // How to Enum so both this class and the Velocity component know about it?
            // Create systems; same as components in that it should be read in from somewhere else and generated, aint no1 got time to type all this out
            var renderSystem        = new Render();
            var keyboardInputSystem = new KeyboardPlayerInput();
            var motionSystem        = new Motion();

            World = new World(); // A whole new world!!!
            World.AddEntity(new Entity(new List <IEntityComponent> {
                playerAppearanceComponent, playerControlledComponent, playerPositionComponent, velocityComponent
            }));                                                                                                                                                          // Player Entity added

            // Setting up mouse cursor entity
            var cursorAppearanceComponent = new Appearance("cursor");
            var cursorPositionComponent   = new Position(0, 0);
            var mouseControlledComponent  = new MouseControlled();
            var mouseInputSystem          = new MouseInput();

            World.AddEntity(new Entity(new List <IEntityComponent> {
                cursorAppearanceComponent, cursorPositionComponent, mouseControlledComponent
            }));                                                                                                                                      // Mouse cursor entity added

            World.AddSystems(new List <IEntitySystem> {
                keyboardInputSystem, mouseInputSystem, motionSystem, renderSystem
            });                                                                                                              // Need to ensure these are executed in a specific order, should I use SortedList here?
        }