public Map() { try { string file = File.ReadAllText("routes.txt"); string[] routes = file.Split('\n'); _distance = new Entity[routes.Length, routes.Length]; foreach (var route in routes) { try { string[] elements = route.Split(','); int from = Convert.ToInt32(elements[0]); int to = Convert.ToInt32(elements[1]); int plane = Convert.ToInt32(elements[2]); int car = Convert.ToInt32(elements[3]); _distance[from, to].CarDistance = car; _distance[from, to].FlyDistance = plane; _distance[to, from].CarDistance = car; _distance[to, from].FlyDistance = plane; } catch { } } } catch { throw; } }
void ProcessVision(Entity[,] grid, double curTime) { for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { int dist = Math.Abs((int)position.X - i) + Math.Abs((int)position.Y - j); if (dist > attributes["eyesightRange"]) { continue; // don't account for things you cannot see } Entity e = grid[i, j]; if (e != null) { if (e is Ant) { ants.Add((Ant)e); } else if (e is Food) { foods.Add((Food)e); } } lastSeen[i, j] = (int)curTime; } } }
private bool CheckOnePosState(Entity[,] entities, byte[,] stateCaches, int row, int column, int checkTileId, byte checkState) { var curState = stateCaches[row, column]; if ((curState & checkState) == 0) { var entity = entities[row, column]; if (entity == Entity.Null) { return(false); } var tileComponent = World.GetComponent <TileComponent>(entity); if (tileComponent.tileId == checkTileId) { return(true); } else { return(false); } } else { return(false); } }
public Map(int width, int height) { this.width = width; this.height = height; terrains = new Terrain[width, height]; objects = new Entity[width, height]; }
public void GenerateNeighbors() { if (!CanUpdate) { return; } _tiles = new Entity[_dimensions * 2 + 1, _dimensions * 2 + 1]; for (var i = -_dimensions; i <= _dimensions; i++) { for (var j = -_dimensions; j <= _dimensions; j++) { if (!Model.IsLoaded) { Model.Request(); while (!Model.IsLoaded) { Script.Yield(); } } var pos = Position + new Vector3(i, j, 0) * _tileSize; var obj = World.CreateProp(Model, pos, Vector3.Zero, false, false) ?? new Prop(0); obj.FreezePosition = true; obj.Quaternion = Quaternion; obj.PositionNoOffset = pos; _tiles[i + _dimensions, j + _dimensions] = obj; } } LastTile = this; }
public void LoadString(string str) { string[] arr = str.Split(new char[] { ',' }); width = int.Parse(arr[0]); height = int.Parse(arr[1]); size_w = int.Parse(arr[2]); size_h = int.Parse(arr[3]); entitys = new Entity[size_w, size_h]; string data = arr[4]; arr = data.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr[i].Length; j++) { entitys[i, j] = new Entity(); entitys[i, j].x = i; entitys[i, j].y = j; entitys[i, j].rect = new Rectangle(i * width, j * height, width, height); if (arr[i].Substring(j, 1) == "0") { entitys[i, j].is_alive = false; } else { entitys[i, j].is_alive = true; } } } }
public LevelData(int xSize, int ySize) { tiles = new Tile[xSize, ySize]; entities = new Entity[xSize, ySize]; moveableTileEndPositions = new List <Vector2>(); levelSize = new Vector2(xSize, ySize); }
public override void Init() { gameboardEntity = Scene.Entities.FirstOrDefault(e => e.HasExactComponents(CompatibleTypes)); verticalElementsCount = gameboardEntity.GetComponent <Gameboard>().VerticalElementsCount; horizontalElementsCount = gameboardEntity.GetComponent <Gameboard>().HorizontalElementsCount; spacing = gameboardEntity.GetComponent <Gameboard>().Spacing; initialPosition = gameboardEntity.GetComponent <Transform>().Position; gameState = GameState.CheckingMatches; isSwapping = false; random = new Random(); gems = new Entity[horizontalElementsCount, verticalElementsCount]; //initialising stuff GemsInitialize(); Entity gameBoardTile = new TileEntity("tile", new Vector2(initialPosition.X, initialPosition.Y)); gameBoardTile.GetComponent <Transform>().SetScale(0.5f); Scene.AddEntity(gameBoardTile); score = new ScoreEntity("score", new Vector2(5, 60)); Scene.AddEntity(score); timer = new TimerEntity("timer", new Vector2(5, 20)); Scene.AddEntity(timer); }
public void StartExperiment(float foodSpawnRate) { // Initialise variables TileEntities = new Entity[Config.WorldSize, Config.WorldSize]; PreyList = new List <Prey>(); NewPreyList = new List <Prey>(); PreyCanMateList = new List <Prey>(); PredatorList = new List <Predator>(); FoodList = new List <Food>(); HasMapChanged = false; ticksSinceLastHour = 0; foodSpawnProgress = 0; groupingScoreCalculateProgress = Config.HoursPerGroupingScoreUpdate; TimeInHours = 0; GroupingScoreAvg = null; isPlaying = true; this.foodSpawnRate = foodSpawnRate; if (!Config.DoReplay) { SpawnRandomPrey(rand, Config.NumberOfPrey); SpawnRandomPredators(rand, Config.NumberOfPredators); SpawnRandomFood(rand, Config.StartingAmountOfFood); } }
public int[,] ParseEntityToInt(Entity[,] mapWithEntity) { int[,] result = new int[_map.Height - 1, _map.Width - 1]; for (int colCnt = 1; colCnt <= _map.Height - 1; colCnt++) { for (int rowCnt = 1; rowCnt <= _map.Width - 1; rowCnt++) { var item = mapWithEntity[colCnt, rowCnt]; if ((item is Space) || (item is MonsterFly) || (item is MonsterClever) || (item is MonsterNotFly) || (item is Bomber) || (item is Bomb) || (item is BomberOnBomb)) { if ((!(item is Bomber)) && (!(item is BomberOnBomb))) { result[colCnt - 1, rowCnt - 1] = Const.SPACE_CLEVER; continue; } else { result[colCnt - 1, rowCnt - 1] = Const.BOMBER_CLEVER; } } else { result[colCnt - 1, rowCnt - 1] = Const.WALL_CLEVER; } } } return(result); }
/// <summary> /// Questtracker requires the entity array used to create the current level to calculate the number of bosses in use. /// </summary> /// <param name="entityArray"></param> /// <param name="numberColumns"></param> /// <param name="numberRows"></param> public Questtracker(Entity[,] entityArray, int numberColumns, int numberRows) { uiBossCount = 0; uiBossesSlayed = 0; for (int x = 0, y = 0; y < numberRows; x++) { if (entityArray[x, y] != null && entityArray[x, y].GetIsBoss()) { uiBossCount++; } if (x >= numberColumns - 1) { x = 0; y++; } } if (uiBossCount == 0) { sQuesttext = "Exploration Mode"; } }
public World(int width, int height) { Width = width; Height = height; m_entitiesMap = new Entity[Width, Height]; }
public void InitBoard(int x, int y) { board = new Entity[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if ((i == 0 && j == 0) || (i == 0 && j == y - 1) || (i == x - 1 && j == 0) || (i == x - 1 && j == y - 1)) { board[i, j] = new Entity(i, j, Direction.None, "background"); continue; } if (j == 0) { board[i, j] = new BoardButton(Direction.North, i, j); continue; } if (j == y - 1) { board[i, j] = new BoardButton(Direction.South, i, j); continue; } if (i == 0) { board[i, j] = new BoardButton(Direction.East, i, j); continue; } if (i == x - 1) { board[i, j] = new BoardButton(Direction.West, i, j); continue; } board[i, j] = new Entity(i, j); } } }
public void generateMap(int level, ICardContext cardContext, float ratioEmptyCard = 1) { Random rnd = new Random(); Entity[,] entities = MapGenerator.generateMapCard(this.width, this.height, level); for (int x = 0; x < this.width; x++) { for (int y = 0; y < this.height; y++) { if (entities[x, y] == null) { int value = rnd.Next(100); if (value > (100 * ratioEmptyCard)) { this.setCard(x, y, null); } else { this.setCard(x, y, new Card(null, cardContext)); } } else { this.setCard(x, y, new Card(entities[x, y], cardContext)); } } } }
public Board() { grid = new Entity[8, 8]; Entity entity = new Entity(EntityType.Blue); PlaceEntity(entity, new Position(0, 0)); }
public void GetMapFromFile(string theFileName) { List <string> lines = new List <string>(); StreamReader theReader = new StreamReader(theFileName); while (!theReader.EndOfStream) { string line = theReader.ReadLine().Replace(" ", ""); // Remove spaces between characters lines.Add(line); } Entity[,] theEntities = new Entity[lines[0].Length, lines.Count]; for (int y = 0; y < lines.Count; y++) { for (int x = 0; x < lines[y].Length; x++) { theEntities[x, y] = MakeEntity(lines[y][x], new Point(x, y)); } } theEntities[1, 1] = new EmptySpot(new Point(1, 1)); Dot.NumDots--; MapGrid = theEntities; }
public double[,] CalculateDiffusion(Entity[,] grid, double curTime) { for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { Vector2 currentPos = new Vector2(i, j); if (curTime - lastSeen[i, j] >= attributes["timeToReexplore"]) { diffusionGrid[i, j] = attributes["desireToExplore"]; } else { diffusionGrid[i, j] = 0; } foreach (Food food in foods) { diffusionGrid[i, j] += Score(attributes["desireForFood"] * food.Calories(), food.Position(), currentPos); } foreach (Ant ant in ants) { diffusionGrid[i, j] += Score(attributes["desireToFollowAnts"], ant.Position(), currentPos); if (ant.health >= attributes["healthThreshold"]) { if (curTime - timeOfLastChild >= attributes["childbirthCooldown"] && curTime - timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME) { diffusionGrid[i, j] += Score((attributes["desireToMate"] + (ant.health - attributes["healthThreshold"])) / (children.Count + 1) , ant.Position(), currentPos); } } } Vector2 sameDirMove = directionTranslate(lastMove); if (i == sameDirMove.X && j == sameDirMove.Y && lastMove != '0') { // prevents equal-sum scenarios diffusionGrid[i, j] += attributes["desireToContinueInSameDirection"]; } Vector2 backwardsDirMove = directionTranslate(BackwardsDirection(lastMove)); if (i == backwardsDirMove.X && j == backwardsDirMove.Y && lastMove != '0') { // prevents oscillation diffusionGrid[i, j] += attributes["desireToGoBackwards"]; } } } return(diffusionGrid); }
void moveDown(Entity e, int column, int row, Entity[,] grid) { var nextRowPos = grid.GetNextEmptyRow(column, row); if (nextRowPos != row) { e.ReplacePosition(column, nextRowPos); } }
public Game(int width, int height, int snake_length) { this.snake_length = snake_length; snake_length_count = snake_length; this.width = width; this.height = height; board = new Entity[width, height]; controller = new FFNN(40, 6, 3); }
public void Update(Entity[,] grid, GameTime gameTime, Random rng) { // update health every second if (gameTime.TotalGameTime.TotalSeconds - timeOfLastUpdate > 1) { timeOfLastUpdate = gameTime.TotalGameTime.TotalSeconds; health -= STANDING_COST; } int curTime = (int)gameTime.TotalGameTime.TotalSeconds; Vector2 newPosition = position; foreach (char c in Entity.Directions) { newPosition = directionTranslate(c); // give birth to ant sometimes if (newPosition.Y >= 0 && newPosition.Y < grid.GetLength(1) && newPosition.X >= 0 && newPosition.X < grid.GetLength(0) && grid[(int)newPosition.X, (int)newPosition.Y] is Ant) { Ant other = (Ant)grid[(int)newPosition.X, (int)newPosition.Y]; if (curTime - timeOfLastChild >= attributes["childbirthCooldown"] && curTime - other.timeOfLastChild >= other.attributes["childbirthCooldown"] && curTime - other.timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME && curTime - timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME) { if (rng.NextDouble() <= attributes["childbirthPercentage"] / 100) { Ant child = new Ant(this, other, rng, grid); child.sprite = other.sprite; timeOfLastChild = curTime; other.timeOfLastChild = curTime; // health of parents go into raising the child child.health = other.attributes["childbirthCost"] + attributes["childbirthCost"]; other.health -= 1.5 * other.attributes["childbirthCost"]; health -= 1.5 * attributes["childbirthCost"]; } } } } // punish ants for having high eyesight, strength, etc health -= attributes["eyesightRange"] * .0001; // death if (health <= 0 || moves >= attributes["oldestPossibleAge"]) { // kill this ant if it has low health Die(grid); } }
public Level(int levelID, string name, string difficulty, Color32 backgroundColor, char[,] groundLayout, Entity[,] entityLayout, Mechanism[,] mechanismLayout) { _levelID = levelID; _name = name; _difficulty = difficulty; _backgroundColor = backgroundColor; _groundLayout = groundLayout; _entityLayout = entityLayout; _mechanismLayout = mechanismLayout; }
public Level(int levelID, string name, string difficulty, Color32 backgroundColor, char[,] groundLayout, Entity[,] entityLayout, Mechanism[,] mechanismLayout) { _levelID = levelID; _name = name; _difficulty = difficulty; _backgroundColor = backgroundColor; _groundLayout = groundLayout; _entityLayout = entityLayout; _mechanismLayout = mechanismLayout; }
public void moveDown(Entity[,] Pos, Air air) { if ((Pos[X, Y + 1] is Air) && (Y + 1 <= 16) && (Body.Visible == true)) { Body.Top = Body.Top + Body.Height;//(int)Math.Round(0.082 * Screen.PrimaryScreen.Bounds.Height - 30) Pos[X, Y] = air; Y = Y + 1; Pos[X, Y] = this; orientation = 3; } }
public static int GetNextEmptyRow(this Entity[,] grid, int column, int row) { var rowBelow = row - 1; while (rowBelow >= 0 && grid[column, rowBelow] == null) { rowBelow -= 1; } return(rowBelow + 1); }
public void moveLeft(Entity[,] Pos, Air air) { if ((Pos[X - 1, Y] is Air) && (X - 1 > 0) && (Body.Visible == true)) { Body.Left = Body.Left - Body.Width;//(int)Math.Round(0.020 * Screen.PrimaryScreen.Bounds.Width + 8) Pos[X, Y] = air; X = X - 1; Pos[X, Y] = this; orientation = 4; } }
public void moveRight(Entity[,] Pos, Air air) { if ((Pos[X + 1, Y] is Air) && (X + 1 <= 32) && (Body.Visible == true)) { Body.Left = Body.Left + Body.Width;//(int)Math.Round(0.020 * Screen.PrimaryScreen.Bounds.Width + 8) Pos[X, Y] = air; X = X + 1; Pos[X, Y] = this; orientation = 2; } }
public void moveUp(Entity[,] Pos, Air air) { if ((Pos[X, Y - 1] is Air) && (Y - 1 > 0) && (Body.Visible == true)) { Body.Top = Body.Top - Body.Height;//(int)Math.Round(0.082 * Screen.PrimaryScreen.Bounds.Height - 30) Pos[X, Y] = air; Y = Y - 1; Pos[X, Y] = this; orientation = 1; } }
public static void WriteMap(string mapname, Tile[,] tileArray, Entity[,] entityArray, string zoneName) { using (StreamWriter sw = File.CreateText(mapname)) { sw.WriteLine("zone;" + zoneName); for (int i = 0; i < tileArray.GetLength(0); i++) { for (int j = 0; j < tileArray.GetLength(1); j++) { var textureArchiveName = Archive.textureDictionary.FirstOrDefault(x => x.Value == tileArray[i, j].texture).Key; sw.WriteLine("tile;" + textureArchiveName + ";" + tileArray[i, j].position.X + ";" + tileArray[i, j].position.Y + ";" + tileArray[i, j].Wall); } } for (int i = 0; i < entityArray.GetLength(0); i++) { for (int j = 0; j < entityArray.GetLength(1); j++) { if (entityArray[i, j] != null) { var textureArchiveName = Archive.textureDictionary.FirstOrDefault(x => x.Value == entityArray[i, j].texture).Key; if (entityArray[i, j] is Player) { sw.WriteLine("player;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y); } else if (entityArray[i, j] is Enemy) { Enemy enemy = (Enemy)entityArray[i, j]; var teamName = CombatTeamDatabase.teamDictionary.FirstOrDefault(x => x.Value.ID == enemy.team.ID).Key; sw.WriteLine("enemy;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + teamName); } else if (entityArray[i, j] is FriendlyEntity) { FriendlyEntity npc = (FriendlyEntity)entityArray[i, j]; var dialogName = DialogDictionary.dialogDictionary.FirstOrDefault(x => x.Value == npc.dialog).Key; sw.WriteLine("friendly;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + dialogName); } else if (entityArray[i, j] is ItemEntity) { ItemEntity item = (ItemEntity)entityArray[i, j]; var itemName = ItemDatabase.items.FirstOrDefault(x => x.Value == item.containedItem).Key; sw.WriteLine("item;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + itemName); } else if (entityArray[i, j] is PortalEntity) { PortalEntity portal = (PortalEntity)entityArray[i, j]; sw.WriteLine("portal;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + portal.zoneName + ";" + portal.spawnPosition.X + ";" + portal.spawnPosition.Y); } } } } } }
/* Constructs a new Grid of size (X, Y) with 2 preinstantiated Geners and Solvers * PARAMETER: X and Y are positive. */ public Grid(int maxX, int maxY) { if (maxX <= 0 || maxY <= 0) { throw new ArgumentOutOfRangeException("Grid size must be positive."); } grid = new Entity[maxX, maxY]; registry = new List <Actor>(); this.MaxX = maxX; this.MaxY = maxY; }
public void AddElementArray(Entity[,] entitiesToAdd) { if (entitiesToAdd.Length < p_TableSlots.Length) { for (int x = 0; x < entitiesToAdd.Length; x++) { for (int y = 0; y < entitiesToAdd.Length; y++) { p_TableSlots[x, y].AddChild(entitiesToAdd[x, y]); } } } }
/// <summary> /// Generate a "square" room of size 20x10. /// </summary> public Room() { // Default room size. SizeCols = 20; SizeRows = 10; displayGrid = GenerateNewGrid(SizeCols, SizeRows); AddWall(new Coordinate(0, 0), new Coordinate(SizeRows - 1, 0), "WestWall"); AddWall(new Coordinate(0, 0), new Coordinate(0, SizeCols - 1), "NorthWall"); AddWall(new Coordinate(0, SizeCols - 1), new Coordinate(SizeRows - 1, SizeCols - 1), "EastWall"); AddWall(new Coordinate(SizeRows - 1, 0), new Coordinate(SizeRows - 1, SizeCols), "SouthWall"); }
public void Die(Entity[,] grid) { Statistics.totalNumberOfAnts--; foreach (KeyValuePair <string, double> kvp in attributes) { // remove these attributes from the current pool Statistics.currentSum[kvp.Key] -= attributes[kvp.Key]; } ((Ant)grid[(int)position.X, (int)position.Y]).isDead = true; grid[(int)position.X, (int)position.Y] = null; }
public Game(int width, int height, int snake_length, int vision, bool smell) { if (vision < 1) throw new ArgumentOutOfRangeException("vision must be 1 or more"); //snake properties this.vision = vision; this.smell = smell; this.snake_length = snake_length; snake_length_count = snake_length; controller = new FFNN(vision * 12 + (smell ? 4 : 0), 6, 3); //board properties this.width = width; this.height = height; board = new Entity[width, height]; }
public Game(Settings setmenu, ContentManager cm, int x, int y) { settingMenu = setmenu; _content = cm; boardX = x; boardY = y; viewX = 0; //Sets the view to the bottom left corner viewY = y - SCREEN; mBoard = new Tile[x, y]; entityMap = new Entity[x, y]; instance = this; if (QLearning) agentType = AgentType.QLearningAgent; }
public new void Initialize(String name, Vector2 position) { magnetHitBox = new Rectangle((int)position.X, (int)position.Y, 64, 64); minorEntities = new Entity[2,2]; Random rand = new Random(); for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { // randomly generate entities if (rand.Next(2) == 0) { Vector2 entityPosition = new Vector2(position.X + x * 32, position.Y + y * 32); int type = rand.Next(6); minorEntities[x, y] = spawnOnTables(entityPosition, type); } } } base.Initialize(name, position); }
public LightSystem() { _darkSpots = new Entity[GameState.GridWidth, GameState.GridHeight]; _sourcesAndLights = new Dictionary<Entity, List<Entity>>(); }
/// <summary> /// Create the level select menu /// </summary> void CreateLevelSelect() { Entity background = new Entity(0, GameState.LevelSelect); SpriteComponent backgroundSprite = new SpriteComponent(new Rectangle(0, 0, screenWidth, screenHeight), collBackgroundTexture); backgroundSprite.OffsetRatio = new Vector2(0, 0); background.AddComponent(backgroundSprite); EntityManager.AddEntity(background); Entity levelSelectTitle = new Entity(5, GameState.LevelSelect); levelSelectSpritePointer = new SpriteComponent(new Rectangle(400, 20, 200, 50), shadeTexture); levelSelectSpritePointer.OffsetRatio = new Vector2(.5f, .5f); levelSelectTitle.AddComponent(levelSelectSpritePointer); TextSpriteComponent selectLevelText = new TextSpriteComponent("Select a level!", TextAlignment.Left, new Vector2(400, 20), menuFont); selectLevelText.TextAlighment = TextAlignment.Center; levelSelectTitle.AddComponent(selectLevelText); EntityManager.AddEntity(levelSelectTitle); int numberTilesX = 3; int numberTilesY = 3; int xSideBuffer = 50; int ySideBuffer = 50; int xBuffer = 10; int yBuffer = 10; int previewWidth = (screenWidth - (xSideBuffer * 2) - (xBuffer * 2)) / numberTilesX; int previewHeight = (screenHeight - (ySideBuffer * 2) - (yBuffer * 2)) / numberTilesY; //Loading all maps! if (Directory.Exists("Content/Maps/MapFiles")) { string[] fileEntries = Directory.GetFiles("Content/Maps/MapFiles"); foreach (string fileName in fileEntries) mapNames.Add(fileName); } if (Directory.Exists("Content/Maps/MapPreviews")) { string[] fileEntries = Directory.GetFiles("Content/Maps/MapPreviews"); foreach (string fileName in fileEntries) { string finalFileName = ""; for (int c = 8; c < fileName.Length; c++) { finalFileName += fileName[c]; } mapPreviewNames.Add(finalFileName); } } //Done Loading maps! levelPreviews = new Entity[numberTilesX, numberTilesY]; int numberOfPreviews = 0; for (int y = 0; y < numberTilesY; y++) { for (int x = 0; x < numberTilesX; x++) { if (numberOfPreviews < mapNames.Count) { Entity preview = new Entity(8, GameState.LevelSelect); levelPreviews[x, y] = preview; SpriteComponent previewSprite = new SpriteComponent(new Rectangle(xSideBuffer + (x * (previewWidth + xBuffer)), ySideBuffer + (y * (previewHeight + yBuffer)), previewWidth, previewHeight), Content.Load<Texture2D>(mapPreviewNames[numberOfPreviews])); previewSprite.OffsetRatio = Vector2.Zero; preview.AddComponent(previewSprite); EntityManager.AddEntity(preview); numberOfPreviews++; } else //We are out of previews { levelPreviews[x, y] = null; } } } for (int y = 0; y < numberTilesY; y++) { for (int x = 0; x < numberTilesX; x++) { if (mapNames.Count < (y * numberTilesX) + x) { mapNames.Add(null); } } } //Creating the glow of being selected SpriteComponent selectedPreviewSprite = (SpriteComponent)levelPreviews[0, 0].GetComponent("Sprite"); Entity selectedLevelHighlight = new Entity(9, GameState.LevelSelect); levelSelectSpritePointer = new SpriteComponent(selectedPreviewSprite.Position, selectedGraphic); levelSelectSpritePointer.OffsetRatio = Vector2.Zero; selectedLevelHighlight.AddComponent(levelSelectSpritePointer); EntityManager.AddEntity(selectedLevelHighlight); }
public override void Initialize() { hexEntityGrid = new Entity[(int)gridSize.X, (int)gridSize.Y]; createGrid(); base.Initialize(); }
public MousePositionDetector(Entity[,] gridBox) { // set 2D array to use entityArray = gridBox; InitializeTree(); }
private void MainForm_Resize(object sender, EventArgs e) { this.cells = new Entity[(this.ClientSize.Width >> this.cellSize) + 1, (this.ClientSize.Height >> this.cellSize) + 1]; this.entities_Create(); }
public override void Initialize() { hexEntityGrid = new Entity[(int)gridSize.X, (int)gridSize.Y]; createGrid(); oldVisible = new List<HexComponent>(); newVisible = new List<HexComponent>(); base.Initialize(); }
// todo: keep track of the last generation of ants that were alive... then average out // all of their characteristics at the end, and analyze the difference between // the starting 10 ants and the last generation of ants // todo: implement DISEASE factor; it's a green spot that when stepped on produces disease // that wears down an ant's health. it can be passed on randomly to adjacent ants // and it becomes more severe with time until the ants die. protected override void Initialize() { debugMessage = ""; lastFoodSpawnTime = 0; //seeded by time rng = new Random((int)DateTime.Now.Ticks); // TODO: store generations in an array in Statistics // TODO: represent ants that are dead with a new icon foodSpawnInterval = 10; // how many seconds before food should respawn GRID_WIDTH = (3 * ((int) (7* (rng.NextDouble() * .7 + .3)))); GRID_HEIGHT = (int)((2f/3f)*GRID_WIDTH); STARTING_ANTS = (int)((rng.NextDouble()*.15)*GRID_WIDTH*GRID_HEIGHT) + 2; if (STARTING_ANTS > 20) STARTING_ANTS = 20; numberOfFoodsSpawned = (int)((rng.NextDouble()*.10)*GRID_WIDTH*GRID_HEIGHT)+1; // how many foods made Statistics.EXTREME_MUTATION_CHANCE = rng.NextDouble() * .5; Statistics.runTimeInSeconds = 0; LINE_THICKNESS = 0; gameState = Statistics.GameState.ANTS_SCREEN; secondsCounter = 30.0; cursor = new SpriteSheet(Content.Load<Texture2D>("cursorSheet"), 50, 50); cursor.SetScale(TILE_WIDTH, TILE_HEIGHT); Statistics.birthEffects = new List<BirthEffect>(); Statistics.foodEffects = new List<FoodEffect>(); Statistics.foodFades = new List<FoodFade>(); numberOfSecondsBeforeRoundEnds = 100; // TODO: remember to check that ALL statistics.attributes are refreshed // TODO: have a Dictionary that returns a list of ants associated with a particular generation number Statistics.numberOfMovements = 0; Statistics.longestAgeLived = 0; Statistics.largestNumberOfChildren = 0; Statistics.largestNumberOfFoodsEaten = 0; Statistics.topFiveAncestors = new List<Ant>(); Statistics.largestPopulation = 0; Statistics.longestGenerationLived = 0; Statistics.timeOfLastMovement = 0; Statistics.systemHasMoved = false; Statistics.totalFoods = 0; Statistics.totalNumberOfAnts = 0; grid = new Entity[GRID_WIDTH, GRID_HEIGHT]; SIDE_PANEL_WIDTH = (int) (graphics.GraphicsDevice.Viewport.Width * .2f); SCREEN_WIDTH = graphics.GraphicsDevice.Viewport.Width - SIDE_PANEL_WIDTH; SCREEN_HEIGHT = graphics.GraphicsDevice.Viewport.Height; TILE_WIDTH = SCREEN_WIDTH / GRID_WIDTH; TILE_HEIGHT = SCREEN_HEIGHT / GRID_HEIGHT; attributes = new Dictionary<string, double>(); Statistics.attributeRange = new Dictionary<string, Vector2>(); attributeRange = Statistics.attributeRange; Statistics.firstAverages = new Dictionary<string, double>(); Statistics.currentSum = new Dictionary<string, double>(); attributes["redColor"] = 100; //RGB color scheme attributeRange["redColor"] = new Vector2(0, 255); attributes["blueColor"] = 50; attributeRange["blueColor"] = new Vector2(0, 255); attributes["greenColor"] = 70; attributeRange["greenColor"] = new Vector2(0, 255); attributes["mutationFactor"] = .2; attributeRange["mutationFactor"] = new Vector2(0, 1); attributes["walkSpeed"] = 1000.0; // how many milliseconds it takes to move a single step attributeRange["walkSpeed"] = new Vector2(100, 2000); attributes["desireForFood"] = 100.0; // how much this ant prioritizes collecting food attributeRange["desireForFood"] = new Vector2(-4000, 4000); attributes["desireToFollowAnts"] = 10.0; // how much this ant is willing to follow/avoid ants attributeRange["desireToFollowAnts"] = new Vector2(-300, 300); attributes["desireToExplore"] = 1.0; // how much this ant is willing to explore new places attributeRange["desireToExplore"] = new Vector2(-200, 200); attributes["desireToMate"] = 500.0; // influenced by number of children attributeRange["desireToMate"] = new Vector2(-600, 600); attributes["desireToContinueInSameDirection"] = 1500.0; // prevents equal-sum scenarios attributeRange["desireToContinueInSameDirection"] = new Vector2(-2000, 2000); attributes["desireToGoBackwards"] = -1000.0; // prevents oscillation attributeRange["desireToGoBackwards"] = new Vector2(-1500, 1500); attributes["timeToReexplore"] = 10.0; // how long (seconds) an ant remembers a spot attributeRange["timeToReexplore"] = new Vector2(1, 30); attributes["decayFactor"] = 4.0; // analogous to the ant's sense of smell attributeRange["decayFactor"] = new Vector2(1, 8); attributes["healthThreshold"] = 200.0; // if another ant meets this health threshold, // then the two will mate and produce offspring attributeRange["healthThreshold"] = new Vector2(1, 400); attributes["childbirthPercentage"] = 21.0; // % chance of having child when threshold met attributeRange["childbirthPercentage"] = new Vector2(1, 100); attributes["childbirthCost"] = 50.0; // how much the parent pays to raise child attributeRange["childbirthCost"] = new Vector2(1, 300); attributes["childbirthCooldown"] = 10.0; // how many seconds before having a child again attributeRange["childbirthCooldown"] = new Vector2(5, 30); //attributes["health"] = 150.0; // health is restored by eating food, // and it is lowered by moving around and taking damage //attributeRange["health"] = new Vector2(0, 300); //attributes["strength"] = 10.0; // TODO: damage dealt in a hit to a predator. influences // construction of buildings, too attributes["oldestPossibleAge"] = 200.0; // number of moves this ant can make before dying attributeRange["oldestPossibleAge"] = new Vector2(30, 400); attributes["eyesightRange"] = 100.0; // number of tiles this ant can see attributeRange["eyesightRange"] = new Vector2(3, 150); //attributes["resistance"] = 5.0; // TODO: immunity to cold, poison, and disease // also, social model vs individualistic model. social model is a shared diffusion. //attributes["shelterShape"] = 22.0; // TODO: this number gets rounded down when used in calculation. // base-2 representation of the truncated version is // used. each digit represents having or not having // a block in a certain location in a 5x5 grid. // digit ordering as follows: (1 = first digit's block location) // and alphabetical chars correspond to numbers beyond 9 // 22 = 10110(b2) = _ // _| shape /* PLDEM * KC56F * B4127 * JA38G * OI9HN */ line = new Texture2D(graphics.GraphicsDevice, 1, 1); line.SetData(new Color[] { Color.White }); base.Initialize(); }