Ejemplo n.º 1
0
        public void LoadMap(MapData map)
        {
            this.map = map;

            mySprites.Clear();
            myPlatforms.Clear();
            myWordSprites.Clear();

            Vector2 center = myScreenSize / 2;

            Texture2D shadow = Content.Load<Texture2D>("shadow");

            //Make a Platform
            Texture2D plat45 = Content.Load<Texture2D>("platform45squished");
            foreach (PlatformData data in map.Platforms)
            {
                if (myAnimatedHero.Items.Contains(data.Item))
                {
                    data.Item = null;
                }
                PlatformSprite platform = new PlatformSprite(plat45, data);
                mySprites.Add(platform);
                myPlatforms.Add(platform);
                platform.LoadItemTextures(Content, shadow);
            }

            SpriteFont font = Content.Load<SpriteFont>("DefaultFont");
            foreach (WordCloudData wordCloud in map.WordClouds)
            {
                foreach (WordData word in wordCloud.Words)
                {
                    myWordSprites.Add(new WordSprite(word, font));
                }
            }

            //It's important to keep Hero added after the other sprites!
            mySprites.Add(myAnimatedHero);

            myAnimatedHero.Reset();
            int startIndex = map.Platforms.IndexOf(map.startPlatform);
            if (startIndex >= 0)
            {
                PlatformSprite startPlatform = myPlatforms[startIndex];
                startPlatform.Update(0);
                myAnimatedHero.myPosition = myPlatforms[startIndex].myPosition;
                myAnimatedHero.currentPlatform = myPlatforms[startIndex];
            }

            Update(new GameTime());
            offset = center - myAnimatedHero.myPosition;
        }
Ejemplo n.º 2
0
 public void UpdateCurrentPlatform(float elapsedTime, List<PlatformSprite> platforms)
 {
     foreach (PlatformSprite platform in platforms)
     {
         platform.UpdateHeroOnPlatform(currentPlatform == platform && IsGrounded && !falling, elapsedTime);
     }
     if (!IsGrounded || falling) return;
     currentPlatform = null;
     foreach (PlatformSprite platform in platforms)
     {
         if (platform.Solid && platform.Contains(myPosition))
         {
             currentPlatform = platform;
             if (platform.Safe)
             {
                 respawnPlatform = currentPlatform;
             }
         }
         platform.RespawnPlatform = respawnPlatform == platform;
     }
 }
Ejemplo n.º 3
0
 public void UpdateCurrentPlatform(List<PlatformSprite> platforms)
 {
     if (!IsGrounded || falling) return;
     currentPlatform = null;
     foreach (PlatformSprite platform in platforms)
     {
         if (platform.Contains(myPosition))
         {
             currentPlatform = platform;
             lastPlatform = currentPlatform;
             break;
         }
     }
 }
Ejemplo n.º 4
0
        public override void Update(float elapsedTime)
        {
            base.Update(elapsedTime);
            myBook.Update((double)elapsedTime);
            if (currentPlatform == null)
            {
                falling = true;
            }

            if (falling)
            {
                myScale *= 0.9f;
                myVelocity = Vector2.Zero;

                if (myScale < 0.001f)
                {
                    myScale = 1;
                    myPositionZ = 0;
                    myVelocityZ = 0;
                    currentPlatform = respawnPlatform;
                    if (currentPlatform != null)
                        myPosition = currentPlatform.myPosition;
                    falling = false;
                }
                return;
            }

            myVelocityZ += -2000f * elapsedTime;
            myPositionZ += myVelocityZ * elapsedTime;
            myPositionZ = Math.Max(myPositionZ, 0);

            float maxVel = 400;
            float slideFactor = (float)Math.Pow(currentPlatform.data.Slide, 0.1);
            float factor = 1f;
            if (!moved)
            {
                factor = 0.9f;
                if (IsGrounded)
                {
                    if (!Keyboard.GetState().IsKeyDown(Keys.L))
                    {
                        factor = 0.3f + slideFactor * 0.7f;
                    }
                }
            }
            myVelocity *= factor;
            Vector2 edge;
            if (IsGrounded &&  currentPlatform != null && (edge = currentPlatform.NearEdge(myPosition)) != Vector2.Zero)
            {
                Vector2 nV = myVelocity; nV.Normalize();
                edge.Normalize();
                if ((nV + edge).Length() > Math.Sqrt(2))
                {
                    myVelocity /= Math.Max(20 * (1 - slideFactor), 1);
                }
            }

            if (myVelocity.Length() > maxVel)
            {
                myVelocity *= maxVel / myVelocity.Length();
            }
            if (currentPlatform != null)
            {
                if (IsGrounded)
                {
                    if (currentPlatform.LastFrameMovement.Length() < MAX_PLATFORM_JUMP)
                    {
                        myPosition += currentPlatform.LastFrameMovement;
                    }
                    //pushoffVelocity = currentPlatform.Velocity;
                }
                else
                {
                    myPosition += pushoffVelocity * elapsedTime;
                }
            }
            moved = false;

            float transTime = 0;
            if (currentPlatform != null)
            {
                if (currentPlatform.Item != null)
                {
                    if ((myPosition - currentPlatform.Item.myPosition).Length() < 35)
                    {
                        currentPlatform.Item.IsCollected = true;
                        Items.Add(currentPlatform.data.Item);
                    }
                }

                if (IsGrounded && currentPlatform.OnMapTransition(myPosition))
                {
                    transTime = transitionTime + elapsedTime;
                }
            }
            transitionTime = transTime;
        }
Ejemplo n.º 5
0
        public override void Update(float elapsedTime)
        {
            base.Update(elapsedTime);
            if (currentPlatform == null)
            {
                falling = true;
            }

            if (falling)
            {
                myScale *= 0.9f;
                myVelocity = Vector2.Zero;

                if (myScale < 0.001f)
                {
                    myScale = 1;
                    myPositionZ = 0;
                    myVelocityZ = 0;
                    currentPlatform = lastPlatform;
                    if (currentPlatform != null)
                        myPosition = currentPlatform.myPosition;
                    falling = false;
                }
                return;
            }

            myVelocityZ += -2000f * elapsedTime;
            myPositionZ += myVelocityZ * elapsedTime;
            myPositionZ = Math.Max(myPositionZ, 0);

            float maxVel = 400;
            if (!moved)
            {
                if (IsGrounded)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.L))
                    {

                        myVelocity *= 0.9f;
                    }
                    else
                    {

                        myVelocity *= 0.3f;
                    }
                }
                else
                {
                    myVelocity *= 0.9f;
                }
            }
            if (myVelocity.Length() > maxVel)
            {
                myVelocity *= maxVel / myVelocity.Length();
            }
            if (currentPlatform != null)
            {
                if (IsGrounded)
                {
                    pushoffVelocity = currentPlatform.Velocity;
                }
                myPosition += pushoffVelocity * elapsedTime;
                Debug.WriteLine(currentPlatform.Velocity);
            }
            moved = false;
        }