예제 #1
0
        // system execution
        void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
        {
            for (int i = 0; i < entities.Length; i++)
            {
                //get entity
                ECSEntity entity = entities[i];

                // get data
                PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
                VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

                // manipulate data
                pc.Position += vc.Velocity * Time.DeltaTime;

                // set data
                engine.SetComponent(entity, pc);

                Debug.Log("Entity: " + entity + " - Pos: " + pc.Position, ConsoleColor.Green, entity);

                // other operations
                if (pc.Position.y < -10)
                {
                    Console.Clear();
                    Debug.Log("Destroyed: " + entity, ConsoleColor.Red, entity);

                    // destroy entities
                    engine.DestroyEntity(entity);
                }
            }
        }
예제 #2
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
            VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

            if (Input.IsKeyPressed(KeyCode.W))
            {
                pc.Position.Y -= vc.Velocity.Y * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.S))
            {
                pc.Position.Y += vc.Velocity.Y * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.A))
            {
                pc.Position.X -= vc.Velocity.X * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.D))
            {
                pc.Position.X += vc.Velocity.X * Time.DeltaTime;
            }

            engine.SetComponent <PositionComponent>(entity, pc);
        }
    }
예제 #3
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            TimeComponent tc = engine.GetComponent <TimeComponent>(entity);

            tc.CurrentTime -= Time.DeltaTime;

            if (tc.CurrentTime <= 0f)
            {
                tc.CurrentTime += tc.Time;

                SpawnPointComponent pc = engine.GetComponent <SpawnPointComponent>(entity);

                var enemy = engine.CreateEntity();

                engine.AddComponent <NameComponent>(enemy,
                                                    new NameComponent()
                {
                    Name = "ENEMY"
                });

                engine.AddComponent <PositionComponent>(enemy,
                                                        new PositionComponent()
                {
                    Position = pc.SpawnPoint
                });

                engine.AddComponent <VelocityComponent>(enemy,
                                                        new VelocityComponent()
                {
                    Velocity = new Vector2(0f, 5f)
                });

                engine.AddComponent(enemy, new BoxColliderComponent()
                {
                    Size = new Vector2(1f, 1f)
                });

                engine.AddComponent <SpriteRendererComponent>(enemy,
                                                              new SpriteRendererComponent()
                {
                    RenderOffset = RenderOffset.Player,
                    Texture      = TextureManager.GetTexture("EnemyBlack2"),
                    Sprite       = new Sprite(1f, 1f)
                    {
                        pivot = Vector2.One * 0.5f
                    }
                });

                engine.AddComponent <AIComponent>(enemy, new AIComponent());
            }

            engine.SetComponent <TimeComponent>(entity, tc);
        }
    }
예제 #4
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
            VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

            pc.Position += vc.Velocity * Time.DeltaTime;

            engine.SetComponent <PositionComponent>(entity, pc);
        }
    }
예제 #5
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent       pc  = engine.GetComponent <PositionComponent>(entity);
            SpriteRendererComponent src = engine.GetComponent <SpriteRendererComponent>(entity);

            src.Sprite.position = pc.Position;
            engine.SetComponent <SpriteRendererComponent>(entity, src);

            src.Sprite.DrawTexture(src.Texture);
        }
    }