Ejemplo n.º 1
0
        public void AddLights()
        {
            GameObjectFactory factory = new GameObjectFactory();
            Vector2           size    = new Vector2(SpriteSize.Y) * 0.1f,
                              pos = Position
                                    + new Vector2(0.5f, -0.1f) * SpriteSize
                                    - 0.5f * size;

            LockedLight = factory.Create(
                new Obj
            {
                Type          = "secondary",
                Position      = pos,
                SpriteSize    = size,
                TextureString = "Sprites/Misc/red_light"
            }) as PlatformBackground;

            UnlockedLight = factory.Create(
                new Obj
            {
                Type          = "secondary",
                Position      = pos,
                SpriteSize    = size,
                TextureString = "Sprites/Misc/green_light"
            }) as PlatformBackground;

            LockedLight.Active   = !Unlocked;
            UnlockedLight.Active = Unlocked;
        }
Ejemplo n.º 2
0
        public Platform(Vector2 position, Vector2 spriteSize, string textureString,
                        float displacement, string dir, int actId, string secondTextureString)
            : base(position, spriteSize)
        {
            TextureString = textureString;
            Position      = position;
            SpriteSize    = spriteSize;
            Falling       = false;

            Speed       = Vector2.Zero;
            Mass        = 10;
            Visible     = true;
            LastUpdated = new TimeSpan();
            Movable     = false;
            Activate    = false;

            Displacement = displacement;
            ActivationId = actId;
            Speed        = Vector2.Zero;

            Initialize();

            if (dir is null)
            {
                dir = "y";
                secondTextureString = "Sprites/Misc/platform_mechanismy";
                Displacement        = 800;
            }

            if (dir == "y")
            {
                _movingInYdir    = true;
                DisplacementStep = new Vector2(0.0f, 5.0f);
                MaxHeight        = Position.Y - Displacement;
                MinHeight        = Position.Y;
                Background       = new PlatformBackground(new Vector2(Position.X, MaxHeight + SpriteSize.Y * 0.8f),
                                                          new Vector2(SpriteSize.X, Displacement),
                                                          secondTextureString)
                {
                    Active = true
                };
            }
            else if (dir == "x")
            {
                _movingInYdir    = false;
                DisplacementStep = new Vector2(-5.0f, 0.0f);
                MaxHeight        = Position.X + Displacement;
                MinHeight        = Position.X;
                Background       = new PlatformBackground(new Vector2(Position.X, Position.Y + SpriteSize.Y * 0.5f),
                                                          new Vector2(Displacement + SpriteSize.X, SpriteSize.Y),
                                                          secondTextureString)
                {
                    Active = true
                };
            }
        }
Ejemplo n.º 3
0
        public override GameObject Create(
            Object obj)
        {
            GameObject instance;
            Obj        entity = obj as Obj;

            switch (entity.Type.ToLower())
            {
            case "miner":
                instance = new Miner(
                    entity.Position,
                    entity.SpriteSize)
                {
                    Speed         = entity.Velocity,
                    Mass          = entity.Mass,
                    TextureString = entity?.TextureString,
                    Handling      = GameState.Handling.Actor,
                    Tool          = _toolFactory.Create(new Obj {
                        Type = entity.Tool
                    })
                };
                break;

            case "ground":
                instance = new Ground(
                    entity.Position,
                    entity.SpriteSize)
                {
                    TextureString = entity?.TextureString,
                    Handling      = GameState.Handling.Solid
                };
                break;

            case "rock":
                instance = new Rock(
                    entity.Position,
                    entity.SpriteSize)
                {
                    // compute the mass of the rock depending on the sprite size
                    // and consider the density as being 1/750
                    Mass          = entity.SpriteSize.X * entity.SpriteSize.Y / 750f,
                    TextureString = entity?.TextureString,
                    Handling      = GameState.Handling.Solid
                };
                break;

            case "door":
                instance = new Door(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString)
                {
                    Handling      = GameState.Handling.Interact,
                    RequiresKey   = entity.Requirement,
                    KeyId         = entity.Id,
                    TextureString = entity.TextureString,
                    Id            = currentDoor++
                };

                bool unlocked = !entity.Requirement;
                if (entity.Requirement)
                {
                    (instance as Door).AddKey(entity.Id);
                }
                break;

            case "crate":
                instance = new Crate(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString)
                {
                    Handling = GameState.Handling.Solid
                };
                break;

            case "ladder":
                instance = new Ladder(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString)
                {
                    Handling = GameState.Handling.None
                };
                break;

            case "platform":
                instance = new Platform(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString,
                    entity.Displacement,
                    entity.Direction,
                    entity.ActivationKey,
                    entity.SecondTexture)
                {
                    Handling = GameState.Handling.Solid
                };
                break;

            case "lever":
                instance = new Lever(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString,
                    entity.ActivationKey)
                {
                    Handling          = GameState.Handling.None,
                    RightleverTexture = entity?.SecondTexture
                };
                //(instance as Lever).RightleverTexture = entity?.SecondTexture;
                break;

            case "button":
                instance = new Button(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString,
                    entity.ActivationKey)
                {
                    Handling = GameState.Handling.None
                };
                activationKeys++;
                break;

            case "rockandhook":
                entity.SecondTexture = "Sprites/Misc/Rope";
                instance             = new RockHook(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString,
                    entity.SecondTexture,
                    entity.RopeLength)
                {
                    Handling = GameState.Handling.Solid
                };
                break;

            case "secondary":
                instance = new PlatformBackground(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString);
                break;

            case "key":
                instance = new Key(
                    entity.Position,
                    entity.SpriteSize)
                {
                    TextureString = entity.TextureString,
                    Handling      = GameState.Handling.Collect,
                    Id            = entity.Id
                };
                currentKey++;
                break;

            case "sign":
                instance = new Sign(
                    entity.Position,
                    entity.SpriteSize,
                    entity.TextureString)
                {
                    Handling = GameState.Handling.None
                };
                break;

            default:
                instance = null;
                MyDebugger.WriteLine(
                    string.Format("GameObject '{0}' cannot be created",
                                  entity?.Type), true);
                break;
            }
            if (instance != null)
            {
                instance.Visible = true;
                instance.Active  = true;
            }
            return(instance);
        }