private void initObjects() { int id = 0; foreach (ObjectPlaceholder objectPlaceholder in levelData.objects) { GameObject obj = Instantiate(Resources.Load("Prefabs/Objects/EatableObject", typeof(GameObject))) as GameObject; obj.name = objectPlaceholder.getPathName(); EatableObject script = null; if (objectPlaceholder.getModel().Equals(GenericObject.Model.Soft)) { script = obj.AddComponent <SoftObject>(); } else if (objectPlaceholder.getModel().Equals(GenericObject.Model.Hard)) { script = obj.AddComponent <HardObject>(); } script.setProperties(objectPlaceholder.getIsOnSomething(), objectPlaceholder.getIsHanging(), objectPlaceholder.getIsHorizontallyFlipped(), objectPlaceholder.getStrengthCoefficient()); script.setId(id); script.setPosition(objectPlaceholder.getCoordinates(), objectPlaceholder.getZIndex()); script.setName(objectPlaceholder.getName(), objectPlaceholder.getPathName()); obj.transform.SetParent(this.transform); addObjectToRoom(script, objectPlaceholder.getRoomNumber()); objects.Add(script); id++; } }
public static bool IsIntersectsCircleVsCircle(EatableObject circle1, EatableObject circle2) { float deltaX = (circle2.GetCenter().X - circle1.GetCenter().X); float deltaY = (circle2.GetCenter().Y - circle1.GetCenter().Y); float distanceSquare = (deltaX * deltaX + deltaY * deltaY); return(distanceSquare < circle2.shape.Radius * circle2.shape.Radius); }
public override void OnStateEnter() { Context.Context.ScreenClearColor = Color.Black; rand = new Random(); MapGenerator.GenerateMap(30, 1); Random rnd = new Random(); for (int i = 0; i < 100 ; i++) { VisitorAgent go = new VisitorAgent(new Vector2(50, -80), 1); go.MaxHealth = 1; go.Name = "test"; go.MyTexture = TextureManager.TextureDictionary["testSprite"]; go.Size = new Vector2(20, 20); Game1.AddGameObject(go); agent = go; bool foundTile = false; while (!foundTile) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); go.CurrentTile = MapGenerator.Map[x, y]; foundTile = go.CurrentTile.Walkable; } go.Position = go.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; go.Home = go.CurrentTile; // action.SetTarget(MapGenerator.Map[10,10], go); // go.JobQueue.Add(action); if (i < 100) { go.Team = 1; } else { go.Team = 2; go.MyTexture = TextureManager.TextureDictionary["trump"]; } } DrinkObject drink = new DrinkObject(); drink.MyTexture = TextureManager.TextureDictionary["drinkstand"]; drink.CurrentTile = MapGenerator.Map[10, 10]; drink.Position = new Vector2(500, 500); Game1.AddGameObject(drink); drink = new DrinkObject(); drink.MyTexture = TextureManager.TextureDictionary["drinkstand"]; drink.CurrentTile = MapGenerator.Map[30, 30]; drink.Position = new Vector2(1500, 1500); Game1.AddGameObject(drink); EatableObject eat = new EatableObject(); eat.MyTexture = TextureManager.TextureDictionary["burgerstand"]; eat.CurrentTile = MapGenerator.Map[20, 20]; eat.Position = new Vector2(1000, 1000); Game1.AddGameObject(eat); eat = new EatableObject(); eat.MyTexture = TextureManager.TextureDictionary["burgerstand"]; eat.CurrentTile = MapGenerator.Map[15, 15]; eat.Position = new Vector2(750, 750); Game1.AddGameObject(eat); Tile t = MapGenerator.GetTileAtPosition(new Vector2(0, 0)); t = MapGenerator.GetTileAtPosition(new Vector2(120, 60)); t = MapGenerator.GetTileAtPosition(new Vector2(320, 418)); ToiletObject to = new ToiletObject(); to.MyTexture = TextureManager.TextureDictionary["toilet"]; to.CurrentTile = MapGenerator.Map[15, 25]; to.Position = new Vector2(750, 1250); Game1.AddGameObject(to); Bin bin = new Bin(); bin.CurrentTile = MapGenerator.Map[12, 12]; bin.Position = new Vector2(600, 600); Game1.AddGameObject(bin); JanitorAgent j = new JanitorAgent(new Vector2(50, -80), 1); j.MaxHealth = 1; j.Name = "test"; j.MyTexture = TextureManager.TextureDictionary["trump"]; j.Size = new Vector2(20, 20); Game1.AddGameObject(j); bool found = false; while (!found) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); j.CurrentTile = MapGenerator.Map[x, y]; found = j.CurrentTile.Walkable; } j.Position = j.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; j.Home = j.CurrentTile; JanitorAgent j2 = new JanitorAgent(new Vector2(50, -80), 1); j2.MaxHealth = 1; j2.Name = "test"; j2.MyTexture = TextureManager.TextureDictionary["trump"]; j2.Size = new Vector2(20, 20); Game1.AddGameObject(j2); bool found3 = false; while (!found3) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); j2.CurrentTile = MapGenerator.Map[x, y]; found3 = j2.CurrentTile.Walkable; } j2.Position = j2.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; j2.Home = j2.CurrentTile; }