Esempio n. 1
0
            public void ProtonTest()
            {
                var p = new Proton(1);

                Assert.AreEqual(1.6726219 * Math.Pow(10, -27), p.RestMass);
                Assert.AreEqual(1, p.RelativeCharge);
                Assert.AreEqual(1, p.BaryonNumber);
            }
Esempio n. 2
0
    public void Generate(int protons, int electrons = -1, int neutrons = -1) //just use H or O
    {
        //deal w default params
        if (electrons == -1)
        {
            electrons = protons;
        }
        if (neutrons == -1)
        {
            neutrons = protons;
        }

        textMeshName = UpdateData(protons, electrons, neutrons);
        Debug.Log("----hallo" + textMeshName);

        int orbits = CalcOrbits(electrons);

        //Protons
        GameObject protContainer = new GameObject();

        protContainer.name = "Protons";

        //before knowing parent!
        protContainer.transform.localScale = new Vector3(1, 1, 1);

        protContainer.transform.parent        = transform;
        protContainer.transform.localPosition = Vector3.zero; //.after knowing parent


        for (int i = 0; i < protons; i++)
        {
            Proton prot = Instantiate <Proton>(myProton);
            prot.transform.parent        = protContainer.transform;
            prot.transform.localPosition = Random.onUnitSphere * spawnDistance;
        }

        //Neutrons
        GameObject neutContainer = new GameObject();

        neutContainer.transform.parent        = transform;
        neutContainer.transform.localPosition = Vector3.zero;
        neutContainer.name = "Neutrons";
        for (int i = 0; i < neutrons; i++)
        {
            Proton neut = Instantiate <Proton>(myNeutron);
            neut.transform.parent        = neutContainer.transform;
            neut.transform.localPosition = Random.onUnitSphere * spawnDistance;
        }

        MakeOrbits(electrons, orbits);
    }
Esempio n. 3
0
    private void Start()
    {
        switch (GetState())
        {
        case State.Jump:
            velocity.y -= JumpForce;
            break;

        case State.Zap:
            Sound.Play("zap.wav", this, 20);
            protonLine.Width   = 128;
            protonLine.Texture = lightningTexture;
            if (Mode != Particle.Proton)
            {
                swapAnim.Play("Proton");
                Mode = Particle.Proton;
            }
            break;

        case State.Hook:
            Sound.Play("grapple.wav", this, 15);
            protonLine.Width   = 32;
            protonLine.Texture = lightningTexture;
            if (Mode != Particle.Electron)
            {
                swapAnim.Play("Electron");
                Mode = Particle.Electron;
            }
            RotateTween(0);
            hookDistance = Mathf.Max(GlobalPosition.DistanceTo(closest.GlobalPosition), MinimumHookLength);
            prevProton   = closest;
            break;

        case State.WallSlide:
            RotateTween(0);
            break;

        case State.WallJump:
            velocity.x = -WallJumpKick *Mathf.Sign(wallCurr.CastTo.x);

            velocity.y = -WallJumpForce;
            break;
        }

        string name = GetState().ToString();

        anim.Play(anim.HasAnimation(name) ? name : "Idle");
    }
Esempio n. 4
0
        public static string FeynmanDiagram(int CollisionNumber, List <Particle.Particle> InputList, List <Particle.Particle> OutputList) //This needs to be changed so it is less hardcoded and can generate diagrams by itself
        {                                                                                                                                 //This currently wirtes streight to the console but uses the classes to do so
            string outputString = "";

            switch (CollisionNumber)
            {
            case 1:
                outputString = InputList[0].FeynmanSymbol + " + " + InputList[1].FeynmanSymbol + " --> " + OutputList[0].FeynmanSymbol + " + " + OutputList[1].FeynmanSymbol;
                break;

            case 2:
                outputString = new Proton(1).FeynmanSymbol + " + " + new Electron(1).FeynmanSymbol + " --> " + new Neutron(1, true).FeynmanSymbol + " + " + new ElectronNeutrino().FeynmanSymbol;
                break;
            }

            return(outputString);
        }
Esempio n. 5
0
    private void UpdateZap()
    {
        const int signCost = 50;

        int sign = Mathf.Sign(velocity.x);

        if (sign == 0)
        {
            sign = lastMoveSign;
        }
        else
        {
            lastMoveSign = sign;
        }

        protonLine.ClearPoints();
        closest = null;

        // A proton is only reachable if it's in range of the circle's area + any number
        float closestDist = Mathf.Pi * ZapDistance * ZapDistance + 0.69420f;

        foreach (Proton body in protonField.GetOverlappingAreas())
        {
            float dist = GlobalPosition.DistanceTo(body.GlobalPosition);

            // prioritize protons in the movement direction
            Vector2 dir = GlobalPosition.DirectionTo(body.GlobalPosition);
            if (dir.x * sign > 0)
            {
                dist -= signCost;
            }

            if (Mathf.Abs(dist) < closestDist && body != prevProton)
            {
                protonRay.CastTo = ToLocal(body.GlobalPosition);
                if (protonRay.IsColliding())
                {
                    continue;
                }
                closestDist = dist;
                closest     = body;
            }
        }
    }
Esempio n. 6
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        wallL.GlobalRotation = wallR.GlobalRotation = 0;

        if (GetState() != State.Zap && GetState() != State.Hook)
        {
            UpdateZap();
            HookAndZap();
        }
        UpdateLine();

        switch (GetState())
        {
        case State.Idle:
            Move();
            if (velocity.x != 0)
            {
                SetState(State.Walk);
            }
            break;

        case State.Jump:
            Move(airAcceleration: 20, airFriction: 0.05f);
            if (!Input.IsActionPressed("Jump"))
            {
                if (velocity.y < -JumpSmooth)
                {
                    velocity.y = -JumpSmooth;
                }
            }

            if (velocity.y >= 0)
            {
                SetState(State.Fall);
            }
            break;

        case State.Walk:
            Move();
            if (velocity == new Vector2())
            {
                SetState(State.Idle);
            }
            break;

        case State.Fall:
            Move(airAcceleration: 20, airFriction: 0.05f);
            if (IsOnFloor())
            {
                SetState(State.Idle);
            }
            break;

        case State.Zap:
            prevProton = closest;

            if (closest == null)
            {
                SetState(State.Idle);
                return;
            }
            const int distanceThreshold = 64;

            velocity = GlobalPosition.DirectionTo(closest.GlobalPosition) * ZapSpeed;

            RotateTween(velocity.Angle() + Mathf.Pi / 2);

            // if inside of proton
            if (GlobalPosition.DistanceTo(closest.GlobalPosition) < distanceThreshold)
            {
                SetState(State.Bounce);

                protonLine.Width   = 1;
                protonLine.Texture = null;
            }

            break;

        case State.Bounce:
            Move(AirAcceleration, AirFriction, ZapSpeed);
            if (IsOnFloor() || IsOnWall() || IsOnCeiling())
            {
                SetState(State.Idle);
            }
            break;

        case State.Hook:
            Move(maxSpeed: 2000, friction: 0.02f, air: false, jump: IsOnFloor());

            Vector2 target = closest.GlobalPosition;
            Vector2 pos    = GlobalPosition;
            Vector2 prime  = pos + velocity * delta;

            if (prime.DistanceTo(target) >= hookDistance)
            {
                Vector2 v = velocity - velocity.Dot(pos - target) / pos.DistanceSquaredTo(target) * (pos - target);

                Vector2 prime2 = pos + v * delta;
                Vector2 newPos = target + (prime2 - target) * (pos.DistanceTo(target) / prime2.DistanceTo(target));
                velocity     = (newPos - pos) / delta;
                hookDistance = newPos.DistanceTo(target);
            }

            void ResetLine()
            {
                protonLine.Width   = 1;
                protonLine.Texture = null;
            }

            if (!Input.IsActionPressed("Grapple"))
            {
                SetState(State.Bounce);
                ResetLine();
            }
            break;

        case State.WallJump:
            Move();
            if (!Input.IsActionPressed("Jump"))
            {
                if (velocity.y < -JumpSmooth)
                {
                    velocity.y  = -JumpSmooth;
                    velocity.x -= 50 * Mathf.Sign(velocity.x);
                }
                SetState(State.Fall);
            }

            break;

        case State.WallSlide:
            Move(gravity: velocity.y > 0 ? 10 : Physics.Gravity);

            if (wallCurr == null || IsOnFloor() || !wallCurr.IsColliding())
            {
                SetState(State.Idle);
                break;
            }
            if (Input.IsActionJustPressed("Jump"))
            {
                SetState(State.WallJump);
            }

            sprite.FlipH = !wallCurr.Name.EndsWith('L');

            break;
        }

        velocity = MoveAndSlide(velocity, Vector2.Up);
        if (IsOnFloor())
        {
            sprite.RotationDegrees += velocity.x * delta;
            if (GetState() != State.Hook && GetState() != State.Zap)
            {
                prevProton = null;
            }
        }

        if (GlobalPosition.y > level.deathHeight)
        {
            Die();
        }

        if (Input.IsActionJustPressed("Quit") && !Pause.annoyingBug)
        {
            GetTree().Paused = true;
            Spawner.Node("res://UI/Pause.tscn", GetParent());
        }

        Pause.annoyingBug = false;
    }
Esempio n. 7
0
 public static Tuple <Neutron, Positron, ElectronNeutrino> BetaPlusDecayIndividual(Proton P)
 {
     return(new Tuple <Neutron, Positron, ElectronNeutrino>(new Neutron(0), new Positron(0), new ElectronNeutrino(0)));
 }