0 Replies - 784 Views - Last Post: 07 May 2013 - 09:35 PM

#1 zerophase  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 07-May 13

creating objects in specific maps only.

Posted 07 May 2013 - 09:35 PM

I've been attempting to get an object like a health pack (a bread crumb in this instance.) to only spawn in certain maps. to decide whether the map should have an object I have a check in the breadcrumb class. I pass a tuple with the third value representing each maps integer value to the breadcrumb class check for bread existence, in the draw step, that determines whether the map should have bread or not. I then add a list member to breadCollection for each crumb that represents the graphical component of the bread crumb from the class library. What I am trying to figure out is how to create breads in maps only on the first visit, and if the bread in that location hasn't been picked up by the player yet. The player is supposed to be able to put the bread back on the ground without moving any breads that might be in the same area. My guess is I need a list of x and y coordinates for this.
Check for bread existence:
 public bool breadExists(int existence)
       {
            if ((existence % 5) == 0)
            {
                  
               return this.Location = true;
            }
            return this.Location = false;
       }



code passed to breadExists and creation of object in view:
if (Crumb.breadExists(Map.TupleHolder.Item3) )
{
       if (!firstVisit.ElementAt(Map.TupleHolder.Item3) && dontBakeTooMuchBread && breadTimer <= 0)
       {

            breadCollection.Add(new InteractiveObject());
            dontBakeTooMuchBread = false;
       }

       for (int i = 0; i < breadCollection.Count; i++)
       {
             breadCollection.ElementAt(i).LoadContent(this.Content, "Ball");
             breadCollection.ElementAt(i).position = new Vector2(itemLocationX, itemLocationY);
       }
       foreach (InteractiveObject o in breadCollection)
       {
           o.Draw(this.spriteBatch);
       }
}


So far I've had trouble doing it without getting null reference exceptions from for statements coming back as 0, after all bread has been removed from the current map, and I try to place a bread back on the ground. It seems like a bread creating factory would be an ideal solution for this. So, is anyone able to help with implementing a factory or have suggestions for insuring areas only get breads once?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1