Exemple #1
0
        public override void onUpdate()
        {
            Vector gravity  = new Vector(0, 1);
            Vector acc      = Vector.Zero;
            Vector friction = new Vector(.08f, 0);


            if ((plr.Position - Gob.Position).Length < 1400)
            {
                bool isPlayerOnRight = (plr.X - Gob.X) > 0;
                if (isPlayerOnRight)
                {
                    acc += Vector.UnitX * (.4f + (surface.Y < .2 ? .5f : 0));
                }
                else
                {
                    acc -= Vector.UnitX * (.4f + (surface.Y < .2 ? .5f : 0));
                }

                if (surface.Y > .8f)
                {
                    jumping = true;
                    acc    -= gravity * Math.Min(23, Math.Max(Gob.Y - plr.Y, 0));
                }
            }

            acc += gravity;

            Gob.Velocity += acc;


            Gob.Velocity -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y);


            Gob.Position += Gob.Velocity;

            Collisions <Wall> wallColls = Gob.currentCollisions <Wall>();

            surface = Vector.Zero;
            foreach (Collision <Wall> c in wallColls)
            {
                Gob.Position -= c.MTV;

                Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity);

                if (c.Normal.Y > .8f)
                {
                    surface = c.Normal;

                    jumping = false;
                }
            }

            if (Gob.Bounds.getCollisionInfo(plr.Bounds) != null)
            {
                Gob.close();
            }
        }
Exemple #2
0
        public override void onUpdate()
        {
            Collisions <Wall> walls = Gob.currentCollisions <Wall>();

            if (walls.Count > 0)
            {
                int index = 0;
                if (walls[index].Gob == lastWall)
                {
                    index = walls.Count - 1;
                }

                Gob.Velocity = walls[index].Normal.Perpendicular * Gob.Speed;
                lastWall     = walls[index].Gob;
                onWall       = true;
            }
            else if (onWall)
            {
                Gob.Position -= Gob.Velocity;
                Gob.Velocity  = Gob.Velocity.Perpendicular;
                Gob.Position += Gob.Velocity.Unit;
                onWall        = false;
            }
            else
            {
                Gob.Velocity = Vector.UnitY;
            }

//		    //check for line of sight to target
//		    GameObject target = Objects.getObject(Gob.Target);
//		    if (target != null && onWall){
//		        Vector toTarget = target.Position - Gob.Position;
//		        float length = toTarget.Length;
//		        if (toTarget.Length < 800){
//
//
//			        toTarget = toTarget.Unit;
//
//			        RayCollisions<Wall> rayColls = Gob.currentRayCollisions<Wall>(toTarget);
//			        if (rayColls.Count > 0 && rayColls[0].Length > length){
//			            Log.debug("See you. " + rayColls[0].Length + "/" + length);
//			            onWall = false;
//			            Gob.Position += Gob.Velocity.Perpendicular;
//			            Gob.Velocity = Gob.Velocity.Perpendicular;
//			            Gob.Position += Gob.Velocity;
//
//			        }
//
//		        }
//		    }

            Gob.Position += Gob.Velocity;
        }
Exemple #3
0
        public override void onUpdate()
        {
            Gob.Acceleration = Vector.UnitY;



            Vector vX = Gob.A;

            if (!goingToA)
            {
                vX = Gob.B;
            }

            float d = (vX.X - Gob.X);

            if (Math.Abs(d) < 10)
            {
                goingToA = !goingToA;
            }

            float x = Math.Sign(d);



            Gob.Acceleration += Vector.UnitX * x * 2;
            Gob.Velocity     += Gob.Acceleration;
            Gob.Velocity     -= Gob.Velocity * .1f;

            Gob.Position += Gob.Velocity;

            vis.Position     = Gob.Position + new Vector(0, -75);
            vis.Sprite.Scale = new Vector(x, 1) * 1.5f;
            //if (Gob.Velocity.X != 0){
            a.advanceFrame();

            //}

            var wallColls = Gob.currentCollisions <Wall>();

            foreach (var wallColl in wallColls)
            {
                Gob.Position -= wallColl.MTV;
            }
        }
Exemple #4
0
        public override void onUpdate()
        {
            Collisions <Player> colls = Gob.currentCollisions <Player>();

            foreach (Collision <Player> coll in colls)
            {
                if (coll.Gob is Player)
                {
                    Player plr = (Player)coll.Gob;


                    Gob.Acceleration += new Vector(.01f * plr.Velocity.X, .1f * plr.Velocity.Y);
                }
            }

            if (Gob.Wave == true)
            {
                //Gob.Velocity += new Vector(0, waveAmplitude * (float)Math.Sin(waveFrequency * waveActuator));
                waveActuator += .01f;
            }


            bool hasNeighbors = (Gob.RightNode != null && Gob.LeftNode != null);


            Gob.Velocity += new Vector(hasNeighbors ? Gob.Acceleration.X : 0, Gob.Acceleration.Y);

            if (Gob.Velocity.Length > 30)
            {
                Gob.Velocity = 30 * Gob.Velocity.Unit;
            }

            Gob.Position    += Gob.Velocity;
            Gob.Acceleration = Vector.Zero;

            //}
        }
Exemple #5
0
        public override void onUpdate()
        {
            //Config conf = Objects.getObject<Config>("Config");


            Gob.Acceleration = Vector.Zero;
            Vector friction = new Vector(.08f, 0);

            if (Input.isKeyDown(Keys.A))
            {
                Gob.Acceleration -= Vector.UnitX;
            }
            if (Input.isKeyDown(Keys.D))
            {
                Gob.Acceleration += Vector.UnitX;
            }

            if (Input.isNewKeyDown(Keys.W))
            {
                if (surface.Y > .8f)
                {
                    jumping           = true;
                    jumpCounter       = 40;
                    Gob.Acceleration -= gravity * 12;
                    doubleJumped      = false;

                    SpriteEffect fx = new SpriteEffect(Level);
                    fx.Position      = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4;
                    fx.Effect        = "smokeJump";
                    fx.Frames        = Vector.One * 4;
                    fx.Sprite.Scale *= .3f;
                    fx.Speed         = 4;
                }
                else if (jumping && !doubleJumped)
                {
                    jumpCounter       = 40;
                    doubleJumped      = true;
                    Gob.Acceleration -= gravity * 12;
                    SpriteEffect fx = new SpriteEffect(Level);
                    fx.Position      = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4;
                    fx.Effect        = "smokeJump";
                    fx.Frames        = Vector.One * 4;
                    fx.Sprite.Scale *= .3f;
                    fx.Speed         = 4;
                }
            }


            if (Input.isKeyDown(Keys.W))
            {
                if (jumping && jumpCounter > 0)
                {
                    Gob.Acceleration -= gravity * .02f * jumpCounter;
                    jumpCounter--;
                }
            }

            Gob.Acceleration += gravity;

            Gob.Velocity += Gob.Acceleration;
            if (Gob.Velocity.Length > 55)
            {
                Gob.Velocity = 55 * Gob.Velocity.Unit;
            }

            Gob.Velocity    -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y);
            Gob.Sprite.Scale = new Vector(50 + Math.Abs(Gob.Velocity.X * 15), 256);

            Gob.Position += Gob.Velocity;

            Collisions <Wall> wallColls = Gob.currentCollisions <Wall>();

            surface = Vector.Zero;
            foreach (Collision <Wall> c in wallColls)
            {
                Gob.Position -= c.MTV;

                Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity);

                if (c.Normal.Y > .8f)
                {
                    surface = c.Normal;

                    jumping = false;
                }
            }
        }
Exemple #6
0
        public override void onUpdate()
        {
            //Config conf = Objects.getObject<Config>("Config");


            if (Input.isNewKeyDown(Keys.Escape))
            {
                GameManager.SetLevel("MainMenu.state");
            }

            Gob.Acceleration = Vector.Zero;
            Vector friction = new Vector(.08f, 0);

            if (Input.isKeyDown(Keys.A))
            {
                Gob.Acceleration -= Vector.UnitX;
            }
            if (Input.isKeyDown(Keys.D))
            {
                Gob.Acceleration += Vector.UnitX;
            }

            if (Input.isKeyDown(Keys.O))
            {
                surface = Vector.UnitY;
                jumping = false;
            }

            if (Input.isNewKeyDown(Keys.W))
            {
                if (surface.Y > .8f)
                {
                    jumping     = true;
                    jumpCounter = 40;
                    int jumpPower = 12;
                    if (Gob.InWater)
                    {
                        jumpPower = 12;
                    }
                    Gob.Velocity     = new Vector(Gob.Velocity.X, 0);
                    Gob.Acceleration = -gravity * jumpPower;
                    doubleJumped     = false;

                    SpriteEffect fx = new SpriteEffect(Level);
                    fx.Position      = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 4;
                    fx.Effect        = "smokeJump";
                    fx.Frames        = Vector.One * 4;
                    fx.Sprite.Scale *= .3f;
                    fx.Speed         = 4;
                }
                else if (((jumping && !doubleJumped) || (surface.Y < .8f && !jumping)) && !Gob.InWater)
                {
                    jumpCounter  = 40;
                    doubleJumped = true;
                    jumping      = true;
                    int jumpPower = 12;
                    Gob.Acceleration = -gravity * jumpPower;
                    Gob.Velocity     = new Vector(Gob.Velocity.X, 0);
                    SpriteEffect fx = new SpriteEffect(Level);
                    Vector       xD = Vector.UnitX * Gob.Sprite.FrameWidth;
                    if (Gob.Velocity.X < 0)
                    {
                        xD *= -1;
                    }
                    fx.Position        = Gob.Position - (Vector.UnitY * Gob.Bounds.Size.Y / 2) - xD;
                    fx.Sprite.Rotation = 1.57f;
                    fx.Effect          = "jump";
                    fx.Frames          = new Vector(4, 2);
                    fx.Sprite.Scale   *= .3f;
                    fx.Sprite.Depth    = Gob.Sprite.Depth + .01f;
                    fx.Speed           = 4;
                }
            }


            if (Input.isKeyDown(Keys.W))
            {
                if (jumping && jumpCounter > 0)
                {
                    Gob.Acceleration -= gravity * .02f * jumpCounter;
                    jumpCounter--;
                }
            }
            surface = Vector.Zero;

            Gob.InWater = false;
            var waterBlocks = Gob.currentCollisions <WaterBlock>();

            if (waterBlocks.Count > 0)
            {
                Gob.InWater = true;

                if (Gob.Y > waterBlocks[0].Gob.Bounds.Top)
                {
                    Gob.Acceleration -= gravity * 1.2f;
                    if (Gob.Velocity.Y > 0)
                    {
                        Gob.Velocity *= .8f;
                    }
                }


                //if (Gob.Velocity.Y < 0 ||  Math.Abs(Gob.Y - waterBlocks[0].Gob.Bounds.Top) < 50){
                //	Log.debug("can jump from water");
                surface = Vector.UnitY;
                //jumping = false;
                //}

//				if (waterBlocks[0].Gob.Bounds.Top > Gob.Bounds.Top){
//					surface = Vector.UnitY;
//				}
            }



            Gob.Acceleration += gravity;

            Gob.Velocity += Gob.Acceleration;
            if (Gob.Velocity.Length > 55)
            {
                Gob.Velocity = 55 * Gob.Velocity.Unit;
            }

            Gob.Velocity    -= new Vector(Gob.Velocity.X * friction.X, Gob.Velocity.Y * friction.Y);
            Gob.Sprite.Scale = new Vector(70 + Math.Abs(Gob.Velocity.X * 15), 256);

            Gob.Position += Gob.Velocity;

            Collisions <Wall> wallColls = Gob.currentCollisions <Wall>();


            foreach (Collision <Wall> c in wallColls)
            {
                Gob.Position -= c.MTV;

                Gob.Velocity = c.Normal.Perpendicular * c.Normal.Perpendicular.dot(Gob.Velocity);

                if (c.Gob.Speed != 0)
                {
                    Gob.Position += c.Gob.Velocity;
                }

                if (c.Normal.Y > .8f)
                {
                    surface = c.Normal;

                    jumping = false;
                }
            }


            if (waterBlocks.Count > 0)
            {
                //if (Gob.Y < waterBlocks[0].Gob.Bounds.Top + 10){
                //surface = Vector.UnitY;
                //}
            }


            Collisions <WaterNode> wColls = Gob.currentCollisions <WaterNode>();

            if (wColls.Count != 0 && waterNodes == 0)
            {
                Vector feet = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y;
                //feet.Y += wColls[0].Gob.Velocity.Y;
                float vel = -2f * (Gob.Velocity - wColls[0].Gob.Velocity).Length;
                vel = Math.Max(-25, vel);
                WaterParticle.makeSplash(feet, 20, new Vector(0, vel), 1, 1.2f, false);
            }
            else if (wColls.Count == 0 && waterNodes != 0)
            {
                Vector feet = Gob.Position + Vector.UnitY * Gob.Bounds.Size.Y / 2;
                float  vel  = -1.2f * (Gob.Velocity).Length;
                vel = Math.Max(-10, vel);
                WaterParticle.makeSplash(feet, 8, new Vector(0, vel), 1, 2, false);
            }
            foreach (Collision <WaterNode> coll in wColls)
            {
                coll.Gob.Acceleration += new Vector(0f * Gob.Velocity.X, .05f * Gob.Velocity.Y);
            }
            waterNodes = wColls.Count;
        }