Example #1
0
        public void Draw(SpriteBatch spriteBatch, Player player)
        {
            Rectangle dst;
              Rectangle src = new Rectangle(
            SrcDots.X + 1, SrcDots.Y + 1, SrcDots.Width - 2, SrcDots.Height - 2);

              int size = SrcDots.Width;
              int w = Game1.SCREEN_WIDTH / size;
              int h = Game1.SCREEN_HEIGHT / size;
              int xOffset = (int)(player.Dst.Center.X / size);
              int yOffset = (int)(player.Dst.Center.Y / size);
              int padding = 1;

              int xMin = xOffset - w / 2 - padding - 2;
              int xMax = xOffset + w + padding;
              int yMin = yOffset - h / 2 - padding;
              int yMax = yOffset + h + padding;

              for (int x = xMin; x < xMax; x++)
              {
            for (int y = yMin; y < yMax; y++)
            {
              dst = new Rectangle(x * size, y * size, size, size);
              spriteBatch.Draw(Dots, dst, src, Color.White);
            }
              }

              foreach (Rectangle rect in Clouds.Keys)
              {
            Texture2D texture = Sprites.GetTexture(Clouds[rect]);
            Rectangle srcCloud = Sprites.GetSlice(Clouds[rect]);
            Rectangle dstCloud = rect;
            Color color = Color.White;
            float scale = 1;
            float x = player.Dst.Center.X - Controller.LevelWidth;

            switch (Clouds[rect])
            {
              case Element.Cloud0:
            scale = 0.1f;
            color *= 0.5f;
            break;
              case Element.Cloud1:
            scale = 0.05f;
            color *= 0.3f;
            dstCloud.Height /= 2;
            break;
              case Element.Cloud2:
            scale = 0.01f;
            color *= 0.1f;
            dstCloud.Height /= 3;
            break;
            }
            dstCloud.X = (int)Math.Round(rect.X - x * scale);

            spriteBatch.Draw(texture, dstCloud, srcCloud, color);
              }
        }
Example #2
0
        public Rectangle GetSourceRectangle(
      TimeSpan frameDuration, TimeSpan totalGameTime,
      Player.VerticalState vState,
      Player.HorizontalState hState)
        {
            Rectangle toReturn = new Rectangle();

              if (totalGameTime.TotalMilliseconds - LastTick > frameDuration.TotalMilliseconds)
              {
            CurrentFrame++;
            LastTick = totalGameTime.TotalMilliseconds;

            if (CurrentFrame >= NumberOfFrames)
            {
              if (Looping)
            CurrentFrame = 0;
              else
            CurrentFrame = NumberOfFrames - 1;
            }
              }
              toReturn.Width = FrameWidth;
              toReturn.Height = FrameHeight;
              toReturn.X = CurrentFrame * FrameWidth;

              if (vState.Equals(Player.VerticalState.OnGround))
              {
            switch (hState)
            {
              case Player.HorizontalState.Stopped:
            toReturn.Y = (int)State.Stopped * FrameHeight;
            break;
              case Player.HorizontalState.Walking:
            toReturn.Y = (int)State.Walking * FrameHeight;
            break;
              case Player.HorizontalState.Pushing:
            toReturn.Y = (int)State.Pushing * FrameHeight;
            break;
              case Player.HorizontalState.Carrying:
            toReturn.Y = (int)State.Carrying * FrameHeight;
            break;
            }
              }
              else
              {
            switch (vState)
            {
              case Player.VerticalState.Jumping:
            toReturn.Y = (int)State.Jumping * FrameHeight;
            break;
              case Player.VerticalState.Falling:
            toReturn.Y = (int)State.Falling * FrameHeight;
            break;
            }
              }

              return toReturn;
        }
Example #3
0
 public static void ExecuteAction(Player player, Tile tile, ReactionType action)
 {
     Element tileType = tile.ElementType;
       if (Controller.Reactions.ContainsKey(tileType))
       {
     if (Controller.Reactions[tileType].Types.Contains(action))
     {
       // Execute Action
       switch (action)
       {
     case ReactionType.Platform:
       break;
     case ReactionType.HorizontalPlatform:
       break;
     case ReactionType.VerticalPlatform:
       break;
     case ReactionType.ComplexPlatform:
       break;
     case ReactionType.Hurt:
       player.Hurt(-player.Direction);
       break;
     case ReactionType.HurtFromFront:
       player.Hurt(-player.Direction);
       break;
     case ReactionType.HurtFromBack:
       player.Hurt(-player.Direction);
       break;
     case ReactionType.HurtFromAbove:
       player.Hurt(-player.Direction);
       break;
     case ReactionType.HurtFromBelow:
       player.Hurt(-player.Direction);
       break;
     case ReactionType.Bounce:
       player.Jump(1.0f);
       break;
     case ReactionType.Jump:
       player.Jump(1.0f);
       break;
     case ReactionType.HighJump:
       player.Jump(2.0f);
       break;
     case ReactionType.Collect:
       break;
     case ReactionType.Push:
       break;
     case ReactionType.Destroy:
       break;
     default:
       break;
       }
     }
       }
 }
Example #4
0
        public Controller()
            : base()
        {
            #region Load reactions from XML
              Reactions = new Dictionary<Element, Reaction>();

              List<Reaction> reactions =
            DAO.LoadReactionsFromXML(Reaction.REACTIONS_FILENAME);

              for (int i = 0; i < reactions.Count; i++)
            if (!Reactions.ContainsKey(reactions[i].ElementType))
              Reactions.Add(reactions[i].ElementType, reactions[i]);
              #endregion

              LevelMap = DAO.LoadFile(CurrentLevel + ".xml");

              if (LevelMap == null)
            LevelMap = GenerateTestLevel();

              Camera = new Camera();
              Player1 = new Player(100, 100);
              DeadOjects = new List<DeadObject>();

              #region Play and Loop Music
              Audio.Play(Music.InGameMusic);
              SoundEffect.MasterVolume = Game1.GlobalVolume;
              MediaPlayer.Volume = Game1.GlobalVolume * Volume;
              MediaPlayer.IsRepeating = true; // Loop Music
              #endregion

              LevelWidth = GetLevelWidth();
              LevelHeight = GetLevelHeight();

              InGameMenu = new InGameMenu();

              VisibleTiles = new List<Tile>();
        }
Example #5
0
 public void Release(int direction)
 {
     TileState = State.Falling;
       Holder = null;
       Velocity.X = WorldSettings.THROW_SPEED * direction;
 }
Example #6
0
 public void Carry(Player player)
 {
     TileState = State.Carried;
       Holder = player;
 }
Example #7
0
 public void ResetPlayer(object nothing)
 {
     Player1 = new Player(100, 100);
 }