Esempio n. 1
0
        private void SerialiseWorldspawnChildren(Worldspawn worldspawn, SerialisedObject worldObj, Dictionary <MapObject, int> idMap, int groupId, List <MapObject> list)
        {
            foreach (var c in list)
            {
                var cid = idMap[c];
                switch (c)
                {
                case Entity _:
                    // Ignore everything underneath an entity
                    break;

                case Group g:
                    var sg = new VmfGroup(g, cid);
                    if (groupId != 0)
                    {
                        sg.Editor.GroupID = groupId;
                    }
                    worldObj.Children.Add(sg.ToSerialisedObject());
                    SerialiseWorldspawnChildren(worldspawn, worldObj, idMap, cid, g.Children);
                    break;

                case Solid s:
                    var ss = new VmfSolid(s, cid);
                    if (groupId != 0)
                    {
                        ss.Editor.GroupID = groupId;
                    }
                    worldObj.Children.Add(ss.ToSerialisedObject());
                    break;
                }
            }
        }
Esempio n. 2
0
        public void Update(Playstates.PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var text = Owner.QueryComponent<TextHolder>();
            var builder = new StringBuilder();

            foreach (var property in Properties)
            {
                var split = property.Item1.Split(' ');
                var useful = split.First();
                var propName = useful.Split('.').Last();
                var className = useful.Substring(0, useful.Length - propName.Length - 1);

                var classType = Extensions.GetTypeInfo(Type.GetType(className));
                var propType = classType.GetDeclaredProperty(propName);
                var fieldType = classType.GetDeclaredField(propName);

                builder.Append(propName);
                if (split.Length > 1)
                {
                    builder.Append(" (");
                    builder.Append(property.Item1.Substring(useful.Length + 1));
                    builder.Append(")");
                }
                builder.Append(" : ");
                builder.Append(propType != null ? propType.GetValue(property.Item2) : fieldType.GetValue(property.Item2));
                builder.AppendLine();
            }

            text.Text.Text = builder.ToString();
        }
Esempio n. 3
0
 public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if (Predicate(Worldspawn, Owner, GOID))
     {
         if (Unspawned != null) Unspawned(this, new UnspawnedEventArgs { GOID = GOID, Owner = Owner, Worldspawn = Worldspawn, State = State });
         Worldspawn.GameObjects.Remove(GOID);
     }
 }
Esempio n. 4
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            if (!Activated)
                return;

            if (frame == 0) Owner.QueryComponent<Identity2D>().Transform.Rotation += Increase;
            frame = (frame + 1) % interval;
        }
Esempio n. 5
0
        private static Worldspawn InitWorldspawn(Worldspawn ent, ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            if (InitBrushEntity(ent, value, mapParams) == null)
            {
                return(null);
            }

            ent.SkyMaterial = Material.CreateSkyMaterial(mapParams.Bsp, value["skyname"]);

            return(ent);
        }
        static void ReadWorldspawn(MapFile map, BinaryReader br)
        {
            Worldspawn e = (Worldspawn)ReadObject(map, br);

            map.Worldspawn.SpawnFlags = e.SpawnFlags;
            foreach (KeyValuePair <string, string> p in e.Properties)
            {
                map.Worldspawn.Properties[p.Key] = p.Value;
            }
            map.Worldspawn.Children.AddRange(e.Children);
        }
Esempio n. 7
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var spriteHolder = Owner.QueryComponent<SpriteHolder>();

            var sX = (int)((MaxSize.Width - MinSize.Width) * Maths.Cos(frame * 2 * Maths.Pi / Frequency)) + MinSize.Width;
            var sY = (int)((MaxSize.Height - MinSize.Height) * Maths.Cos(frame * 2 * Maths.Pi / Frequency)) + MinSize.Height;

            spriteHolder.Sprite.Size = new Size2D<int>(IdleSize.HasValue ? (Oscillate ? sX : IdleSize.Value.Width) : sX, IdleSize.HasValue ? (Oscillate ? sY : IdleSize.Value.Height) : sY);

            if (Oscillate)
                frame = ((frame + 1) % 65536);
        }
        static Worldspawn ReadRoot(MapFile map, BinaryReader br)
        {
            Worldspawn wld = new Worldspawn();

            ReadMapBase(map, wld, br);
            ReadEntityData(wld, br);
            int numPaths = br.ReadInt32();

            for (int i = 0; i < numPaths; i++)
            {
                map.Paths.Add(ReadPath(br));
            }
            return(wld);
        }
        void WriteWorld(StreamWriter sw, Worldspawn world, string styleHint)
        {
            List <Solid>  solids   = new List <Solid>();
            List <Entity> entities = new List <Entity>();

            CollectNonEntitySolids(solids, world);
            CollectEntities(entities, world);

            WriteEntityWithSolids(sw, world, solids, styleHint);

            foreach (Entity entity in entities)
            {
                WriteEntity(sw, entity, styleHint);
            }
        }
Esempio n. 10
0
 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     var hitbox = Owner.QueryComponent<Hitbox>();
     var gobs = Worldspawn.SpacePartitionning
         ? Worldspawn.GetNearObjects<Lifespan>(Owner)
         : Worldspawn.GameObjects.Where(Gob => Gob.Value.HasComponent<Lifespan>());
     foreach (var gob in gobs)
     {
         var lifeSpan = gob.Value.QueryComponent<Lifespan>();
         if (lifeSpan.Group != Group) continue;
         var boundingBox = gob.Value.QueryComponent<Hitbox>();
         if (hitbox.Intersects(boundingBox))
         {
             lifeSpan.Kill();
             if (lifeSpan.IsDead)
                 if (InstantlyKill != null) InstantlyKill(this, new InstantlyKilledEventArgs { State = State, GOID = GOID, Owner = Owner, Worldspawn = Worldspawn, DealtTo = gob });
         }
     }
 }
Esempio n. 11
0
        public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var hitbox = Owner.QueryComponent<Hitbox>();
            var gobs = Worldspawn.SpacePartitionning
                ? Worldspawn.GetNearObjects<Lifespan>(Owner)
                : Worldspawn.GameObjects.Where(Gob => Gob.Value.HasComponent<Lifespan>() );
            foreach (var gob in gobs)
            {
                var lifeSpan = gob.Value.QueryComponent<Lifespan>();
                if(lifeSpan.Group != Group) continue;
                var boundingBox = gob.Value.QueryComponent<Hitbox>();
                if (!hitbox.Intersects(boundingBox)) continue;

                var args = new DamageDealtEventArgs { State = State, Worldspawn = Worldspawn, DealtTo = gob, Owner = Owner, GOID = GOID, Amount = Damages };
                var oldLife = lifeSpan.Current;
                lifeSpan.Hurt(Damages);
                args.EffectiveAmount = lifeSpan.Current - oldLife;
                if (DamageDealt != null) DamageDealt(this, args);
            }
        }
 public Vector2 GetScale(Worldspawn Worldspawn, Camera2D Owner)
 {
     return Vector2.One;
 }
Esempio n. 13
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     ServiceLocator.GraphicsService.Draw(MoverSprite, new Transform2D(moverPosition, 0f, Vector2.One));
 }
Esempio n. 14
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var identity2D = Owner.QueryComponent<Identity2D>();
            var sprite = Owner.QueryComponent<SpriteHolder>();
            var hitbox = CustomHitbox.HasValue
                ? new Rectangle<int>((int)identity2D.CameraTransform.Position.X,
                    (int)identity2D.CameraTransform.Position.Y,
                    CustomHitbox.Value.Width,
                    CustomHitbox.Value.Height)
                : new Rectangle<int>((int)identity2D.CameraTransform.Position.X,
                    (int)identity2D.CameraTransform.Position.Y,
                    sprite.Sprite.Size.Width,
                    sprite.Sprite.Size.Height);

            var isDown = false;
            if (ServiceLocator.DeviceService.IsMouseSupported) isDown |= MouseTest(hitbox);
            if (ServiceLocator.DeviceService.IsTouchSupported) isDown |= TouchTest(hitbox);
            IsDown = isDown;

            if (IsPressedOnce && Press != null) Press(this, new VirtualButtonEventArgs { Owner = Owner, Worldspawn = Worldspawn, GOID = GOID, State = State });
            if (IsReleasedOnce && Release != null) Release(this, new VirtualButtonEventArgs { Owner = Owner, Worldspawn = Worldspawn, GOID = GOID, State = State });

            if (Animate) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = IsDown ? PressedAnimation : ReleasedAnimation;

            wasUp = IsUp;
            wasDown = IsDown;
        }
Esempio n. 15
0
 public void Update(Worldspawn Owner)
 {
     cameraTransform.Position = -ScrollingStrategy.GetPosition(Owner, this);
     cameraTransform.Rotation = -RotatingStrategy.GetRotation(Owner, this);
     cameraTransform.Scale = Vector2.Invert(ScalingStrategy.GetScale(Owner, this));
 }
 public Vector2 GetPosition(Worldspawn Worldspawn, Camera2D Owner)
 {
     if (Target == null)
         return -new Vector2(ServiceLocator.GraphicsService.ViewportSize.Width / 2, ServiceLocator.GraphicsService.ViewportSize.Height / 2);
     return ((Target.QueryComponent<Identity2D>().Transform.Position - Offset) * Owner.Transform.Scale - new Vector2(ServiceLocator.GraphicsService.ViewportSize.Width / 2, ServiceLocator.GraphicsService.ViewportSize.Height / 2));
 }
Esempio n. 17
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if(Sprite != null)
         ServiceLocator.GraphicsService.Draw(Sprite, Owner.QueryComponent<Identity2D>().CameraTransform);
 }
 static void WriteRoot(Worldspawn root, BinaryWriter bw)
 {
     bw.WriteCString("CMapWorld", MaxVariableStringLength);
     WriteMapBase(root, bw);
     WriteEntityData(root, bw);
 }
Esempio n. 19
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var identity = Owner.QueryComponent<Identity2D>();
            var position = identity.CameraTransform.Position;
            var rect = new Rectangle<float>(position.X - MaxRadius, position.Y - MaxRadius, MaxRadius * 2, MaxRadius * 2);

            switch (AllowedMode)
            {
                case CursorMode.Touch:
                    if (lastId == -1)
                    {
                        var touches = ServiceLocator.InputService.GetTouches().Where(To => rect.Contains(To.Position) && To.State == TouchState.Pressed).ToList();
                        if (touches.Any()) lastId = touches.First().Id;
                    }

                    if (lastId != -1)
                    {
                        var touch = ServiceLocator.InputService.GetTouches().Where(To => To.Id == lastId).ToList();
                        if (!touch.Any()) lastId = -1;

                        var vect = touch.First().Position - position;
                        if (vect.LengthSquared() > MaxRadius * MaxRadius)
                            vect *= (MaxRadius / vect.Length());

                        moverPosition = position + vect;
                        Value = vect / MaxRadius;
                    }
                    else
                    {
                        moverPosition = position;
                        Value = Vector2.Zero;
                    }
                    break;

                case CursorMode.Mouse:
                    if (!isClicked)
                        if (rect.Contains(ServiceLocator.InputService.GetMousePosition()) && ServiceLocator.InputService.IsMouseButtonDown(MouseButton.LeftButton))
                            isClicked = true;
                    if(isClicked)
                        if (ServiceLocator.InputService.IsMouseButtonUp(MouseButton.LeftButton))
                            isClicked = false;

                    if (isClicked)
                    {
                        var vect = ServiceLocator.InputService.GetMousePosition() - position;
                        if (vect.LengthSquared() > MaxRadius*MaxRadius)
                            vect *= (MaxRadius/vect.Length());

                        moverPosition = position + vect;
                        Value = vect/MaxRadius;
                    }
                    else
                    {
                        moverPosition = position;
                        Value = Vector2.Zero;
                    }

                    break;

                case CursorMode.Mouse | CursorMode.Touch:
                    if (lastId == -1 && !isClicked)
                    {
                        var touches = ServiceLocator.InputService.GetTouches().Where(To => rect.Contains(To.Position) && To.State == TouchState.Pressed).ToList();
                        if (touches.Any()) lastId = touches.First().Id;
                    }

                    if (lastId != -1)
                    {
                        isClicked = false;
                        var touch = ServiceLocator.InputService.GetTouches().Where(To => To.Id == lastId).ToList();
                        if (!touch.Any()) lastId = -1;

                        var vect = touch.First().Position - position;
                        if (vect.LengthSquared() > MaxRadius * MaxRadius)
                            vect *= (MaxRadius / vect.Length());

                        moverPosition = position + vect;
                        Value = vect / MaxRadius;
                    }
                    else
                    {
                        if (!isClicked)
                        {
                            moverPosition = position;
                            Value = Vector2.Zero;
                        }
                    }

                    if (lastId == -1)
                    {
                        if (!isClicked)
                            if (rect.Contains(ServiceLocator.InputService.GetMousePosition()) && ServiceLocator.InputService.IsMouseButtonDown(MouseButton.LeftButton))
                                isClicked = true;
                        if (isClicked)
                            if (ServiceLocator.InputService.IsMouseButtonUp(MouseButton.LeftButton))
                                isClicked = false;

                        if (isClicked)
                        {
                            var vect = ServiceLocator.InputService.GetMousePosition() - position;
                            if (vect.LengthSquared() > MaxRadius * MaxRadius)
                                vect *= (MaxRadius / vect.Length());

                            moverPosition = position + vect;
                            Value = vect / MaxRadius;
                        }
                        else
                        {
                            moverPosition = position;
                            Value = Vector2.Zero;
                        }
                    }
                    break;
            }
        }
 public Vector2 GetPosition(Worldspawn Worldspawn, Camera2D Owner)
 {
     return Vector2.Zero;
 }
 public Vector2 GetScale(Worldspawn Worldspawn, Camera2D Owner)
 {
     return Zoom;
 }
Esempio n. 22
0
 public VmfWorld(Worldspawn root) : base(root, -1)
 {
 }
Esempio n. 23
0
 public void Draw(Worldspawn Owner)
 {
 }
Esempio n. 24
0
 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if (invencibilityFrameCounter > -1) invencibilityFrameCounter--;
 }
 public float GetRotation(Worldspawn Worldspawn, Camera2D Owner)
 {
     return 0f;
 }
Esempio n. 26
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
 }
Esempio n. 27
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            if (CommandMap[up].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, -Speed);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && UpAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = UpAnimation;
            }
            if (CommandMap[down].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, Speed);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && DownAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = DownAnimation;
            }
            if (CommandMap[left].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(-Speed, 0);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && LeftAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = LeftAnimation;
            }
            if (CommandMap[right].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(Speed, 0);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && RightAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = RightAnimation;
            }

            var pos = Owner.QueryComponent<Identity2D>().Transform.Position;

            if(oldPosition == pos)
                if (Owner.HasComponent<SpriteAnimator>() && Animate)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = null;

            if (Owner.HasComponent<SpriteOscillator>() && Bobbing)
                Owner.QueryComponent<SpriteOscillator>().Oscillate = oldPosition != pos;
            oldPosition = pos;
        }
Esempio n. 28
0
 public void Update(Playstates.PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
 }
Esempio n. 29
0
        public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var screenCoordinates = Worldspawn.Camera.Viewport;
            var x = (int) ((screenCoordinates.Left/TileSize).Floor());
            var y = (int) ((screenCoordinates.Top/TileSize).Floor());
            var w = (int) ((screenCoordinates.Width/TileSize).Floor()) + 2;
            var h = (int) ((screenCoordinates.Height/TileSize).Floor()) + 2;

            var identity2D = Owner.QueryComponent<Identity2D>();
            var transform = identity2D.Transform;
            var region = Tileset.Region;
            var size = Tileset.Size;
            var emptyTransform = Transform2D.Identity;
            var depth = Tileset.Depth;

            Tileset.Size = new Size2D<int>(TileSize, TileSize);

            for (int i = x; i < x + w; i++)
            {
                for (int j = y; j < y + h; j++)
                {
                    for (int k = 0; k < Tiles.GetLength(2); k++)
                    {
                        var tile = GetTile(i, j, k);

                        if (tile == null)
                            continue;
                        if (tile.Item1 < 0 || tile.Item2 < 0)
                            continue;

                        Tileset.Region = new Rectangle<int>(tile.Item1*TileSize, tile.Item2*TileSize, TileSize, TileSize);
                        Tileset.Depth = Tiles.GetLength(2) == 1
                            ? MinDepth
                            : Maths.Lerp(MinDepth, MaxDepth, (float) k/(Tiles.GetLength(2) - 1));
                        emptyTransform.Position = new Vector2(i*TileSize, j*TileSize) - Center;
                        ServiceLocator.GraphicsService.Draw(Tileset,
                            Transform2D.Compose(emptyTransform, identity2D.CameraTransform));

                    }
                    emptyTransform.Position += new Vector2(0, TileSize);
                }
            }

            identity2D.Transform = transform;
            Tileset.Region = region;
            Tileset.Size = size;
            Tileset.Depth = depth;
        }
Esempio n. 30
0
 public abstract void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID);
Esempio n. 31
0
 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
 }
Esempio n. 32
0
        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var sprite = Owner.QueryComponent<SpriteHolder>();

            if (CurrentAnimation == null)
            {
                sprite.Sprite.Region = Animations[lastAnimation].First();
                return;
            }

            var animation = Animations[CurrentAnimation];

            sprite.Sprite.Region = animation[i];

            j = (j + 1) % (animation.Length * (int)frameDuration);
            i = (j / (float)frameDuration).IntegerPart();
        }
Esempio n. 33
0
 public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     camera = Worldspawn.Camera;
 }
 public Vector2 GetPosition(Worldspawn Worldspawn, Camera2D Owner)
 {
     return Displacement;
 }