Пример #1
0
 public NffParserScene(Camera camera, IHitable world, IHitable lightHitable, Func <Ray, ColorVector> backgroundFunc)
 {
     _camera         = camera;
     _world          = world;
     _lightHitable   = lightHitable;
     _backgroundFunc = backgroundFunc;
 }
Пример #2
0
    public void defaultEffect(IHitable target, EffectType effectType)
    {
        //!TODO :콜리전 정보를 받아와서 살짝의 랜덤을 준 위치에 생성하는것도 만들 것
        if (effectType == EffectType.NONE)
        {
            return;
        }
        if (target.showEffect == false)
        {
            return;
        }
        var e = GetEffectFromPool(effectType);

        e.transform.position = target.transform.position;
        e.gameObject.SetActive(true);
        //e.GetComponent<Effector>().Disable(0.5f).Play();
        if (effectType == EffectType.SMALL)
        {
            smallHit();
        }
        if (effectType == EffectType.MID)
        {
            midHit();
        }
    }
Пример #3
0
 public LoggedHit(IHitable target, HitboxType part, Gun gun, RaycastHit raycastHit) : base()
 {
     this.gun        = gun;
     this.raycastHit = raycastHit;
     this.target     = target;
     this.part       = part;
 }
Пример #4
0
    AttackMessage rushHandle(IHitable target, FSMbase sender, float attackPoint)
    {
        m.FinalDamage = sender.status.getCurrentStat(STAT.AtkPoint) * attackPoint;

        target.status.AddBuff(new Pierced(pierceTime, target));

        Vector2    dir           = (target.transform.position - sender.transform.position).normalized;
        Vector3    v3Original    = chargeDir;
        Quaternion firstRotation = Quaternion.FromToRotation(v3Original, dir);
        float      dirDot        = firstRotation.eulerAngles.z;
        Vector3    v3Dest;
        Quaternion qUpDir;
        float      reflectionValue = 0;

        if (dirDot >= 0 && dirDot < 180)
        {
            qUpDir = Quaternion.Euler(0, 0, 90);
        }
        else
        {
            qUpDir          = Quaternion.Euler(0, 0, -90);
            reflectionValue = 180;
        }

        v3Original = qUpDir * v3Original;
        float secondRotation = Quaternion.FromToRotation(dir, v3Original).eulerAngles.z * 0.5f;

        v3Dest = Quaternion.Euler(0, 0, dirDot + secondRotation + reflectionValue) * chargeDir;

        v3Dest.Normalize();

        m.CalcKnockBack(v3Dest, 3);
        return(m);
    }
Пример #5
0
        public override void Attack(IAttacker attacker, Vector3 direction)
        {
            if (!IsAvailableToShoot)
            {
                return;
            }
            IEnumerable <RaycastHit> allhits = GetAllHits(transform.position, direction);

            allhits = allhits.Except(allhits.Where(hit => attacker.Equals(hit.transform.GetComponent <IAttacker>())));
            foreach (RaycastHit hit in allhits)
            {
                IHitable target = hit.collider.gameObject.GetComponent <IHitable>();
                if (target != null)
                {
                    HitArgs hitInfo = HitArgs.CreateBuilder().SetDirection(direction).SetAttacker(attacker).SetDamage(this);
                    target.GetStrike(hitInfo);
                }
                else
                {
                    HitAnimation(hit.point);
                }
            }
            ShotAnimation();
            ShotSound();
            lastShot = Time.time;
        }
Пример #6
0
    private void Explode()
    {
        Analytics.CustomEvent("SuccessfulDunk", new Dictionary <string, object> {
            { "Zone", GameManager.GetCurrentZoneName() },
        });
        BallBehaviour i_ball = passController.GetBall();

        ChangeState(DunkState.Explosing);
        if (playerController != null)
        {
            EnergyManager.DecreaseEnergy(energyPercentLostOnSuccess);
        }
        List <IHitable> i_hitTarget = new List <IHitable>();

        Collider[] i_hitColliders = Physics.OverlapSphere(i_ball.transform.position, dunkExplosionRadius);
        int        i = 0;

        while (i < i_hitColliders.Length)
        {
            IHitable i_potentialHitableObject = i_hitColliders[i].GetComponentInParent <IHitable>();
            if (i_potentialHitableObject != null && !i_hitTarget.Contains(i_potentialHitableObject))
            {
                i_potentialHitableObject.OnHit(i_ball, (i_hitColliders[i].transform.position - transform.position).normalized, pawnController, dunkDamages, DamageSource.Dunk);
                i_hitTarget.Add(i_potentialHitableObject);
            }
            i++;
        }
        ChangeState(DunkState.None);
    }
Пример #7
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IHitable hitable = collision.GetComponentInParent <IHitable>();

        if (hitable != null)
        {
            if (shotBy)
            {
                if (collision.transform.IsChildOf(shotBy.transform))
                {
                    return;
                }
            }

            hitable.Hit(this, out bool _destroy);
            if (_destroy)
            {
                DestroyProjectile();
            }
        }
        else
        {
            if (ImpactSounds.Length > 0 && (Time.time - shotTime) > MinSoundLifetime)
            {
                SoundManager.instance.PlaySound(ImpactSounds[Random.Range(0, ImpactSounds.Length)], transform.position, ImpactVolume);
            }

            DestroyProjectile();
        }
    }
        static void Main(string[] args)
        {
            int nx = 300;
            int ny = 300;
            int ns = 50;

            var(world, cam) = Scenes.CornellScene("../../../../SampleObj/teapot.obj", new SunsetquestRandom(), nx, ny);

            var worldBVH = new BVH(world);
            var wl       = new IHitable[] { worldBVH };

            var  pathTracer    = new PathTracer(nx, ny, ns, false);
            uint totalRayCount = 0;

            sw.Start();
            var image = pathTracer.RenderScene(wl, cam, ref totalRayCount, (pcComplete => Console.WriteLine($"{pcComplete}%")));

            sw.Stop();
            image.Save("test.png");
            float seconds = sw.ElapsedMilliseconds / 1000f;
            float rate    = totalRayCount / seconds;
            float mRate   = rate / 1_000_000;

            Console.WriteLine($"totalRayCount: {totalRayCount}");
            Console.WriteLine($"BVH max depth: {worldBVH.MaxTestCount}");
            Console.WriteLine($"Duration: {seconds} | Rate: {mRate} MRays / sec.");
        }
Пример #9
0
    AttackMessage flameHandle(IHitable target, FSMbase sender, float attackPoint)
    {
        m.FinalDamage = sender.status.getCurrentStat(STAT.AtkPoint) * attackPoint;

        target.status.AddBuff(new Burn(burnTime, burnDmg, target));
        return(m);
    }
Пример #10
0
        public Image <Rgba32> Render(Camera camera, IHitable world)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var image = new Image <Rgba32>(this.imageWidth, this.imageHeight);

            Console.WriteLine("Rendering scene... ");
            using var progress = new ProgressBar();
            {
                int completeLines = 0;
                Parallel.For(0, this.imageHeight, j =>
                {
                    Span <Rgba32> rowSpan = image.GetPixelRowSpan(this.imageHeight - j - 1);
                    for (int i = 0; i < this.imageWidth; i++)
                    {
                        Vector3 colour = Vector3.Zero;
                        for (int s = 0; s < this.samplesPerPixel; s++)
                        {
                            float u = (float)(i + StaticRandom.NextDouble()) / this.imageWidth;
                            float v = (float)(j + StaticRandom.NextDouble()) / this.imageHeight;
                            Ray ray = camera.GetRay(u, v);
                            colour += Colour(in ray, world, 0);
                        }

                        colour /= (float)this.samplesPerPixel;
                        colour  = new Vector3((float)Math.Sqrt(colour.X), (float)Math.Sqrt(colour.Y),
                                              (float)Math.Sqrt(colour.Z));
                        rowSpan[i] = new Rgba32(colour);
                    }
Пример #11
0
    public IEnumerator Slash()
    {
        AudioManager.Play("Slashy_hit");
        this.state = SlashyStates.Hit;

        this.Animator.SetTrigger("attack");

        yield return(new WaitForSeconds(0.5f));

        Vector2 center = this.Transform.position;
        var     offset = new Vector2(this.SlashHitBoxOffset.x * this.CharacterController.Direction, this.SlashHitBoxOffset.y);

        center += offset;

        Collider2D[] collided = Physics2D.OverlapAreaAll(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2);
        Debug.DrawLine(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2, Color.green);
        foreach (Collider2D collider in collided)
        {
            IHitable target = collider.gameObject.GetComponent <IHitable>();
            if (collider.gameObject != this.gameObject && target != null)
            {
                target.TakeDamages(this.SlashDamages, this.Transform.position);
            }
        }

        yield return(new WaitForSeconds(0.5f));

        this.state = SlashyStates.Follow;
    }
Пример #12
0
 AttackMessage stingHandle(IHitable target, FSMbase sender, float attackPoint)
 {
     m.effectType     = EffectType.SMALL;
     m.critEffectType = EffectType.CRIT;
     m.FinalDamage    = sender.status.getCurrentStat(STAT.AtkPoint) * attackPoint;
     return(m);
 }
Пример #13
0
        private ColorVector GetRayColor(Ray ray, IHitable world, int depth)
        {
            // the 0.001 corrects for the "shadow acne"
            HitRecord hr = world.Hit(ray, 0.001f, float.MaxValue);

            if (hr != null)
            {
                if (depth < 50)
                {
                    var scatterResult = hr.Material.Scatter(ray, hr);
                    if (scatterResult.IsScattered)
                    {
                        return(scatterResult.Attenuation * GetRayColor(scatterResult.SpecularRay, world, depth + 1));
                    }
                }

                return(ColorVector.Zero);
            }
            else
            {
                var   unitDirection = ray.Direction.ToUnitVector();
                float t             = 0.5f * (unitDirection.Y + 1.0f);
                return((((1.0f - t) * Vector3.One) + (t * new Vector3(0.5f, 0.7f, 1.0f))).ToColorVector());
            }
        }
Пример #14
0
        // -----------------------------------------------------------------------------------
        // Activate
        // -----------------------------------------------------------------------------------
        public virtual void Activate(Character owner, int level = 0)
        {
            owner.AdjustProperty(OnActiveModifier, level);

            foreach (StatusChance tmpl in addStatus)
            {
                owner.states.TryApplyStatus(tmpl.template, tmpl.probability);
            }

            foreach (StatusChance tmpl in removeStatus)
            {
                owner.states.TryRemoveStatus(tmpl.template, tmpl.probability);
            }

            foreach (ItemDropProbability tmpl in createItem)
            {
                Utl.SpawnItem(tmpl, tmpl.spawnProbability, owner.transform.position, dropPrefab);
            }

            if (dealDamage != null)
            {
                IHitable hitable = owner.gameObject.GetComponent(typeof(IHitable)) as IHitable;
                if (hitable != null)
                {
                    hitable.Hit(new HitInfo(dealDamage, owner.transform.position, false, null, level));
                }
            }
        }
Пример #15
0
 public Element(EntityId id, IHitable hitable, IScatterable scatterable, IPositionable positionable)
 {
     Id           = id;
     Hitable      = hitable;
     Scatterable  = scatterable;
     Positionable = positionable;
 }
Пример #16
0
        public VolumeScene(double aspect)
        {
            var red   = new Lambertian(ConstantTexture.Create(0.65, 0.05, 0.05));
            var white = new Lambertian(ConstantTexture.Create(0.73, 0.73, 0.73));
            var green = new Lambertian(ConstantTexture.Create(0.12, 0.45, 0.12));
            var light = new DiffuseLight(ConstantTexture.Create(7, 7, 7));
            var box1  = new Translate(new RotateY(new Box(Vec3.Create(0), Vec3.Create(165), white), -18), Vec3.Create(130, 0, 65));
            var box2  = new Translate(new RotateY(new Box(Vec3.Create(0), Vec3.Create(165, 330, 165), white), 15), Vec3.Create(265, 0, 295));

            IHitable[] hitables =
            {
                new FlipNormals(new YZRect(0,  555,                                    0, 555, 555, green)),
                new YZRect(0,                  555,                                    0, 555,   0, red),
                new XZRect(113,                443,                                  127, 432, 554, light),
                new FlipNormals(new XZRect(0,  555,                                    0, 555, 555, white)),
                new XZRect(0,                  555,                                    0, 555,   0, white),
                new FlipNormals(new XYRect(0,  555,                                    0, 555, 555, white)),
                new ConstantMedium(box1,      0.01, new ConstantTexture(Vec3.Create(1))),
                new ConstantMedium(box2,      0.01, new ConstantTexture(Vec3.Create(0))),
            };
            World = new BVHNode(hitables, 0, 1);
            var    lookFrom      = Vec3.Create(278, 278, -800);
            var    lookAt        = Vec3.Create(278, 278, 0);
            double dist_to_focus = 10;
            double aderpture     = 0;
            double vfov          = 40;

            Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), vfov, aspect, aderpture, dist_to_focus);
        }
Пример #17
0
 public void onWeaponTouch(int colliderType, IHitable target)
 {
     //!TODO fsm만이 아니라 그냥 오브젝트들도 다 되게 할 것
     if (attackedColliders.Contains(target))
     {
         return;
     }
     attackedColliders.Add(target);
     if (colliderType == 0)
     {
         m.effectType = EffectType.MID;
         if (tempAtkCount == 1)
         {
             AttackManager.GetInstance().HandleAttack(AttackHandle, target, player, Damages[tempAtkCount] * 4, false, true);
         }
         else
         {
             AttackManager.GetInstance().HandleAttack(AttackHandle, target, player, Damages[tempAtkCount] * 4);
         }
     }
     else
     {
         m.effectType = EffectType.SMALL;
         AttackManager.GetInstance().HandleAttack(AttackHandle, target, player, Damages[tempAtkCount]);
     }
 }
Пример #18
0
    public BVHNode(List <IHitable> l, int n, double time0, double time1)
    {
        AABB boxLeft, boxRight;
        int  axis = 3 * (int)RandomDouble();

        if (axis == 0)
        {
            l.Sort((a, b) =>
            {
                if (!a.BoundingBox(0, 0, out boxLeft) || !b.BoundingBox(0, 0, out boxRight))
                {
                    throw new Exception();
                }
                return(boxLeft.Min.X.CompareTo(boxRight.Min.X));
            });
        }
        else if (axis == 1)
        {
            l.Sort((a, b) =>
            {
                if (!a.BoundingBox(0, 0, out boxLeft) || !b.BoundingBox(0, 0, out boxRight))
                {
                    throw new Exception();
                }
                return(boxLeft.Min.Y.CompareTo(boxRight.Min.Y));
            });
        }
        else
        {
            l.Sort((a, b) =>
            {
                if (!a.BoundingBox(0, 0, out boxLeft) || !b.BoundingBox(0, 0, out boxRight))
                {
                    throw new Exception();
                }
                return(boxLeft.Min.Z.CompareTo(boxRight.Min.Z));
            });
        }
        if (n == 1)
        {
            left = right = l[0];
        }
        else if (n == 2)
        {
            left  = l[0];
            right = l[1];
        }
        else
        {
            left  = new BVHNode(l, n / 2, time0, time1);
            right = new BVHNode(l.Skip(n / 2).ToList(), n - n / 2, time0, time1);
        }
        if (!left.BoundingBox(time0, time1, out boxLeft) ||
            !right.BoundingBox(time0, time1, out boxRight))
        {
            throw new Exception();
        }
        box = SurroundingBox(boxLeft, boxRight);
    }
Пример #19
0
        public CornellBoxScene()
        {
            var light = new DiffuseLight(new ColorTexture(15.0f, 15.0f, 15.0f));
            var glass = new DialectricMaterial(1.5f);

            _light       = new XzRect(213.0f, 343.0f, 227.0f, 332.0f, 554.0f, light);
            _glassSphere = new Sphere(new Vector3(190.0f, 90.0f, 190.0f), 90.0f, glass);
        }
Пример #20
0
    void OnTriggerEnter(Collider other)
    {
        IHitable hitable = other.gameObject.GetComponent(typeof(IHitable)) as IHitable;

        if (hitable != null)
        {
            hitable.Hit(new HitInfo(damage, transform.position, false, HitInfo.HitSources.Enviroment));
        }
    }
Пример #21
0
    public override void Apply(GameObject go)
    {
        IHitable targ = go.GetComponent <IHitable>();

        if (targ != null)
        {
            targ.Hit(_amount);
        }
    }
Пример #22
0
    AttackMessage ThunderHandle(IHitable target, FSMbase sender, float attackPoint)
    {
        m.effectType     = EffectType.MID;
        m.critEffectType = EffectType.CRIT;
        m.FinalDamage    = sender.status.getCurrentStat(STAT.AtkPoint) * attackPoint;

        target.status.AddBuff(new Electrified(1, target));
        return(m);
    }
Пример #23
0
    public virtual void OnTriggerEnter(Collider other)
    {
        IHitable hittable = other.GetComponent <IHitable>();

        if (hittable != null && (object)hittable != thrower)
        {
            hittable.Hit(this);
        }
    }
Пример #24
0
        public IEnumerator Launch()
        {
            if (!_canAttackMele)
            {
                yield break;
            }

            // initialisation
            this._isMeleAttacking        = true;
            this.PlayerStats.IsInvicible = true;

            // animate
            this.Animator.SetBool("PlayerMele", true);

            // activation
            this.Rigidbody.velocity = Vector2.right * this.PushForce * this.CharacterController.Direction;
            yield return(new WaitForSeconds(this.MeleTimeBeforeHit));

            Vector2 center = this.Transform.position;
            var     offset = new Vector2(this.MeleHitBoxOffset.x * this.CharacterController.Direction, this.MeleHitBoxOffset.y);

            center += offset;

            Collider2D[] collided = Physics2D.OverlapAreaAll(center - this.MeleHitboxSize / 2, center + this.MeleHitboxSize / 2);
            foreach (Collider2D collider in collided)
            {
                IHitable target = collider.gameObject.GetComponent <IHitable>();
                if (collider.gameObject != this.gameObject && target != null)
                {
                    target.TakeDamages(this.MeleDamages, this.Transform.position);
                }
            }

            yield return(new WaitForSeconds(this.MeleTimeBetweenHits));

            center   = this.Transform.position;
            collided = Physics2D.OverlapAreaAll(center - this.MeleHitboxSize / 2, center + this.MeleHitboxSize / 2);
            foreach (Collider2D collider in collided)
            {
                IHitable target = collider.gameObject.GetComponent <IHitable>();
                if (collider.gameObject != this.gameObject && target != null)
                {
                    target.TakeDamages(this.MeleDamages, this.Transform.position);
                }
            }

            this._isMeleAttacking = false;

            this.Animator.SetBool("PlayerMele", false);
            this.PlayerStats.IsInvicible = false;

            // cooldown
            this._meleCooldown = true;
            yield return(new WaitForSeconds(this.MeleAttackCoolDown));

            this._meleCooldown = false;
        }
    public void CollideWith(Collider2D collision)
    {
        IHitable hitOptions = collision.GetComponentInParent <IHitable>();

        if (hitOptions != null)
        {
            hitOptions.Hit(damage);
        }
    }
Пример #26
0
 public Burn(float time, float Dmg, IHitable target)
 {
     buffName     = BUFF.Burn;
     totalTime    = time;
     Damage       = Dmg;
     dealTime     = 0;
     dealedDamage = 0;
     SetTarget(target);
 }
Пример #27
0
 public Poisoned(float time, float Dmg, IHitable target)
 {
     buffName     = BUFF.Bleeding;
     totalTime    = time;
     Damage       = Dmg;
     dealTime     = 0;
     dealedDamage = 0;
     SetTarget(target);
 }
Пример #28
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Destroy(gameObject);
        IHitable hitable = collision.collider.GetComponent <IHitable>();

        if (hitable != null)
        {
            hitable.Hit(damage);
        }
    }
Пример #29
0
 public void onWeaponTouch(int colliderType, IHitable target)
 {
     if (attackedColliders.Contains(target))
     {
         return;
     }
     //!TODO 한 공격에 한번만 맞게 할 것
     attackedColliders.Add(target);
     AttackManager.GetInstance().HandleAttack(stingHandle, target, player, 0.4f);
 }
Пример #30
0
    public void CollideWith(Collider2D collision)
    {
        IHitable hitOptions = collision.GetComponentInParent <IHitable>();

        if (hitOptions != null)
        {
            Debug.Log("AirAttackSwing");
            hitOptions.Hit(damage);
        }
    }
Пример #31
0
 /// <summary>
 /// Destroys the level.
 /// </summary>
 public void DestroyLevel()
 {
     if(visuals != null){
         for(int y = 0; y < visuals.GetLength(1); y++){
             for(int x = 0; x < visuals.GetLength(0); x++){
                 GameObject.Destroy(((MonoBehaviour)visuals[x,y]).gameObject);
                 visuals[x,y] = null;
             }
         }
         GameObject.Destroy((((MonoBehaviour)switchV).gameObject));
         switchV = null;
     }
 }
Пример #32
0
        /// <summary>
        /// Creates the level.
        /// </summary>
        /// <param name="size">Size.</param>
        private void CreateLevel(IntVector2 size)
        {
            visuals = new IGemVisual[size.x,size.y+1];
            for(int y = 0; y < size.y+1; y++){
                for(int x = 0; x < size.x; x++){
                    GameObject c = (GameObject)GameObject.Instantiate(gemVisual,new Vector3(x,-y,0),Quaternion.identity);
                    c.transform.parent = transform;
                    visuals[x,y] = c.GetComponent<IGemVisual>();
                }
            }
            //Create an set the position of the new line switch Visual
            GameObject s = GameObject.Instantiate(switchVisual);
            switchV = (IHitable)s.GetComponent(typeof (IHitable));
            s.transform.position = new Vector3(-2,-size.y+0.5f,0);
            switchV.hitEvent += delegate(int x, int y) { if(newLineEvent != null) newLineEvent.Invoke();};

            //Set the cam on the center of the level
            Vector3 center = new Vector3(size.x / 2, - (size.y / 2), -10);
            gameCam.transform.position = center;

            //Change the size of the camera to fit level
            Vector3 topleft = - new Vector3(0.5f,-0.5f,0f);
            topleft = gameCam.WorldToViewportPoint(topleft);
            float maxV = Mathf.Max (topleft.x, topleft.y);
            gameCam.orthographicSize *= maxV + 0.125f;

            //Change the size of the time bars so they fit over the complite last line.
            timeIndicator.transform.position = new Vector3(-0.5f,-size.y,1);
            timeIndicator.GetChild(0).transform.localScale = new Vector3(size.x / 2 * 100,50,1);
            timeIndicator.GetChild(0).transform.localPosition = new Vector3(size.x / 2f,0,-5);
            timeIndicatorShadow.transform.localScale = new Vector3(size.x / 2 * 100,50,1);
            timeIndicatorShadow.transform.position = new Vector3(size.x / 2f - 0.5f,-size.y,-4);
        }