Esempio n. 1
0
    public override void Update(double dt)
    {
        tex.Update(dt);
        player.Velocity -= Vec2.Clamp(new Vec2(0, player.Velocity.Y + player.Gravity), player.GAcc * dt);
        bool touch = false;

        if (GetTime() > DeathTime)
        {
            player.Respawn();
        }
        foreach (var a in player.collisions.Values)
        {
            foreach (var b in a)
            {
                if (b.GetType() == typeof(Spikes))
                {
                    return;
                }
                else
                {
                    touch = true;
                }
            }
        }
        if (touch)
        {
            player.Velocity = Vec2.Zero;
        }
    }
        public static void ThingMoveTo(Thing thing, Vec2 position, float speed = 3, float lerpAmount = -1)
        {
            if (thing == null)
            {
                return;
            }
            if (thing.y < position.y && thing is MaterialThing materialThing)
            {
                IEnumerable <IPlatform> plats = Level.CheckLineAll <IPlatform>(thing.bottomLeft + new Vec2(1f, 1f), thing.bottomRight + new Vec2(-1f, 1f));
                if (plats.FirstOrDefault((IPlatform p) => p is Block) == null)
                {
                    foreach (IPlatform plat in plats)
                    {
                        if (plat is Block)
                        {
                            break;
                        }
                        if (plat is MaterialThing t)
                        {
                            materialThing.clip.Add(t);
                            IPlatform left = Level.CheckPoint <IPlatform>(t.topLeft + new Vec2(-2f, 2f));
                            if (left is not null and MaterialThing and not Block)
                            {
                                materialThing.clip.Add(left as MaterialThing);
                            }
                            IPlatform right = Level.CheckPoint <IPlatform>(t.topRight + new Vec2(2f, 2f));
                            if (right is not null and MaterialThing and not Block)
                            {
                                materialThing.clip.Add(right as MaterialThing);
                            }
                            thing.vSpeed          += 1;
                            thing.y               += 2;
                            materialThing.grounded = false;
                        }
                    }
                }
            }
            Vec2 anglevec = Vec2.Clamp(new Vec2(position.x - thing.x, thing.y - position.y), new Vec2(-speed), new Vec2(speed));
            Vec2 tmp      = Maths.AngleToVec((float)Math.Atan(anglevec.y / anglevec.x)) * speed;

            if (lerpAmount == -1)
            {
                thing.hSpeed = anglevec.x < 0 ? -tmp.x : tmp.x;
                thing.vSpeed = anglevec.x < 0 ? -tmp.y : tmp.y;
            }
            else
            {
                var newHSpeed = anglevec.x < 0 ? -tmp.x : tmp.x;
                var newVSpeed = anglevec.x < 0 ? -tmp.y : tmp.y;
                thing.hSpeed = MathHelper.Lerp(thing.hSpeed, newHSpeed, lerpAmount);
                thing.vSpeed = MathHelper.Lerp(thing.vSpeed, newVSpeed, lerpAmount);
            }

            if (Level.CheckRect <Window>(thing.topLeft, thing.bottomRight) is Window window)
            {
                window.Destroy();
            }
        }
Esempio n. 3
0
        public void Vec2_ClampMax()
        {
            Vec2 v1 = new Vec2(1, 5);

            Vec2 result = v1.Clamp(0, 4);

            Assert.AreEqual(1, result.x);
            Assert.AreEqual(4, result.y);
        }
Esempio n. 4
0
        public void Vec2_ClampMin()
        {
            Vec2 v1 = new Vec2(1, 5);

            Vec2 result = v1.Clamp(2, 6);

            Assert.AreEqual(2, result.x);
            Assert.AreEqual(5, result.y);
        }
Esempio n. 5
0
    public virtual void Update(double dt)
    {
        player.Velocity -= Vec2.Clamp(new Vec2(player.Velocity.X - player.Controller.NeedVel().X *player.Speed *player.SpeedUp, 0), player.Acc * player.SpeedUp * dt);
        AnimatedTexture tex = GetTexture();

        if (tex != null)
        {
            tex.Update(dt);
        }
    }
Esempio n. 6
0
    private void UpdatePosition()
    {
        Vec2.Clamp(ref _velocity, -_maxVelocity, _maxVelocity);

        ApplyFriction();

        //Debug.Log(_velocity.x);

        position += _velocity;

        _instance.transform.position = new Vector3(position.x, position.y, 0);
    }
Esempio n. 7
0
 public override void Update(double dt)
 {
     if (player.collisions[Side.Left].Count != 0)
     {
         side = Side.Left;
     }
     else
     {
         side = Side.Right;
     }
     player.Dir       = side == Side.Left ? -1 : 1;
     player.Velocity -= Vec2.Clamp(player.Velocity - new Vec2(0, -1) * player.SlideSpeed, player.SlideAcc * dt);
     base.Update(dt);
 }
        public void ServerOrSingle_MoveUpdatePosition(Vec2 newPosition)
        {
            if (!serverOrSingle_Moving)
            {
                return;
            }

            //clamp position
            Vec2 clampedPosition = newPosition;
            Rect gameArea        = JigsawPuzzleManager.Instance.GetGameArea();

            gameArea.Expand(-.5f);
            clampedPosition.Clamp(gameArea.Minimum, gameArea.Maximum);

            //"Position" will be send to clients from JigsawPuzzlePiece.OnSetTransform() method
            Position = new Vec3(clampedPosition.X, clampedPosition.Y, .1f);
        }
Esempio n. 9
0
        public override void Update(double dt)
        {
            Weapon1.Owner = this;
            Weapon2.Owner = this;
            base.Update(dt);
            t += SwingSpeed * dt;
            double vx = 0, vy = 0;

            if (Key.A.Pressed())
            {
                vx -= 1;
            }
            if (Key.D.Pressed())
            {
                vx += 1;
            }
            if (Key.W.Pressed())
            {
                vy += 1;
            }
            if (Key.S.Pressed())
            {
                vy -= 1;
            }
            if (MouseButton.Left.Pressed())
            {
                Weapon1.Shoot(World.Current.cam.FromWH(Mouse.Position, App.Width, App.Height));
            }
            if (MouseButton.Right.Pressed())
            {
                Weapon2.Shoot(World.Current.cam.FromWH(Mouse.Position, App.Width, App.Height));
            }
            var targetVel = new Vec2(vx, vy).Unit *Speed;

            Velocity += Vec2.Clamp(targetVel - Velocity, Accel * dt);
            Weapon2.Update(dt);
            Weapon1.Update(dt);
        }
Esempio n. 10
0
 public override void Update(double dt)
 {
     Vel      -= Vec2.Clamp(Vel - NeedVel * Speed, Acc * dt * 60);
     Position += Vel * dt;
 }
Esempio n. 11
0
 public void Update(double dt)
 {
     Time     += dt;
     Vel      -= Vec2.Clamp(Vel - NeedVel * Speed, Acc * dt);
     Position += Vel * dt;
 }
Esempio n. 12
0
 public override void Update(double dt)
 {
     base.Update(dt);
     player.Velocity -= Vec2.Clamp(new Vec2(player.Velocity.X - player.Controller.NeedVel().X * player.Speed * player.SpeedUp, 0), player.Acc * player.SpeedUp * dt);
     player.Velocity -= Vec2.Clamp(new Vec2(0, player.Velocity.Y + player.Gravity), player.GAcc * dt);
 }
Esempio n. 13
0
        void UpdateClouds(double dt)
        {
            foreach (var a in objects)
            {
                if (a is Cloud)
                {
                    double REPL  = a.Size;
                    double REP   = 20;
                    double GRAV  = 2;
                    double GRAVL = 2 * a.Size;
                    double MINL  = a.Size * 0.1;
                    double d2    = Math.Max(GRAVL, REPL * 2);
                    foreach (var b in posGroup.Query(a.Position - new Vec2(d2, d2), a.Position + new Vec2(d2, d2)))
                    {
                        if (!(b is Cloud))
                        {
                            continue;
                        }
                        if (a == b)
                        {
                            continue;
                        }
                        Vec2   dv = b.Position - a.Position;
                        double d  = dv.Length;
                        if (d < MINL)
                        {
                            continue;
                        }
                        if (d < REPL * 2)
                        {
                            Vec2 f = (d - REPL) * REP * dv * Math.Pow(d, -3) * dt;
                            a.Velocity += f;
                            b.Velocity -= f;
                        }
                        else if (d < GRAVL)
                        {
                            Vec2 f = GRAV * dv * Math.Pow(d, -3) * dt;
                            a.Velocity += f;
                            b.Velocity -= f;
                        }
                    }

                    foreach (var b in posGroup.Query(a.Position - new Vec2(d2, d2), a.Position + new Vec2(d2, d2)))
                    {
                        if (!(b is Asteroid))
                        {
                            continue;
                        }
                        Vec2         dv   = b.Position - a.Position;
                        double       d    = dv.SqrLength;
                        const double AST  = 2;
                        const double ASTK = 100;
                        if (d < AST * AST)
                        {
                            a.Velocity -= ASTK * dv / d;
                        }
                    }

                    {
                        Vec2         dv    = player.Position - a.Position;
                        double       d     = dv.SqrLength;
                        const double PLAST = 2;
                        const double PLK   = 1000;
                        if (d < PLAST * PLAST)
                        {
                            a.Velocity -= PLK * dv / d;
                        }
                    }
                }
            }

            const double CLOUDSPEED = 2;

            foreach (var cloud in objects.Where(o => o is Cloud))
            {
                const double frict = 1;
                cloud.Velocity -= cloud.Velocity * frict * dt;
                cloud.Velocity  = Vec2.Clamp(cloud.Velocity, CLOUDSPEED);
            }
        }