Example #1
0
 private void OnColides(ColiderComponent colider, FloatRect overlap)
 {
     if(colider.MyEntity.HasComponent<Player>() &&
        StateManager.Instance.CurrentState is LevelState )
     {
         var levelState = StateManager.Instance.CurrentState as LevelState;
         levelState.CurrentLevel++;
     }
 }
Example #2
0
 public override void Init(Entity entity)
 {
     base.Init(entity);
     if(MyEntity.HasComponent<ColiderComponent>())
     {
         myColider = MyEntity.GetComponent<ColiderComponent>();
         myColider.Colides += OnColide;
     }
 }
Example #3
0
 public static Entity LevelEnd(int x, int y)
 {
     var entity = new Entity();
     entity.Transform.Origin = new Vector2f(TILE_SIZE / 2f, TILE_SIZE / 2f);
     entity.Transform.Position = new Vector2f(x * TILE_SIZE, y * TILE_SIZE);
     var hitbox = new FloatRect(0, 0, TILE_SIZE, TILE_SIZE);
     var colider = new ColiderComponent(hitbox);
     var end = new LevelEnd();
     entity.AddComponent(colider);
     entity.AddComponent(end);
     return entity;
 }
Example #4
0
 public static Entity Box(int x, int y)
 {
     var entity = new Entity();
     var texture = ResourceManager.Instance.Get<Texture>("rock" + Randomizer.Generator.Next(1, 3) + ".png");
     entity.Transform.Origin = new Vector2f(texture.Size.X / 2f, texture.Size.Y / 2f);
     entity.Transform.Position = new Vector2f(x * texture.Size.X, y * texture.Size.Y);
     var sprite = new SpriteComponent(texture);
     var hitbox = new FloatRect(0, 0, texture.Size.X, texture.Size.Y);
     var colider = new ColiderComponent(hitbox);
     var box = new Solid();
     entity.AddComponent(sprite);
     entity.AddComponent(colider);
     entity.AddComponent(box);
     return entity;
 }
Example #5
0
        private void OnColide(ColiderComponent otherColider, FloatRect overlap)
        {
            rectangle = new RectangleShape(new Vector2f(overlap.Width, overlap.Height));
            rectangle.Position = new Vector2f(overlap.Left, overlap.Top);
            rectangle.OutlineThickness = 1;
            rectangle.OutlineColor = Color.Yellow;
            rectangle.FillColor = new Color(0, 0, 0, 0);
            Console.WriteLine(overlap);

            if (overlap.Width < overlap.Height)
            {
                if (otherColider.Hitbox.Left + otherColider.Hitbox.Width > myColider.Hitbox.Left &&
                    otherColider.Hitbox.Left + otherColider.Hitbox.Width < myColider.Hitbox.Left + myColider.Hitbox.Width)
                {
                    otherColider.MyEntity.Transform.Position -= new Vector2f(overlap.Width, 0);
                }
                if (otherColider.Hitbox.Left > myColider.Hitbox.Left &&
                     otherColider.Hitbox.Left < myColider.Hitbox.Left + myColider.Hitbox.Width)
                {
                    otherColider.MyEntity.Transform.Position += new Vector2f(overlap.Width, 0);
                }
            }
            else
            {
                if (otherColider.Hitbox.Top + otherColider.Hitbox.Height > myColider.Hitbox.Top &&
                    otherColider.Hitbox.Top + otherColider.Hitbox.Height < myColider.Hitbox.Top + myColider.Hitbox.Height)
                {
                    otherColider.MyEntity.Transform.Position -= new Vector2f(0, overlap.Height);
                }
                if (otherColider.Hitbox.Top > myColider.Hitbox.Top &&
                     otherColider.Hitbox.Top < myColider.Hitbox.Top + myColider.Hitbox.Height)
                {
                    otherColider.MyEntity.Transform.Position += new Vector2f(0, overlap.Height);
                }
            }
        }
Example #6
0
 public void Colide(ColiderComponent colider, FloatRect overlap)
 {
     var handler = Colides;
     if (handler != null)
         handler(colider, overlap);
 }
Example #7
0
 public static Entity Player(int x, int y)
 {
     var entity = new Entity();
     var texture = ResourceManager.Instance.Get<Texture>("BlueDude.png");
     entity.Transform.Origin = new Vector2f(texture.Size.X / 2f, texture.Size.Y / 2f);
     entity.Transform.Position = new Vector2f(x * texture.Size.X, y * texture.Size.Y);
     var sprite = new SpriteComponent(texture);
     var hitbox = new FloatRect(0, 0, texture.Size.X, texture.Size.Y);
     var colider = new ColiderComponent(hitbox);
     var player = new Player();
     entity.AddComponent(sprite);
     entity.AddComponent(colider);
     entity.AddComponent(player);
     return entity;
 }