Beispiel #1
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);
     }
 }
Beispiel #2
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;
        }
Beispiel #3
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);
        }
Beispiel #4
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 });
         }
     }
 }
Beispiel #5
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 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;
        }
Beispiel #7
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;
        }
Beispiel #8
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;
        }
Beispiel #9
0
 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
 }
Beispiel #10
0
 public abstract void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID);
Beispiel #11
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if(Sprite != null)
         ServiceLocator.GraphicsService.Draw(Sprite, Owner.QueryComponent<Identity2D>().CameraTransform);
 }
Beispiel #12
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;
            }
        }
Beispiel #13
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     ServiceLocator.GraphicsService.Draw(MoverSprite, new Transform2D(moverPosition, 0f, Vector2.One));
 }
Beispiel #14
0
 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
 }
Beispiel #15
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();
        }
Beispiel #16
0
 public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     camera = Worldspawn.Camera;
 }
Beispiel #17
0
 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if (invencibilityFrameCounter > -1) invencibilityFrameCounter--;
 }