public DeadObject(Texture2D texture, Vector2 position, IsoGrid grid) { this.tex = texture; this.gridposition = position; this.rect = new Rectangle(0,0,tex.Width, tex.Height); this.position = grid.gridCoords(gridposition) - new Vector2(tex.Width/2.0f,tex.Height); }
public void Draw(GraphicsDevice graphicsDevice, SpriteBatch sbatch, List<Vector2> path, Vector2 offset, IsoGrid grid) { Texture2D blank = new Texture2D(graphicsDevice, 1, 1, false, SurfaceFormat.Color); blank.SetData(new[] { Microsoft.Xna.Framework.Color.White }); for (int x = 0; x < (path.Count() - 1); x++) { Vector2 startPoint = grid.gridCoords(path[x]); Vector2 endPoint = grid.gridCoords(path[x + 1]); float angle = (float)Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X); float length = Vector2.Distance(startPoint, endPoint); sbatch.Draw(blank, startPoint + offset, null, Microsoft.Xna.Framework.Color.Blue, angle, Vector2.Zero, new Vector2(length, 3.0f), SpriteEffects.None, 0); } }
public void StartRoute(ModCity city, ModCity homeCity, IsoGrid isogrid, Path path) { // calculate a path for movement running = true; drawPath = path.PathList(homeCity.gridposition + new Vector2(2, 2), city.gridposition + new Vector2(2, 2), isogrid); pathStep = 1; walkingTarget = drawPath[pathStep]; gridPosition = drawPath[0]; position = isogrid.gridCoords( homeCity.position); }
public GridTileRegion(Texture2D texture, Vector2 gridposition,Vector2 region, IsoGrid grid, Random random) { this.tex = texture; this.rect = new Rectangle(0, 0, tex.Width/size, tex.Height/size); this.gridPosition = gridposition; this.region = region; for (int x = 0; x < region.X; x++) { for (int y = 0; y < region.Y; y++) { nums.Add(new Vector2(random.Next(10),random.Next(10))); pos.Add(grid.gridCoords(gridposition + new Vector2(x,y))); } } }
public City(string name, Texture2D texture,Texture2D highlightTexture, Texture2D clickedTexture, Vector2 position, IsoGrid grid, Tuple<float,float,float> politicalStanding,List<Ship> shipList, List<Material> materialList, bool playerCity = false) { this.lowTex = texture; this.highTex = highlightTexture; this.clickTex = clickedTexture; this.gridposition = position; this.rect = new Rectangle(0, 0, lowTex.Width, lowTex.Height); this.position = grid.gridCoords(gridposition) - new Vector2(0, lowTex.Height); this.name = name; this.player = playerCity; this.politics = politicalStanding; this.ships = shipList; this.materials = materialList; this.tex = lowTex; }
public ModCity(string name, Texture2D texture, Texture2D highlightTexture, Texture2D clickedTexture, Vector2 gridposition,Vector2 gridOffset,float size, IsoGrid grid, Tuple<float, float, float> politicalStanding, List<Ship> shipList, List<Material> materialList, List<Tuple<Building, int>> buildingList, GraphicsDevice graphicsDevice,Random random, bool playerCity = false) { this.lowTex = texture; this.highTex = highlightTexture; this.clickTex = clickedTexture; this.gridposition = gridposition; this.rect = new Rectangle(0, 0, lowTex.Width, lowTex.Height); this.position = grid.gridCoords(gridposition) - new Vector2(0, lowTex.Height); this.name = name; this.player = playerCity; this.politics = politicalStanding; this.ships = shipList; this.materials = materialList; this.buildingTypes = buildingList; this.tex = lowTex; this.isogrid = new CityIsoGrid(graphicsDevice, Math.PI / 6.0, 8, size ,position + gridOffset); // fill grid with buildings in random positions List<Vector2> positions = new List<Vector2>{}; // list of possible positions... for (int i=0;i<isogrid.size;i++) { for (int j=0;j<isogrid.size;j++) { if (isogrid.usage[i,j] == 0) { positions.Add(new Vector2(i,j)); } } } List<Vector2> rpositions = new List<Vector2>{}; // randomised list of possible positions... foreach (Vector2 p in positions) { int i = random.Next(rpositions.Count); rpositions.Insert(i,p); } foreach (Tuple<Building, int> buildingType in buildingList) // fit them all in somewhere... { for (int n = 0; n < buildingType.Item2; n++) // for the number in the city... { Vector2 pos = Vector2.Zero; for (int j = 0; j < rpositions.Count; j++) // find a suitable position... { pos = rpositions[j]; bool fit = true; for (int l = 0; l < buildingType.Item1.footprint.X; l ++) { for (int k = 0; k < buildingType.Item1.footprint.Y; k++) { if ((int)pos.X + l >= isogrid.usage.GetLength(0) | (int)pos.Y + k >= isogrid.usage.GetLength(1)) { fit = false; } else if (isogrid.usage[(int)pos.X + l, (int)pos.Y + k] == 1) { fit = false; } } } if (fit == true) { break; } } int type = random.Next(1, buildingType.Item1.variations); buildings.Add(new Tuple<Building, int, Vector2>(buildingType.Item1, type, pos)); for (int x = (int)pos.X; x < buildingType.Item1.footprint.X + (int)pos.X; x++) { for (int y = (int)pos.Y; y < buildingType.Item1.footprint.Y + (int)pos.Y; y++) { isogrid.usage[x, y] = 1; rpositions.Remove(pos + new Vector2(x, y)); } } } } }
public void Update(ModCity homeCity, IsoGrid isogrid, GameTime gametime) { // continuous movement if (running == true) { direction = (isogrid.gridCoords(walkingTarget) - isogrid.gridCoords(gridPosition)); targetDistance = direction.Length(); direction.Normalize(); walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.02f; distanceGone = walkingOffset.Length(); if (distanceGone < targetDistance) { position = isogrid.gridCoords(gridPosition) + walkingOffset; } else { pathStep += 1; if (pathStep < drawPath.Count) { gridPosition = drawPath[pathStep - 1]; walkingTarget = drawPath[pathStep]; position = isogrid.gridCoords(gridPosition); } else { drawPath.Reverse(); pathStep = 1; walkingTarget = drawPath[pathStep]; gridPosition = drawPath[pathStep - 1]; position = isogrid.gridCoords(gridPosition); } walkingOffset = Vector2.Zero; targetDistance = 0; distanceGone = 0; } } // set direction anim (8 directions!) double dot = Vector2.Dot(new Vector2(0, -1), direction); // dot product of direction with vertical double angle = Math.Acos(dot); // angle from vertical if (angle == 0) { dir = 0; } else if (0 < angle && angle < Math.PI / 2 && direction.X > 0) { dir = 1; } else if (angle == Math.PI / 2 && direction.X > 0) { dir = 2; } else if (Math.PI / 2 < angle && angle < Math.PI && direction.X > 0) { dir = 3; } else if (angle == Math.PI) { dir = 4; } else if (Math.PI / 2 < angle && angle < Math.PI && direction.X < 0) { dir = 5; } else if (angle == Math.PI / 2 && direction.X < 0) { dir = 6; } else if (0 < angle && angle < Math.PI/2 && direction.X < 0) { dir = 7; } if (dir != 0) { } // update animation timer += gametime.ElapsedGameTime.Milliseconds; if (timer >= msecsTweenFrames) { timer = 0; if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; } } rect.X = currentFrame * rect.Width; rect.Y = dir * rect.Height; }