//this currently can only collide with adjacent tiles, should be more dynamic if we wanted bigger things //this is also using interactable as collidable, may or may not want to keep it this way public static List<Doodad> GetCollidableDoodads(GameObject go) { List<Doodad> collidableDoodads = new List<Doodad>(); int xTile = (int)go.Position.X / Data.TileSize; int yTile = (int)go.Position.Y / Data.TileSize; for (int x = (xTile-1); x < (xTile + 2); x++) { for (int y = (yTile-1); y < (yTile + 2); y++) { if (GetTile(x, y) != null) { foreach (Doodad doodad in GetTile(x, y).GetDoodads()) { if (doodad.IsInteractable) { collidableDoodads.Add(doodad); } } } } } return collidableDoodads; }
public void InsertGameObject(GameObject go) { if(gameObjects.ContainsKey(go.GetId())) { return; } gameObjects.Add(go.GetId(), go); }
public void RemoveObject(GameObject gameObject) { gameObjects.Remove(gameObject.GetId()); }
protected override void Interact(GameObject gameObject) { if (DateTime.Now.CompareTo(interactionOffCooldown) < 0) { return; } goalPosition = position; //bad, change it to be more dynamic! if (gameObject is Toon) { InteractWithObject((Toon)gameObject); } }
public bool AddToBag(GameObject gameObject) { return _bag.Add(gameObject); }
public void RemoveFromContainer(GameObject gObject) { _bag.GameObjects.Remove(gObject); }
public MoveToGameObjectMobState(GameObject gameObject, Mob mob) { this.gameObject = gameObject; this.mob = mob; }
public bool IsGameObjectInsideRange(GameObject gameObject, int range) { return (gameObject.Position - Position).Length() < range; }
protected virtual void Interact(GameObject gameObject) { }
public void ReceiveEvent(MoveToGameObjectEvent leEvent) { goalGameObject = Map.GetGameObject(leEvent.GoalGameObject); }
public void ReceiveEvent(MoveToPositionEvent leEvent) { goalPosition = leEvent.Position; goalGameObject = null; }
public static void RemoveGameObject(GameObject gameObject) { GetTile((int)gameObject.Position.X / Data.TileSize, (int)gameObject.Position.Y / Data.TileSize).RemoveObject(gameObject); allGameObjects.Remove(gameObject.GetId()); if (gameObject is Mob) { allMobs.Remove(gameObject.GetId()); } if (gameObject is Toon) { allToons.Remove(gameObject.GetId()); } }
//use the given GameObjects position to manage what tile to go into public static void InsertGameObject(GameObject go) { //BAD BAD IF STATEMENT, BE GONE, DAMN ARRAYS if (go.Position.X < 0 || go.Position.X > tiles.GetLength(0) * Data.TileSize || go.Position.Y < 0 || go.Position.Y > tiles.GetLength(1) * Data.TileSize) { go.Position = new Vector2(100, 100); //looks and feels horrible } tiles[(int)(go.Position.X / Data.TileSize), (int)(go.Position.Y / Data.TileSize)].InsertGameObject(go); if (!allGameObjects.ContainsKey(go.GetId())) { allGameObjects.Add(go.GetId(), go); } if (go is Mob) { if (!allMobs.ContainsKey(go.GetId())) { allMobs.Add(go.GetId(), (Mob)go); } } if (go is Toon) { if (!allToons.ContainsKey(go.GetId())) { allToons.Add(go.GetId(), (Toon)go); } } }
protected override void Interact(GameObject gameObject) { if (DateTime.Now.CompareTo(interactionOffCooldown) == -1) { return; } base.Interact(gameObject); goalGameObject = null; //<-- this is to stop you from interacting every frame, this may be removed once a cooldown has been introduced goalPosition = position; //bad ifs, change it to be more dynamic if (gameObject is Tree) { InteractWithObject((Tree)gameObject); } else if (gameObject is PalmTree) { InteractWithObject((PalmTree)gameObject); } else if (gameObject is Loot) { InteractWithObject((Loot)gameObject); } else if (gameObject is Mob) { InteractWithObject((Mob)gameObject); } }