public Surface(Tower a, Tower b, SurfaceType type, Level Parent) { tower_A = a; tower_A.AddSurface(this); tower_B = b; tower_B.AddSurface(this); m_type = type; surfaceLineSegment = new LineSegment(a.getPosition(), b.getPosition()); parent = Parent; construct(); }
public void buildTower() { selectTower(new Tower(parent.id + " " + parent.num_towers, region, position, parent)); selected.built = false; region.AddTower(parent.id + " " + parent.num_towers, selected); parent.num_towers++; selected_2 = new Tower(parent.id + " " + parent.num_towers, region, position, parent); selected_2.built = false; region.AddTower(parent.id + " " + parent.num_towers, selected_2); parent.m_towers.Add(selected); parent.m_towers.Add(selected_2); parent.num_towers++; c_build = true; temp_surface = new Surface(selected, selected_2, c_build_type, region); temp_surface.built = false; region.AddSurface(temp_surface); }
private void UpdateClick(MouseState mousestate, MouseState lastmousestate) { if (mCurrentState == State.Click && mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released && mousestate.X < 800 && Stats.getGold() >= 50) { // **x2** //showGrid(1); TileX = (int)Math.Floor((float)(mousestate.X / tileWidth)); TileY = (int)Math.Floor((float)(mousestate.Y / tileHeight)); squarePositionX = (TileX * tileWidth) + (tileWidth / 2); squarePositionY = (TileY * tileHeight) + (tileHeight / 2); Tower aTower = new Tower("Tower", squarePositionX - 30, squarePositionY - 30); // *X1* Center tower on mouse. Change to 1/2 texture size. aTower.Scale = 0.5f; aTower.LoadContent(mContentManager); towers.Add(aTower); mCurrentState = State.Button; Stats.setGold(Stats.getGold() - 50); } if (mCurrentState == State.Button && mousestate.X > START_POSITION_X && mousestate.X < (START_POSITION_X + (int)(mSpriteTexture.Width * Scale)) && mousestate.Y > START_POSITION_Y && mousestate.Y < (START_POSITION_Y + (int)(mSpriteTexture.Height * Scale))) { //hover over button here if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) { mCurrentState = State.Click;//button click here } } }
public void changeTower(Tower new_tower) { tower_B = new_tower; }
public void Update() { if (!parent.isFiring()) { position += 15* input.LStickPosition(); } FixPosition(); if (input.IsCreateTowerNewlyPressed()) region.AddSpawnPoint(new SpawnPoint(position, 1000f, region)); if (input.IsCancelSurfaceNewlyPressed()) { if (selected_2 != null && !selected_2.built) region.RemoveTower(selected_2); if(selected != null && !selected.built) region.RemoveTower(selected); selected = null; c_build = false; } if (input.IsIncrementTowerNewlyPressed()) { incrementTowerIndex(); if (c_build) { if (!selected_2.built) { Tower temp = selected_2; selected_2 = parent.m_towers[tower_index]; temp_surface.changeTower(selected_2); temp.ClearSurfaces(); region.RemoveTower(temp); } else selected_2 = parent.m_towers[tower_index]; position = selected_2.position; Vector2 distance = selected.position - position; while (distance.LengthSquared() > 10000) { incrementTowerIndex(); selected_2 = parent.m_towers[tower_index]; position = selected_2.position; distance = selected.position - position; } temp_surface.changeTower(selected_2); } else selectTower(parent.m_towers[tower_index]); } if (input.IsDecrementTowerNewlyPressed()) { decrementTowerIndex(); if (c_build) { if (!selected_2.built){ Tower temp = selected_2; selected_2 = parent.m_towers[tower_index]; temp_surface.changeTower(selected_2); temp.ClearSurfaces(); region.RemoveTower(temp); }else selected_2 = parent.m_towers[tower_index]; position = selected_2.position; Vector2 distance = selected.position - position; while (distance.LengthSquared() > 14400) { incrementTowerIndex(); selected_2 = parent.m_towers[tower_index]; position = selected_2.position; distance = selected.position - position; } temp_surface.changeTower(selected_2); } else selectTower(parent.m_towers[tower_index]); } if (c_build) { Vector2 distance = selected.position - position; if (distance.LengthSquared() > 14400){ distance.Normalize(); position = selected.position - distance * 120f; } if (!selected_2.built) { selected_2.position = position; } temp_surface.ChangeType(c_build_type); } if (input.IsCreateSurfaceNewlyPressed() && parent.legalSurface(c_build_type)) { if (c_build) { selected.Anchor(); selected_2.Anchor(); c_temp = Vector2.Zero; temp_surface.built = true; c_build = false; selected.UnHighlight(); selected = null; selected_2 = null; temp_surface = null; parent.incrementSurface(c_build_type); }else { if (selected == null) buildTower(); else buildTower(selected); } } if (input.IsToggleBuildNewlyPressed()) { region.AddPrism(new AntiPrism(region, position)); } if (input.IsSetReflectiveNewlyPressed() && parent.legalSurface(Surface.SurfaceType.Reflective)) c_build_type = Surface.SurfaceType.Reflective; if (input.IsSetAbsorbantNewlyPressed() && parent.legalSurface(Surface.SurfaceType.Absorbant)) c_build_type = Surface.SurfaceType.Absorbant; if (input.IsSetRefractiveNewlyPressed() && parent.legalSurface(Surface.SurfaceType.Refractive)) c_build_type = Surface.SurfaceType.Refractive; if (input.createPrismNewlyPressed()) { region.AddPrism(position); } }
public void selectTower(Tower select) { if(selected != null) selected.UnHighlight(); selected = select; selected.Highlight(); }
public void RemoveTower(Tower remove) { List<Surface> destroyed = new List<Surface>(); foreach (Surface s in remove.adj_surfaces) { destroyed.Add(s); remove.owner.decrementSurface(s.M_type); } foreach (Surface s in destroyed) RemoveSurface(s); towers.Remove(remove.id); }
public void AddTower(String key,Tower add) { towers.Add(key,add); add.loadImage(m_content); }
public void removeTower(Tower remove) { m_towers.Remove(remove); }
public Map(int Height, int Width, int Center_X, int Center_Y, int left_Width, int top_Height, int right_Width, int down_Height, int screen_width, int screen_height) { bullet_to_wall = false; bullet_to_tower = false; center_X = Center_X; center_Y = Center_Y; Left_Width = left_Width; Top_Height = top_Height; Down_Height = down_Height; Right_Width = right_Width; Screen_Height = screen_height; Screen_Width = screen_width; height = Height; width = Width; Camera_Height = Screen_Height - Top_Height - Down_Height; Camera_Width = Screen_Width - Left_Width - Right_Width; Max_Distance_X = Camera_Width / 2; Max_Distance_Y = Camera_Height / 2; Min_Buff_X = -Left_Width; Min_Buff_Y = -Top_Height; Max_Buff_X = width - (Screen_Width - Right_Width); Max_Buff_Y = height - (Screen_Height - Top_Height); tower = new Tower[Towers_Count]; Random o = new Random(); for (int i = 0; i < Max_Zombies_Count; i++) { zombies[i] = new Zombie(); } n = height / 100; m = width / 100; Net = new int[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == 0 || j == 0 || i == n - 1 || j == m - 1) { Net[i, j] = 1; } else { Net[i, j] = 0; } } } int builded = 0; int need = o.Next(3, 10); while (builded != need) { int way = o.Next(1, 5); switch (way) { case 1: { bool place = false; int x = 0, y = 0; while (!place) { x = o.Next(1, m - 1); y = o.Next(1, n - 1); if (Net[y, x + 1] == 1 && (Net[y, x - 1] + Net[y, x] + Net[y - 1, x - 1] + Net[y - 1, x] + Net[y + 1, x - 1] + Net[y + 1, x]) == 0) { place = true; } } int l = o.Next(1, m / 2); if ((x - l) > 0) { for (int i = x - 1; i >= x - l; i--) { if (Net[y, i - 1] + Net[y + 1, i - 1] + Net[y - 1, i - 1] > 0) { place = false; } } } else { place = false; } if (place) { builded++; for (int i = x; i >= x - l; i--) { Net[y, i] = 1; } } } break; case 2: { bool place = false; int x = 0, y = 0; while (!place) { x = o.Next(1, m - 1); y = o.Next(1, n - 1); if (Net[y, x - 1] == 1 && (Net[y, x + 1] + Net[y, x] + Net[y - 1, x + 1] + Net[y - 1, x] + Net[y + 1, x + 1] + Net[y + 1, x]) == 0) { place = true; } } int l = o.Next(1, m / 2); if ((x + l) < m - 1) { for (int i = x + 1; i <= x + l; i++) { if (Net[y, i + 1] + Net[y + 1, i + 1] + Net[y - 1, i + 1] > 0) { place = false; } } } else { place = false; } if (place) { builded++; for (int i = x; i <= x + l; i++) { Net[y, i] = 1; } } } break; case 3: { bool place = false; int x = 0, y = 0; while (!place) { x = o.Next(1, m - 1); y = o.Next(1, n - 1); if (Net[y + 1, x] == 1 && (Net[y, x - 1] + Net[y, x] + Net[y, x + 1] + Net[y - 1, x - 1] + Net[y - 1, x] + Net[y - 1, x + 1]) == 0) { place = true; } } int l = o.Next(1, n / 2); if ((y - l) > 0) { for (int i = y - 1; i >= y - l; i--) { if (Net[i - 1, x - 1] + Net[i - 1, x] + Net[i - 1, x + 1] > 0) { place = false; } } } else { place = false; } if (place) { builded++; for (int i = y; i >= y - l; i--) { Net[i, x] = 1; } } } break; case 4: { bool place = false; int x = 0, y = 0; while (!place) { x = o.Next(1, m - 1); y = o.Next(1, n - 1); if (Net[y - 1, x] == 1 && (Net[y, x - 1] + Net[y, x] + Net[y, x + 1] + Net[y + 1, x - 1] + Net[y + 1, x] + Net[y + 1, x + 1]) == 0) { place = true; } } int l = o.Next(1, n / 2); if ((y + l) < n - 1) { for (int i = y + 1; i <= y + l; i++) { if (Net[i + 1, x - 1] + Net[i + 1, x] + Net[i + 1, x + 1] > 0) { place = false; } } } else { place = false; } if (place) { builded++; for (int i = y; i <= y + l; i++) { Net[i, x] = 1; } } } break; } } greed = new GreedHelp(Net, n, m, 100); for (int i = 0; i < Towers_Count; i++) { bool build = false; while (!build) { Random o1 = new Random(); int x = o1.Next(1, n - 2), y = o.Next(1, m - 2); if ((Net[x, y] == 0 && Net[x + 1, y] == 0 && Net[x + 1, y + 1] == 0 && Net[x, y + 1] == 0) && ((Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x + 2, y - 1] == 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x + 2, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0) || (Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0 && Net[x - 1, y + 2] == 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x + 2, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0) || (Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x - 1, y - 1] == 0 && Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0 && Net[x - 1, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0) || (Net[x, y + 2] > 0 && Net[x + 1, y + 2] > 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x + 2, y - 1] == 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x - 1, y - 1] == 0 && Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0) || (Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x + 2, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0) || (Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0 && Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0 && Net[x - 1, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0) || (Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0 && Net[x - 1, y - 1] == 0 && Net[x + 1, y + 2] > 0 && Net[x, y + 2] > 0) || (Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x + 2, y - 1] == 0 && Net[x + 1, y + 2] > 0 && Net[x, y + 2] > 0) || (Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x, y + 2] > 0 && Net[x + 1, y + 2] > 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0) || (Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0) || (Net[x - 1, y] == 0 && Net[x - 1, y + 1] == 0 && Net[x, y - 1] > 0 && Net[x + 1, y - 1] > 0 && Net[x, y + 2] > 0 && Net[x + 1, y + 2] > 0 && Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0) || (Net[x - 1, y] > 0 && Net[x - 1, y + 1] > 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x, y + 2] > 0 && Net[x + 1, y + 2] > 0 && Net[x + 2, y] > 0 && Net[x + 2, y + 1] > 0) || (Net[x - 1, y - 1] == 0 && Net[x, y - 1] == 0 && Net[x + 1, y - 1] == 0 && Net[x + 2, y - 1] == 0 && Net[x + 2, y] == 0 && Net[x + 2, y + 1] == 0 && Net[x + 2, y + 2] == 0 && Net[x + 1, y + 2] == 0 && Net[x, y + 2] == 0 && Net[x - 1, y + 2] == 0 && Net[x - 1, y + 1] == 0 && Net[x - 1, y] == 0))) { tower[i] = new Tower((y + 1) * 100, (x + 1) * 100, greed); Net[x, y] = 5; Net[x + 1, y] = 5; Net[x + 1, y + 1] = 5; Net[x, y + 1] = 5; build = true; } } } for (int i = 0; i < Towers_Count; i++) { tower[i].Update_Map(greed); } for (int i = 0; i < Portals_Count; i++) { bool built = false; while (!built) { int x = o.Next(0, m - 1), y = o.Next(0, n - 1); if (Net[y, x] == 0 && Net[y + 1, x] == 0 && Net[y, x + 1] == 0 && Net[y + 1, x + 1] == 0) { Portals_X[i] = ((x + 1) * 100); Portals_Y[i] = ((y + 1) * 100); Net[y, x + 1] = 2; Net[y + 1, x] = 2; Net[y, x] = 2; Net[y + 1, x + 1] = 2; built = true; } } } bool state = false; int h_x = 0, h_y = 0; while (!state) { h_x = o.Next(1, m - 1); h_y = o.Next(1, n - 1); if (Net[h_y, h_x] == 0) { state = true; } } state = false; int new_x = 0, new_y = 0; while (!state) { int x = o.Next(0, m - 1), y = o.Next(0, n - 1); if (Net[y, x] == 0 && Net[y + 1, x] == 0 && Net[y, x + 1] == 0 && Net[y + 1, x + 1] == 0) { new_x = ((x + 1) * 100); new_y = ((y + 1) * 100); Net[y, x + 1] = 4; Net[y + 1, x] = 4; Net[y, x] = 4; Net[y + 1, x + 1] = 4; state = true; } } base_1 = new Base(new_x, new_y); base_1.Time_Create += 50; state = false; while (!state) { int x = o.Next(0, m - 1), y = o.Next(0, n - 1); if (Net[y, x] == 0 && Net[y + 1, x] == 0 && Net[y, x + 1] == 0 && Net[y + 1, x + 1] == 0) { new_x = ((x + 1) * 100); new_y = ((y + 1) * 100); Net[y, x + 1] = 4; Net[y + 1, x] = 4; Net[y, x] = 4; Net[y + 1, x + 1] = 4; state = true; } } base_2 = new Base(new_x, new_y); hero = new Hero((h_x * 100) + 50, (h_y * 100) + 50, height, width, ((Screen_Width - Right_Width) / 100) + 1); greed = new GreedHelp(Net, n, m, 100); }