Пример #1
0
 //Methods
 public bool Collision(GameObject o)
 {
     if (SpriteBounds.Intersects(o.SpriteBounds))
     {
         if (PixelsIntersect(SpriteBounds,
                             TextureToArray(sprite),
                             o.SpriteBounds,
                             TextureToArray(o.sprite)))
             return true;
     }
     return false;
 }
Пример #2
0
 //check if the GameObj is in the view area
 public bool Visible(GameObject gobj)
 {
     return boundingRect.Intersects(gobj.SpriteBounds);
 }
Пример #3
0
 //set the camera to a game object
 public void LockToObject(GameObject gameObject)
 {
     focusObject = gameObject;
     mode = CameraMode.Locked;
 }
Пример #4
0
        Texture2D spriteTexHit; //the texture used once the box has been smashed

        #endregion Fields

        #region Constructors

        //Constructor
        public ItemBox(Vector2 pos, Vector2 vel, Texture2D spritetex1, Texture2D spritetex2, ObjectType objType, GameObject I)
            : base(pos, vel, spritetex1, ObjectType.ItemBox)
        {
            item = I; //the item box is linked to an item
            spriteTexHit = spritetex2; //load the hit texture
        }
Пример #5
0
 internal Level LoadLevelFromFile(string filename)
 {
     var level = new Level();
     using (var sr = new StreamReader(filename))
     {
         while (!sr.EndOfStream)
         {
             string s = sr.ReadLine();
             if (s != null && (s.StartsWith("//") || s == ""))
                 continue;
             if (s != null)
             {
                 string[] split = s.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                 if (split[2] == "startzone")
                 {
                     Vector2 sp = new Vector2(float.Parse(split[0]), float.Parse(split[1]));
                     level.StartPosition = sp;
                 }
                 else if (split[2] == "finishzone")
                 {
                     Vector2 fp = new Vector2(float.Parse(split[0]), float.Parse(split[1]));
                     level.FinishZone = new Rectangle((int)fp.X, (int)fp.Y, 32, 32);
                 }
                 else if (split[2] == "enemy")
                 {
                     Texture2D sprite = enemyTexture;
                     Enemy enemy = new Enemy(new Vector2(float.Parse(split[0]), float.Parse(split[1])), Vector2.Zero,
                                             sprite);
                     level.GameObjects.Add(enemy);
                 }
                 else
                 {
                     var sprite = Content.Load<Texture2D>("objects/" + split[2]);
                     sprite.Name = split[2];
                     var gameObj = new GameObject(
                         new Vector2(float.Parse(split[0]), float.Parse(split[1])),
                         new Vector2(0, 0), sprite, GameObject.ObjectType.Block);
                     level.GameObjects.Add(gameObj);
                 }
             }
         }
     }
     return level;
     //first line = X
     //second line = Y
     //third line = spritename
 }
Пример #6
0
 //parse the .txt file and create a new Level object that contains all of the objects and positions
 //of the new level. returns the new Level object.
 internal Level LoadLevelFromFile(string filename)
 {
     var level = new Level();
     using (var sr = new StreamReader(filename))
     {
         while (!sr.EndOfStream)
         {
             string s = sr.ReadLine();
             if (s != null && (s.StartsWith("//") || s == ""))
                 continue;
             if (s != null)
             {
                 string[] split = s.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                 if (split[2] == "startzone")
                 {
                     Vector2 sp = new Vector2(float.Parse(split[0]), float.Parse(split[1]));
                     level.StartPosition = sp;
                 }
                 else if (split[2] == "finishzone")
                 {
                     Vector2 fp = new Vector2(float.Parse(split[0]), float.Parse(split[1]));
                     level.FinishZone = new Rectangle((int)fp.X, (int)fp.Y, 32, 32);
                 }
                 else if (split[2] == "enemy")
                 {
                     Texture2D sprite = enemyTexture;
                     Enemy enemy = new Enemy(new Vector2(float.Parse(split[0]), float.Parse(split[1])), Vector2.Zero,
                                             sprite);
                     level.GameObjects.Add(enemy);
                 }
                 else if (split[2] == "itembox")
                 {
                     Texture2D sprite1 = Content.Load<Texture2D>("objects/itembox");
                     Texture2D sprite2 = Content.Load<Texture2D>("objects/itembox_hit");
                     Item newItem = new Item(new Vector2(float.Parse(split[4]),
                                                                     float.Parse(split[5])),
                                                         ItemTextures[int.Parse(split[3])],
                                                         int.Parse(split[3]));
                     newItem.alive = false;
                     ItemBox itemBoxObj = new ItemBox(new Vector2(float.Parse(split[0]),
                                                                  float.Parse(split[1])),
                                                      Vector2.Zero,
                                                      sprite1,
                                                      sprite2,
                                                      GameObject.ObjectType.ItemBox,
                                                      newItem);
                     level.GameObjects.Add(itemBoxObj);
                     level.GameObjects.Add(newItem);
                 }
                 else
                 {
                     Texture2D sprite = Content.Load<Texture2D>("objects/" + split[2]);
                     GameObject gameObj = new GameObject(
                         new Vector2(float.Parse(split[0]), float.Parse(split[1])),
                         Vector2.Zero, sprite, GameObject.ObjectType.Block);
                     level.GameObjects.Add(gameObj);
                 }
             }
         }
     }
     return level;
 }