Exemplo n.º 1
0
        public override void Update()
        {
            angle += angleSpeed * 0.001f;

            raycast.dir  = MapTools.AngleToVector(angle - MathHelper.Pi * 0.5f);
            raycast.pos  = pos + raycast.dir * 10;
            hitOfRaycast = raycast.getHit();
            if (hitOfRaycast.obj is Player)
            {
                Game1.getPlayer().die();
            }
            //           Game1.world.particles.Add(new Particle(hitOfRaycast.pos.X - raycast.dir.X * 5, hitOfRaycast.pos.Y - raycast.dir.Y * 5, 5, 5, new Vector2(((float)new Random().NextDouble() - 0.5f) * 20.0f, ((float)new Random().NextDouble() - 0.5f) * 20.0f)));
            particleEmitter.pos.X     = hitOfRaycast.pos.X;
            particleEmitter.pos.Y     = hitOfRaycast.pos.Y;
            particleEmitter.Direction = angle - Math.PI * (0.5f - Math.Sign(angleSpeed) * 0.2f) + Math.PI;
            particleEmitter.update();
            base.Update();
        }
Exemplo n.º 2
0
        public void applySpeed()
        {
            Vector2 speedVec = new Vector2((float)((speed) * Math.Round(MapTools.getXMultiplier())), (float)((speed) * Math.Round(MapTools.getYMultiplier())));

            if ((speed > 0 && !collidesRight(false)))
            {
                raycast = new Raycast(rightPoints()[0], MapTools.getMultiplierVec() + new Vector2(0.0000001f, 0.0000001f), 1000, true);
                CollisionInfo hit = raycast.getHit();

                if ((hit.pos - rightPoints()[0]).Length() < speedVec.Length())
                {
                    speedVec = hit.pos + MapTools.getMultiplierVec() * 0.1f - rightPoints()[0];
                }

                pos += speedVec;
            }
            else if ((speed < 0 && !collidesLeft(false)))
            {
                raycast = new Raycast(leftPoints()[0], -MapTools.getMultiplierVec() + new Vector2(0.0000001f, 0.0000001f), 1000, true);
                CollisionInfo hit = raycast.getHit();

                if ((hit.pos - leftPoints()[0]).Length() < speedVec.Length())
                {
                    speedVec = hit.pos - MapTools.getMultiplierVec() * 0.1f - leftPoints()[0];
                }
                pos += speedVec;
            }
            else
            {
                speed = 0;
            }

            if ((collisionInfoDownBeginOfFrame.getRealSpeed() > 0 && !collidesRight(false)) || (collisionInfoDownBeginOfFrame.getRealSpeed() < 0 && !collidesLeft(false)))
            {
                pos.X += (float)((collisionInfoDownBeginOfFrame.getRealSpeed()) * Math.Round(MapTools.getXMultiplier()));
                pos.Y += (float)((collisionInfoDownBeginOfFrame.getRealSpeed()) * Math.Round(MapTools.getYMultiplier()));
            }

            rect.X = (int)pos.X;
            rect.Y = (int)pos.Y;
        }
Exemplo n.º 3
0
        public void applyFallSpeed(float delta)
        {
            if (!isGrounded().collided)
            {
                if (fallSpeed < maxFallSpeed)
                {
                    if (framesSpacePressed >= 30)
                    {
                        fallSpeed += fallAcceleration * 1f;
                    }
                    else
                    {
                        fallSpeed += fallAcceleration * 0.3f;
                    }
                }
                framesInAir++;
            }
            else if (!Keyboard.GetState().IsKeyDown(Keys.Space) && fallSpeed > 0)
            {
                fallSpeed = 0;
            }
            if (collidesUp().collided)
            {
                fallSpeed = 1;
            }

            if (isGrounded().collided&& fallSpeed > 0)
            {
                fallSpeed = 0;
            }

            if ((fallSpeed) > 0)
            {
                Vector2 fallVec = new Vector2((float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.X))), (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.Y))));

                raycast = new Raycast(downPoint(), WorldInfo.gravity + new Vector2(0.0000001f, 0.0000001f), 1000, true);
                CollisionInfo hit = raycast.getHit();

                if ((hit.pos - downPoint()).Length() < fallVec.Length())
                {
                    fallVec = (hit.pos - downPoint());
                }

                pos += fallVec;
            }
            else if ((fallSpeed) < 0)
            {
                pos.X += (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.X)));
                pos.Y += (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.Y)));
            }

            pos += new Vector2((float)((collisionInfoDownBeginOfFrame.getFallSpeed()) * (float)(Math.Round(WorldInfo.gravity.X))), (float)((collisionInfoDownBeginOfFrame.getFallSpeed()) * (float)(Math.Round(WorldInfo.gravity.Y))));



            /*
             * if(fallSpeed > 0) {
             *  for(int i = 0; i < fallSpeed; i++) {
             *      if (isGrounded().collided)
             *      {
             *          fallSpeed = isGrounded().getFallSpeed() + 1;
             *          //pos += isGrounded().speed;
             *          if (!state.IsKeyDown(Keys.Space))
             *              framesSpacePressed = 0;
             *          framesInAir = 0;
             *          //break;
             *      } else {
             *          pos.X += (float)(WorldInfo.gravity.X);
             *          pos.Y += (float)(WorldInfo.gravity.Y);
             *      }
             *  }
             * }
             * else if (fallSpeed < 0)
             * {
             *  for (int i = 0; i > fallSpeed; i--)
             *  {
             *
             *      if (collidesUp())
             *      {
             *          framesSpacePressed = 30;
             *          fallSpeed = 3;
             *          //break;
             *      }
             *      else
             *      {
             *          pos.X -= (float)(WorldInfo.gravity.X);
             *          pos.Y -= (float)(WorldInfo.gravity.Y);
             *      }
             *  }
             * }
             */
        }