예제 #1
0
    GetSelf UpdateRock(GetSelf self)
    {
        var lastBullet   = self();
        var lastPosition = lastBullet.Item1;
        var velocity     = lastBullet.Item2;
        var rotation     = lastBullet.Item3;
        var type         = lastBullet.Item4;
        var lifetime     = (float)lastBullet.Item6;

        lifetime = lifetime - Time.deltaTime;

        if (lifetime < 0)
        {
            return(null);
        }
        if (TestCollision(self, ObjectType.MyBullet).Any())
        {
            CreateParticles(lastPosition, RockParticleSpeed, RockParticleLife, 30, Color.red);
            return(null);
        }

        var position = lastPosition + Time.deltaTime * velocity;
        var result   = Tuple.Create(position, velocity, rotation, type, lastBullet.Item5, (object)lifetime);

        return(() => result);
    }
예제 #2
0
    GetSelf UpdateParticle(GetSelf self)
    {
        var lastBullet   = self();
        var lastPosition = lastBullet.Item1;
        var velocity     = lastBullet.Item2;

        velocity += Vector3.down * Gravity * Time.deltaTime;
        var type = lastBullet.Item4;

        var item6    = (Tuple <Vector3, Color>)lastBullet.Item6;
        var lifetime = item6.Item1.x - Time.deltaTime;

        if (lifetime < 0)
        {
            return(null);
        }

        var rotation = lastBullet.Item3 * Quaternion.Euler(0, 0, Time.deltaTime * item6.Item1.z);
        var position = lastPosition + Time.deltaTime * velocity;
        var result   = Tuple.Create(
            position,
            velocity,
            rotation,
            type,
            lastBullet.Item5,
            (object)Tuple.Create(new Vector3(lifetime, item6.Item1.y, item6.Item1.z), item6.Item2));

        return(() => result);
    }
예제 #3
0
    GetDraw DrawMyBullet(GetSelf getSelf)
    {
        var position = getSelf().Item1;
        var rotation = getSelf().Item3;
        var scale    = (1f / 80) * Vector3.one;
        var color    = Color.yellow;
        var verts    = new[]
        { new Vector3(-0.2f, -0.7f), new Vector3(-0.2f, 0.7f), new Vector3(0.2f, 0.7f), new Vector3(0.2f, -0.7f) };
        var tuple = Tuple.Create(position, scale, rotation, color, verts);

        return(() => tuple);
    }
예제 #4
0
    static GetDraw DrawPlayer(GetSelf getSelf)
    {
        var position = getSelf().Item1;
        var rotation = getSelf().Item3;
        var scale    = (1f / 40) * Vector3.one;
        var color    = Color.cyan;
        var verts    = new[]
        { new Vector3(0, 0.6f), new Vector3(0.4f, -0.3f), new Vector3(0, -0.6f), new Vector3(-0.4f, -0.3f) };
        var tuple = Tuple.Create(position, scale, rotation, color, verts);

        return(() => tuple);
    }
예제 #5
0
    // Item1 : Position
    // Item2 : Velocity
    // Item3 : Rotation
    // Item4 : Object Type
    // Item5 : Collision Radius
    // Item6 : Lifetime
    Tuple <GetSelf, OnUpdate, DrawSelf> CreateEnemyBullet(Vector3 position, Quaternion rotation, Vector3 velocity)
    {
        GetSelf getSelf = () =>
                          Tuple.Create(
            position,
            velocity,
            rotation,
            ObjectType.EnemyBullet,
            1f / 160,
            (object)(RockRadius * 2 / velocity.magnitude));

        return(Tuple.Create <GetSelf, OnUpdate, DrawSelf>(getSelf, UpdateEnemyBullet, DrawEnemyBullet));
    }
예제 #6
0
    Tuple <GetSelf, OnUpdate, DrawSelf> CreatePlayer()
    {
        GetSelf getSelf = () =>
                          Tuple.Create(
            Vector3.zero,
            Vector3.zero,
            Quaternion.identity,
            ObjectType.Player,
            1f / 80,
            (object)0f);

        return(Tuple.Create <GetSelf, OnUpdate, DrawSelf>(getSelf, UpdatePlayer, DrawPlayer));
    }
예제 #7
0
    // Item1 : Position
    // Item2 : Velocity
    // Item3 : Rotation
    // Item4 : Object Type
    // Item5 : Collision Radius
    // Item6 : Lifetime
    Tuple <GetSelf, OnUpdate, DrawSelf> CreateMyBullet(Vector3 position, Quaternion rotation, Vector3 velocity)
    {
        var     bulletDirection = rotation * Quaternion.Euler(0, 0, Random.Range(-ShotSpread, ShotSpread));
        GetSelf getSelf         = () =>
                                  Tuple.Create(
            position,
            bulletDirection * Vector3.up * BulletSpeed + velocity,
            bulletDirection,
            ObjectType.MyBullet,
            1f / 160,
            (object)1f);

        return(Tuple.Create <GetSelf, OnUpdate, DrawSelf>(getSelf, UpdateMyBullet, DrawMyBullet));
    }
예제 #8
0
    // Item1 : Position
    // Item2 : Velocity
    // Item3 : Rotation
    // Item4 : Object Type
    // Item5 : Collision Radius
    // Item6 : {[Time, Lifetime, Angular velocity], Color}
    Tuple <GetSelf, OnUpdate, DrawSelf> CreateParticle(Vector3 position, Quaternion rotation, Vector3 velocity,
                                                       float lifetime, Color color)
    {
        var     angularVelocity = Random.Range(-ParticleAngularSpeed, ParticleAngularSpeed);
        GetSelf getSelf         = () =>
                                  Tuple.Create(
            position,
            velocity,
            rotation,
            ObjectType.Particle,
            1f / 160,
            (object)Tuple.Create(new Vector3(lifetime, lifetime, angularVelocity), color));

        return(Tuple.Create <GetSelf, OnUpdate, DrawSelf>(getSelf, UpdateParticle, DrawParticle));
    }
예제 #9
0
    GetDraw DrawRock(GetSelf getSelf)
    {
        var position = getSelf().Item1;
        var rotation = getSelf().Item3;
        var scale    = (1f / 30) * Vector3.one;
        var color    = Color.red;
        var verts    = new[]
        {
            new Vector3(0, -0.7f), new Vector3(-0.5f, -0.2f), new Vector3(-0.5f, 0.2f), new Vector3(0f, 0.7f),
            new Vector3(0, -0.7f), new Vector3(0.5f, -0.2f), new Vector3(0.5f, 0.2f), new Vector3(0f, 0.7f)
        };
        var tuple = Tuple.Create(position, scale, rotation, color, verts);

        return(() => tuple);
    }
예제 #10
0
    GetSelf UpdatePlayer(GetSelf player)
    {
        var lastPlayer   = player();
        var lastPosition = lastPlayer.Item1;
        var lastVelocity = lastPlayer.Item2;
        var lastRotation = lastPlayer.Item3;
        var type         = lastPlayer.Item4;
        var cooldown     = (float)lastPlayer.Item6;

        var velocity = lastVelocity * (1 - Time.deltaTime * Damp) + (Vector3)(Acceleration * input);
        var position = lastPosition + Time.deltaTime * velocity;

        if (position.x > 0.5f / widthScale)
        {
            position.x -= 1 / widthScale;
        }
        if (position.x < -0.5f / widthScale)
        {
            position.x += 1 / widthScale;
        }
        if (position.y > 0.5f)
        {
            position.y -= 1;
        }
        if (position.y < -0.5f)
        {
            position.y += 1;
        }
        var rotation = Quaternion.Lerp(lastRotation,
                                       Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(-velocity.x, velocity.y)), 0.5f);

        if (TestCollision(player, ObjectType.Rock | ObjectType.EnemyBullet).Any())
        {
            CreateParticles(position, PlayerParticleSpeed, PlayerParticleLife, 50, Color.cyan);
            return(null);
        }

        cooldown = Mathf.Max(0f, cooldown - Time.deltaTime);
        if (Input.GetButton("Jump") && cooldown <= 0)
        {
            objectList.Add(CreateMyBullet(position, rotation, velocity));
            cooldown += 1 / ShotRate;
        }

        var result = Tuple.Create(position, velocity, rotation, type, lastPlayer.Item5, (object)cooldown);

        return(() => result);
    }
예제 #11
0
    GetDraw DrawParticle(GetSelf getSelf)
    {
        var position = getSelf().Item1;
        var rotation = getSelf().Item3;
        var item6    = (Tuple <Vector3, Color>)getSelf().Item6;
        var lifeRate = item6.Item1.x / item6.Item1.y;
        var color    = item6.Item2;

        color.a *= lifeRate;
        var scale = (1f / 80) * Vector3.one;
        var verts = new[]
        { new Vector3(-0.3f, -0.6f), new Vector3(-0.3f, 0.6f), new Vector3(0.3f, 0.6f), new Vector3(0.3f, -0.6f) };
        var tuple = Tuple.Create(position, scale, rotation, color, verts);

        return(() => tuple);
    }
예제 #12
0
 IEnumerable <GetSelf> TestCollision(GetSelf toTest, ObjectType filter)
 {
     foreach (var obj in objectList.Where(o => o != null && (o.Item1().Item4 & filter) != 0))
     {
         if (obj.Item1 == null)
         {
             continue;
         }
         var one   = toTest();
         var other = obj.Item1();
         var dist  = Vector3.Distance(one.Item1, other.Item1);
         if (dist < one.Item5 + other.Item5)
         {
             yield return(obj.Item1);
         }
     }
 }
예제 #13
0
    GetSelf UpdateEnemyBullet(GetSelf self)
    {
        var lastBullet   = self();
        var lastPosition = lastBullet.Item1;
        var velocity     = lastBullet.Item2;
        var rotation     = lastBullet.Item3;
        var type         = lastBullet.Item4;
        var lifetime     = (float)lastBullet.Item6;

        lifetime = lifetime - Time.deltaTime;
        if (lifetime < 0)
        {
            return(null);
        }

        var position = lastPosition + Time.deltaTime * velocity;
        var result   = Tuple.Create(position, velocity, rotation, type, lastBullet.Item5, (object)lifetime);

        return(() => result);
    }
예제 #14
0
 ActorRef On(GetSelf _) => Self;