Пример #1
0
        protected override void OnUpdate()
        {
            // EntityManager em = World.Active.GetOrCreateManager<EntityManager>();
            // NativeArray<Entity> ea = em.ent
            for (int i = 0; i < _enemy.Length; ++i)
            {
                var   entity      = _enemy.Entities[i];
                Enemy en          = _enemy.Enemies[i];
                float blink_timer = _enemy.Blinks[i].Value;
                // float blink_timer = en.HitBlinkTimer;
                // BlinkTrigger bts = _enemy.Triggers[i];

                // MeshInstanceRenderer mr = _enemy.MeshRenderer[i];
                // MeshInstanceRenderer mr = manager.GetSharedComponentData<MeshInstanceRenderer>(entity);
                // Material mat = mr.material;
                if (blink_timer > 0.0f)
                {
                    // mat.SetColor("_Color", Color.red);
                    blink_timer     -= Time.deltaTime;
                    _enemy.Blinks[i] = new BlinkTimer {
                        Value = blink_timer
                    };
                    // _enemy.Enemies[i] = en;
                    // em.SetSharedComponentData<MeshInstanceRenderer>(entity, Bootloader.OnHitOne);
                    PostUpdateCommands.SetSharedComponent(entity, Bootloader.OnHitOne);
                    // nextMat = Bootloader.OnHitOne;
                    // _enemy[i].MeshRenderer = Bootloader.OnHitOne;
                }
                else
                {
                    // mat.SetColor("_Color", DefaultColor);
                    // MeshInstanceRenderer nextMat = Bootloader.OnHitOne;
                    // em.SetSharedComponentData<MeshInstanceRenderer>(entity, Bootloader.EnemyPrefab);
                    PostUpdateCommands.SetSharedComponent(entity, Bootloader.EnemyPrefab);
                }
                // mr.material = mat;
                // _enemy.MeshRenderer[i] = mr;
            }

            for (int i = 0; i < _player.Length; ++i)
            {
                Entity     pe = _player.Entity[i];
                BlinkTimer bt = _player.Blinks[i];
                if (bt.Value > 0.0f)
                {
                    bt.Value         -= Time.deltaTime;
                    _player.Blinks[i] = bt;
                    PostUpdateCommands.SetSharedComponent(pe, Bootloader.OnHitPlayer);
                }
                else
                {
                    PostUpdateCommands.SetSharedComponent(pe, Bootloader.BounceBall);
                }
            }
        }
Пример #2
0
            public void Execute(int index)
            {
                // dmg from enemies to player
                float3               playerPos    = PlayerPos[index].Value;
                Health               playerHealth = PlayerHealth[index];
                BlinkTimer           playerBlink  = Blinks[index];
                HealthDamageCooldown hcd          = HurtCooldown[index];

                for (int i = 0; i < EnemyPos.Length; ++i)
                {
                    float3 enemyPos = EnemyPos[i].Value;
                    float3 distance = enemyPos - playerPos;
                    float  squard   = math.dot(distance, distance);
                    // player been touched
                    if (squard <= PlayerHitboxRadiusSquared && hcd.CanBeHurt)
                    {
                        playerHealth.Value  = math.max(playerHealth.Value - GameSettings.ENEMY_DMG, 0);
                        hcd.Value           = GameSettings.HURT_COOLDOWN;
                        PlayerHealth[index] = playerHealth;
                        HurtCooldown[index] = hcd;
                        playerBlink.Value   = GameSettings.BLINK_TIME * 5;
                        Blinks[index]       = playerBlink;
                    }

/*                  Health enemy_health = EnemyHealth[i];
 *                                      for(int j=0;j<Shots.Length;++j)
 *                                      {
 *                                              // dmg from player shots to enemies
 *                                              float3 shotPos = ShotPos[j].Value;
 *                                              float3 delta = shotPos - enemyPos;
 *                                              float squard_to_bullet = math.dot(delta,delta);
 *                                              Shot s = Shots[j];
 *                                              if(squard_to_bullet <= EnemyHitboxRadiusSquared)
 *                                              {
 *                                                      // destroy bullet
 *                                                      s.TimeToLive = 0.0f;
 *                                                      // -hp
 *                                                      enemy_health.Value -= GameSettings.BULLET_DMG;
 *                                                      Shots[j] = s;
 *                                                      EnemyHealth[i] = enemy_health;
 *                                                      break;
 *                                              }
 *                                      } */
                }
            }
Пример #3
0
            public void Execute(int index)
            {
/*              EnemyHitboxRadiusSquared = 1.0f;
 *                              Shots = _shotsData.Shots;
 *                              ShotPos =_shotsData.ShotPositions;
 *                              EnemyPos = _enemies.Positions; */

                Shot   s          = Shots[index];
                float3 bullet_pos = ShotPos[index].Value;

                for (int j = 0; j < EnemyHealth.Length; ++j)
                {
                    Health     hp         = EnemyHealth[j];
                    float3     pos        = EnemyPos[j].Value;
                    Enemy      en         = Enemies[j];
                    BlinkTimer bt         = Blink[j];
                    float      blinkTimer = bt.Value;

                    float distance = math.dot(bullet_pos - pos, bullet_pos - pos);
                    if (distance <= EnemyHitboxRadiusSquared)
                    {
                        // hit
                        hp.Value -= s.Energy;
                        hp.Value  = math.max(hp.Value, 0);
                        // destroy bullet
                        s.TimeToLive = 0.0f;
                        blinkTimer   = GameSettings.BLINK_TIME;

                        Shots[index]   = s;
                        EnemyHealth[j] = hp;
                        bt.Value       = blinkTimer;
                        Blink[j]       = bt;
                        Enemies[j]     = en;
                    }
                }
            }