private void CheckEntityBounds(List <Apple> apples) { Kolobok kolobok = data.GetKolobok(); List <Wall> walls = (List <Wall>)data.GetWalls(); List <River> rivers = (List <River>)data.GetRivers(); List <Apple> applesTemp = new List <Apple>(apples); foreach (Apple apple in applesTemp) { if (boxCollides(kolobok.posX, kolobok.posY, kolobok.SpriteSize, apple.posX, apple.posY, apple.SpriteSize)) { data.RemoveApple(apple); lbl_AppleCounter.Text = (++AppleCounter).ToString(); data.AddApple(); } else { foreach (Wall wall in walls) { if (boxCollides(wall.posX, wall.posY, wall.SpriteSize, apple.posX, apple.posY, apple.SpriteSize)) { apple.posY -= 45; } } foreach (River river in rivers) { if (boxCollides(river.posX, river.posY, river.SpriteSize, apple.posX, apple.posY, apple.SpriteSize)) { apple.posY -= 45; } } } } }
public Form2(List <Apple> apples, List <EnemyTank> enemies, Kolobok kolobok) { InitializeComponent(); this.apples = apples; this.enemies = enemies; this.kolobok = kolobok; UpdateData(apples, enemies, kolobok); }
public Game() { for (int i = 0; i < GameForm.countWall; i++) { Rectangle rect = new Rectangle(); listWall.Add(new Wall(rect.Location)); } PlaceWalls(); for (int i = 0; i < GameForm.countRiver; i++) { Rectangle rect = new Rectangle(); listRiver.Add(new River(rect.Location)); } PlaceRiver(); for (int i = 0; i < (int)GameForm.paramsGame["countTank"]; i++) { Rectangle rect = new Rectangle(); do { rect = new Rectangle(GameForm.rand.Next(0, GameForm.MaxX), GameForm.rand.Next(0, GameForm.MaxY), (new Tank()).Width, (new Tank()).Height); } while (Collides(rect)); listTank.Add(new Tank(rect.Location, (int)GameForm.paramsGame["speed"])); } for (int i = 0; i < (int)GameForm.paramsGame["countApples"]; i++) { Rectangle rect = new Rectangle(); do { rect = new Rectangle(GameForm.rand.Next(0, GameForm.MaxX), GameForm.rand.Next(0, GameForm.MaxY), (new Apple()).Width, (new Apple()).Height); } while (Collides(rect)); listApple.Add(new Apple(rect.Location)); } Rectangle rect2 = new Rectangle(); do { rect2 = new Rectangle(GameForm.rand.Next(0, GameForm.MaxX), GameForm.rand.Next(0, GameForm.MaxY), (new Kolobok()).Width, (new Kolobok()).Height); } while (Collides(rect2)); packMan = new Kolobok(rect2.Location, (int)GameForm.paramsGame["speed"]); SubscribePos(); }
public Tank(ImageList imageList, Border border, Wall wall, Kolobok kolobok, BrokenWall brokenWall, int speed) : base(imageList, border, wall, brokenWall, speed) { CreateRandomLocation(); LastPosition = new Position(CurrentPosition); Directions = Direction.RIGHT; TanksView = new TankView(imageList); kolobok.HitTankEvent += Shot_HitTankEvent; positionsOfTanks.Add(this); }
public bool checkAccidentTankToKolobok(Kolobok kolobok) { Point coordKolobok = new Point(); coordKolobok.X = kolobok.x; coordKolobok.Y = kolobok.y; for (int j = 0; j < tanksList.Count; j++) { if (tanksList[j].direction == "UP") { if (collides(coordKolobok.X, coordKolobok.Y, coordKolobok.X + tank.sizeX - 11, coordKolobok.Y + tank.sizeY - 15, tanksList[j].x, tanksList[j].y, tanksList[j].x + tank.sizeX - 11, tanksList[j].y + tank.sizeY + tank.speed)) { return(true); } } else { if (tanksList[j].direction == "DOWN") { if (collides(coordKolobok.X - 2, coordKolobok.Y, coordKolobok.X + tank.sizeX - 15, coordKolobok.Y + tank.sizeY - 15, tanksList[j].x, tanksList[j].y - tank.speed, tanksList[j].x + tank.sizeX - 11, tanksList[j].y + tank.sizeY)) { return(true); } } else { if (tanksList[j].direction == "LEFT") { if (collides(coordKolobok.X - kolobok.speed, coordKolobok.Y, coordKolobok.X + tank.sizeX - 15, coordKolobok.Y + tank.sizeY - 15, tanksList[j].x, tanksList[j].y, tanksList[j].x + tank.sizeX - 3, tanksList[j].y + tank.sizeY)) { return(true); } } else { if (tanksList[j].direction == "RIGHT") { if (collides(coordKolobok.X, coordKolobok.Y, coordKolobok.X + tank.sizeX + tank.speed - 15, coordKolobok.Y + tank.sizeY - 15, tanksList[j].x, tanksList[j].y, tanksList[j].x + tank.sizeX - 11, tanksList[j].y + tank.sizeY)) { return(true); } } } } } } return(false); }
public bool checkAccidentBullToKolobok(Kolobok kolobok) { Point coordKolobok = new Point(); coordKolobok.X = kolobok.x; coordKolobok.Y = kolobok.y; for (int j = 0; j < bulletTankList.Count; j++) { if (bulletTankList[j].direction == "UP") { if (collides(coordKolobok.X, coordKolobok.Y, coordKolobok.X + kolobok.sizeX, coordKolobok.Y + kolobok.sizeY, bulletTankList[j].x, bulletTankList[j].y, bulletTankList[j].x + bulletTankList[j].sizeX, bulletTankList[j].y + bulletTankList[j].sizeY + bulletTankList[j].speed)) { return(true); } } else { if (bulletTankList[j].direction == "DOWN") { if (collides(coordKolobok.X, coordKolobok.Y, coordKolobok.X + kolobok.sizeX, coordKolobok.Y + kolobok.sizeY, bulletTankList[j].x, bulletTankList[j].y - bulletTankList[j].speed, bulletTankList[j].x + bulletTankList[j].sizeX, bulletTankList[j].y + bulletTankList[j].sizeY)) { return(true); } } else { if (bulletTankList[j].direction == "LEFT") { if (collides(coordKolobok.X - bulletTankList[j].speed, coordKolobok.Y, coordKolobok.X + kolobok.sizeX, coordKolobok.Y + kolobok.sizeY, bulletTankList[j].x, bulletTankList[j].y, bulletTankList[j].x + bulletTankList[j].sizeX, bulletTankList[j].y + bulletTankList[j].sizeY)) { return(true); } } else { if (bulletTankList[j].direction == "RIGHT") { if (collides(coordKolobok.X, coordKolobok.Y, coordKolobok.X + kolobok.sizeX + bulletTankList[j].speed, coordKolobok.Y + kolobok.sizeY, bulletTankList[j].x, bulletTankList[j].y, bulletTankList[j].x + bulletTankList[j].sizeX, bulletTankList[j].y + bulletTankList[j].sizeY)) { return(true); } } } } } } return(false); }
public void StopGame() { gameRun = false; timer1.Enabled = false; apples.Clear(); enemies.Clear(); bullets.Clear(); kolobok = null; g.Clear(backgroundColor); if (form2 != null) { form2.Clear(); } this.label2.Text = "0"; }
private void MainForm_KeyPress(object sender, KeyPressEventArgs e) { Kolobok kolobok = data.GetKolobok(); if (e.KeyChar == 'w') { //for (int i = 0; i < kolobok.Speed; i++) //{ // kolobok.posY -= 1; //} kolobok.Direction = RotateFlipType.RotateNoneFlipNone; // kolobok = KolobokAnimationCheck(kolobok); } if (e.KeyChar == 's') { //for (int i = 0; i < kolobok.Speed; i++) //{ // kolobok.posY += 1; //} kolobok.Direction = RotateFlipType.Rotate180FlipNone; // kolobok = KolobokAnimationCheck(kolobok); } if (e.KeyChar == 'a') { //for (int i = 0; i < kolobok.Speed; i++) //{ // kolobok.posX -= 1; //} kolobok.Direction = RotateFlipType.Rotate270FlipNone; // kolobok = KolobokAnimationCheck(kolobok); } if (e.KeyChar == 'd') { //for (int i = 0; i < kolobok.Speed; i++) //{ // kolobok.posX += 1; //} kolobok.Direction = RotateFlipType.Rotate90FlipNone; // kolobok = KolobokAnimationCheck(kolobok); } if (e.KeyChar == ' ') { data.AddBullet(new Bullet(kolobok, false)); } data.UpdateKolobok(kolobok); }
public void LoadReportData(Kolobok kolobok, Field field) { ClearData(); reportGridView.Rows.Add("Kolobok", kolobok.Position.X, kolobok.Position.Y); foreach (Tank tank in field.Tanks) { reportGridView.Rows.Add(tank.ObjectType, tank.Position.X, tank.Position.Y); } foreach (FieldObject fieldObject in field.FieldObjects) { reportGridView.Rows.Add(fieldObject.ObjectType, fieldObject.Position.X, fieldObject.Position.Y); } Show(); }
private void buttonStart_Click(object sender, EventArgs e) { kolobok = new Kolobok(new Bitmap(imageList1.Images[3], new Size(30, 30)), new Point(200, 290), 0, 0, pictureBox1.Size); foreach (Point point in respawnPoints) { AddEnemy(point); } for (int i = 0; i < 5; i++) { AddApple(); } gameRun = true; timer1.Enabled = true; }
private void Update(TimeSpan dt) { this.Focus(); gameTime = gameTime + dt.Milliseconds; List <Tank> tanks = (List <Tank>)data.GetTanks(); for (int i = 0; i < tanks.Count; i++) { //Tank temp = data.TankMove(tanks[i]); //tanks[i] = temp; //tanks[i] = data.TankMove(tanks[i]); tanks[i].Move(); if (tanks[i].fire) { data.AddBullet(new Bullet(tanks[i], true)); } CheckEntityBounds(tanks[i]); } data.UpdateTanks(tanks); Kolobok kolobok = data.GetKolobok(); kolobok.Move(); List <Bullet> bullets = (List <Bullet>)data.GetBullets(); for (int i = 0; i < bullets.Count; i++) { bullets[i].Move(); } data.UpdateBullets(bullets); CheckEntityBounds(kolobok); bullets = CheckEntityBounds(bullets); data.UpdateBullets(bullets); List <Apple> apples = (List <Apple>)data.GetApples(); CheckEntityBounds(apples); logForm.RefreshLog(); Map.Refresh(); }
internal void CheckKolobok(Kolobok kolobok, Tanks form1) { Rectangle rec = new Rectangle(this.Point, this.Size); Rectangle rec2 = new Rectangle(kolobok.Point, kolobok.Size); rec2.Inflate(60, 60); if (rec.IntersectsWith(rec2) && timeTillFire < 1) { this.Fire(form1); timeTillFire = 100; } else { timeTillFire--; } }
internal void UpdateData(List <Apple> apples, List <EnemyTank> enemies, Kolobok kolobok) { dataSource = new List <GameObject>(); dataSource.Add((GameObject)kolobok); foreach (EnemyTank item in enemies) { dataSource.Add((GameObject)item); } foreach (Apple item in apples) { dataSource.Add((GameObject)item); } dataGridView1.DataSource = dataSource; }
private void button1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tbCountOfTanks.Text) && !int.TryParse(tbCountOfTanks.Text, out countOfTanks)) { label2.Text = "Введите корректное значение"; return; } if (!String.IsNullOrEmpty(tbCountOfApple.Text) && !int.TryParse(tbCountOfApple.Text, out countOfApple)) { lblError.Text = "Введите корректное значение"; return; } if (!String.IsNullOrEmpty(tbSpeed.Text) && !int.TryParse(tbSpeed.Text, out speed)) { label6.Text = "Введите корректное значение"; return; } tank = new Tank[countOfTanks]; kolobok = new Kolobok(imageList1, border, wall, brokenWall, speed); listOfObjects.Add(kolobok); for (int i = 0; i < countOfTanks; i++) { tank[i] = new Tank(imageList1, border, wall, kolobok, brokenWall, speed); listOfObjects.Add(tank[i]); Thread.Sleep(50); } kolobok.InitEvent(tank); apple = new Apple[countOfApple]; for (int i = 0; i < countOfApple; i++) { apple[i] = new Apple(imageList1, border, wall, brokenWall); listOfObjects.Add(apple[i]); Thread.Sleep(50); } pictureBox1.Image = buf; timer1.Start(); Reset(); }
public void RefreshData(Kolobok kolobok, Field field) { int index = 1; reportGridView[1, 0].Value = kolobok.Position.X; reportGridView[2, 0].Value = kolobok.Position.Y; foreach (Tank tank in field.Tanks) { reportGridView[1, index].Value = tank.Position.X; reportGridView[2, index].Value = tank.Position.Y; index++; } foreach (FieldObject fieldObject in field.FieldObjects) { reportGridView[1, index].Value = fieldObject.Position.X; reportGridView[2, index].Value = fieldObject.Position.Y; index++; } }
public Point[] CreateArrCoordinateApple(Point[] arrCoordinateHurdles, Kolobok kolobok, Point[] arrCoordinateRiver, Point[] arrCoordinateMonolith) { Point[] arrCoordinateApple = new Point[countApple]; Random random = new Random(); bool check = true; while (check) { for (int i = 0; i < arrCoordinateApple.Length; i++) { arrCoordinateApple[i].X = random.Next(36, 684); arrCoordinateApple[i].Y = random.Next(16, 560); } if (checkCollisApple(arrCoordinateApple, arrCoordinateHurdles)) { continue; } if (checkCollisApple(arrCoordinateApple, arrCoordinateMonolith)) { continue; } if (checkCollisApple(arrCoordinateApple, arrCoordinateRiver)) { continue; } if (checkCollisApple(arrCoordinateApple, arrCoordinateApple)) { continue; } if (checkCollisApple(arrCoordinateApple, transfCoordKolToArr(kolobok))) { continue; } check = false; } return(arrCoordinateApple); }
public Shot(ImageList imageList, ITanks tanks) { this.imageList = imageList; CurrentPosition = new Position(tanks.CurrentPosition.X, tanks.CurrentPosition.Y); Directions = new Direction(); if (tanks is Tank) { Tank tank = tanks as Tank; ImageFile = imageList.Images["Enemy_Shot.png"]; this.tank = tank; tank.ShotEvent += Kolobok_ShotEvent; Speed = tank.Speed; } else if (tanks is Kolobok) { Kolobok kolobok = tanks as Kolobok; ImageFile = imageList.Images["Shot.png"]; this.kolobok = kolobok; kolobok.ShotEvent += Kolobok_ShotEvent; Speed = kolobok.Speed; } }
public List <Bullet> CreateKolobokBullet(Kolobok kolobok) { Point coordinatesBullet = Point.Empty; int width = 19; int height = 15; int speed = 8; /////SPEED if (kolobok.direction == arrDirection[0]) { coordinatesBullet.X = kolobok.x + kolobok.sizeX / 2 - 3; coordinatesBullet.Y = kolobok.y; } else if (kolobok.direction == arrDirection[1]) { coordinatesBullet.X = kolobok.x + kolobok.sizeX / 2 - 4; coordinatesBullet.Y = kolobok.y + kolobok.sizeY / 2; } else if (kolobok.direction == arrDirection[2]) { coordinatesBullet.X = kolobok.x; coordinatesBullet.Y = kolobok.y + kolobok.sizeY / 2 - 5; } else if (kolobok.direction == arrDirection[3]) { coordinatesBullet.X = kolobok.x + kolobok.sizeX / 2; coordinatesBullet.Y = kolobok.y + kolobok.sizeY / 2 - 5; } string direction = kolobok.direction; Bullet bullet = new Bullet(coordinatesBullet.X, coordinatesBullet.Y, width, height, speed, direction); bulletKolobokList.Add(bullet); return(bulletKolobokList); }
public StatisticForm(Kolobok kolobok, Tank[] tanks, Apple[] apples) { InitializeComponent(); bindingList = new BindingList <ITanks>(); bindingList.Add(kolobok); foreach (var tank in tanks) { bindingList.Add(tank); } foreach (var apple in apples) { bindingList.Add(apple); } source = new BindingSource(bindingList, null); var result = from t in bindingList select new { t.GetType().Name, t.CurrentPosition.X, t.CurrentPosition.Y }; dgvStatistic.DataSource = result.ToList(); timer1.Interval = 200; timer1.Start(); }
//private Kolobok KolobokAnimationCheck(Kolobok kolobok) //{ // if (KolobokAnimation==2) // { // KolobokAnimation = 0; // if (kolobok.CurrentPic!=6) // { // kolobok.CurrentPic++; // return kolobok; // } // else // { // kolobok.CurrentPic = 0; // return kolobok; // } // } // else // { // KolobokAnimation++; // return kolobok; // } //} #region Drawing private void Map_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { this.Focus(); Graphics g = e.Graphics; List <Wall> walls = (List <Wall>)data.GetWalls(); Bitmap sprite; if (walls.Count != 0) { sprite = new Bitmap(walls[0].Sprite); foreach (Wall wall in walls) { g.DrawImage(sprite, wall.posX, wall.posY); } } Kolobok kolobok = data.GetKolobok(); sprite = new Bitmap(kolobok.Sprite[kolobok.CurrentPic]); sprite.RotateFlip(kolobok.Direction); g.DrawImage(sprite, kolobok.posX, kolobok.posY); List <Tank> tanks = (List <Tank>)data.GetTanks(); if (tanks.Count != 0) { foreach (Tank tank in tanks) { sprite = new Bitmap(tank.Sprite); sprite.RotateFlip(tank.Direction); g.DrawImage(sprite, tank.posX, tank.posY); } } else { Victory = true; } List <River> rivers = (List <River>)data.GetRivers(); foreach (River river in rivers) { Bitmap spriteTemp = new Bitmap(river.Sprite); sprite = new Bitmap(spriteTemp, new Size(river.SpriteSize[0], river.SpriteSize[1])); g.DrawImage(sprite, river.posX, river.posY); } List <Bullet> bullets = (List <Bullet>)data.GetBullets(); foreach (Bullet bullet in bullets) { Bitmap spriteTemp = new Bitmap(bullet.Sprite); sprite = new Bitmap(spriteTemp, new Size(bullet.SpriteSize[0], bullet.SpriteSize[1])); sprite.RotateFlip(bullet.Direction); g.DrawImage(sprite, bullet.posX, bullet.posY); } List <Apple> apples = (List <Apple>)data.GetApples(); foreach (Apple apple in apples) { Bitmap spriteTemp = new Bitmap(apple.Sprite); sprite = new Bitmap(spriteTemp, new Size(apple.SpriteSize[0], apple.SpriteSize[1])); g.DrawImage(sprite, apple.posX, apple.posY); } List <Explosion> explosions = new List <Explosion>(Explosions); foreach (Explosion explosion in explosions) { Bitmap spriteTemp = new Bitmap(explosion.Sprites[explosion.curentpic++]); sprite = new Bitmap(spriteTemp, new Size(explosion.SpriteSize[0], explosion.SpriteSize[1])); g.DrawImage(sprite, explosion.posX, explosion.posY); if (explosion.curentpic >= 3) { Explosions.Remove(explosion); } } if (Victory) { Configuration configuration = data.Start(); Bitmap spriteTemp = new Bitmap(@"..\..\..\img\Victory.png"); sprite = new Bitmap(spriteTemp, new Size(configuration.MapWidth, configuration.MapHeight)); g.DrawImage(sprite, 0, 0); timer.Stop(); } if (GameOver) { Configuration configuration = data.Start(); Bitmap spriteTemp = new Bitmap(@"..\..\..\img\gameover.png"); sprite = new Bitmap(spriteTemp, new Size(configuration.MapWidth, configuration.MapHeight)); g.DrawImage(sprite, 0, 0); timer.Stop(); } }
public void Start(TanksForm fm) { UnSubscribe(); Apples.Clear(); Tanks.Clear(); Walls.Clear(); ShotsKolobok.Clear(); ShotsTanks.Clear(); kolobok = null; gameOver = false; Score = 0; Delta = 30; DeltaShots = 30; map = fm.map; backgroundMap = new Bitmap(map.Width, map.Height); mapGraphics = Graphics.FromImage(backgroundMap); mapGraphics.FillRectangle(Brushes.Black, 0, 0, map.Width, map.Height); for (int i = 0; i < example.Count(); i++) { for (int j = 0; j < example[i].Length; j++) { if (example[i][j] == 'X') { Walls.Add(new Wall(j, i)); mapGraphics.DrawImage(Walls.Last().Img, Walls.Last().X *TanksForm.sizeCell, Walls.Last().Y *TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } } } SpawnApples(); while (Tanks.Count < tanksCount) { Tanks.Add(new Tank()); foreach (var item in Walls) { if (Tanks.Last().CollidesWith(item)) { Tanks.RemoveAt(Tanks.Count - 1); break; } } } for (int i = 0; i < Apples.Count; i++) { mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * TanksForm.sizeCell, Apples[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } for (int i = 0; i < Tanks.Count; i++) { mapGraphics.DrawImage(Tanks[i].Img, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } while (true) { kolobok = new Kolobok(); if (!kolobok.CollidesWithWalls(Walls)) { break; } } Subscribe(); mapGraphics.DrawImage(kolobok.Img, kolobok.X * TanksForm.sizeCell, kolobok.Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); map.Image = backgroundMap; }
//Переопределить метод Move, чтобы он помечал на уничтожение пулю при соприкосновением с любым объектом public void Move(DateTime privStep, DateTime now, List <GameObject> walls, List <EnemyTank> enemies, Kolobok kolobok) { int delta = this.Speed * (now - privStep).Milliseconds / 1000; Point nextPoint = new Point(this.Point.X, this.Point.Y); if (delta == 0) { return; } switch (this.Direction) { case Direction.LEFT: nextPoint.X -= delta; if (CheckCollision(nextPoint, this.Size, this.Id, walls)) { this.IsHit = true; nextPoint.X += delta; } break; case Direction.UP: nextPoint.Y -= delta; if (CheckCollision(nextPoint, this.Size, this.Id, walls)) { this.IsHit = true; nextPoint.Y += delta; } break; case Direction.RIGHT: nextPoint.X += delta; if (CheckCollision(nextPoint, this.Size, this.Id, walls)) { this.IsHit = true; nextPoint.X -= delta; } break; case Direction.DOWN: nextPoint.Y += delta; if (CheckCollision(nextPoint, this.Size, this.Id, walls)) { this.IsHit = true; nextPoint.Y -= delta; } break; } switch (this.Direction) { case Direction.LEFT: nextPoint.X -= delta; if (CheckCollision(nextPoint, this.Size, this.Id, enemies)) { this.IsHit = true; nextPoint.X += delta; } break; case Direction.UP: nextPoint.Y -= delta; if (CheckCollision(nextPoint, this.Size, this.Id, enemies)) { this.IsHit = true; nextPoint.Y += delta; } break; case Direction.RIGHT: nextPoint.X += delta; if (CheckCollision(nextPoint, this.Size, this.Id, enemies)) { this.IsHit = true; nextPoint.X -= delta; } break; case Direction.DOWN: nextPoint.Y += delta; if (CheckCollision(nextPoint, this.Size, this.Id, enemies)) { this.IsHit = true; nextPoint.Y -= delta; } break; } Size size = new Size((gameField.Width - (2 * Size.Width)), (gameField.Height - (2 * Size.Height))); Rectangle modifiedGameField = new Rectangle(new Point(Size.Width, Size.Height), size); Rectangle objectRect = new Rectangle(nextPoint, Size); if (!objectRect.IntersectsWith(modifiedGameField)) { this.IsHit = true; } else { this.Point = nextPoint; } }
public Model(int fieldWidth, int fieldHeight, int tanksAmount, int applesAmount, int objectsSpeed) { if ((fieldWidth >= 250) && (fieldWidth <= 770)) { _fieldWidth = fieldWidth; } else { _fieldWidth = 250; } if ((fieldHeight >= 250) && (fieldHeight <= 300)) { _fieldHeight = fieldHeight; } else { _fieldHeight = 250; } if ((tanksAmount >= 10) && (tanksAmount <= 1)) { _tanksAmount = tanksAmount; } else { _tanksAmount = 5; } if ((applesAmount >= 10) && (applesAmount <= 1)) { _applesAmount = applesAmount; } else { _applesAmount = 5; } if ((objectsSpeed >= 10) && (objectsSpeed <= 1)) { ObjectsSpeed = objectsSpeed; } else { ObjectsSpeed = 10; } _objectsSpeed = objectsSpeed; kolobok = new Kolobok(); random = new Random(); Walls = new List <Wall>(); Apples = new List <Apple>(); Tanks = new List <Tank>(); Projectiles = new List <Projectile>(); PackmanProjectiles = new List <PackmanProjectile>(); CreateWalls(); CreateApples(); CreateTanks(); timer.Interval = _objectsSpeed; timer.Tick += new EventHandler(timer_Tick); }
public Point[] AddApple(Point[] arrCoordinateApple, Point[] arrCoordinateHurdles, Kolobok kolobok, Point[] arrCoordinateRiver, Point[] arrCoordinateMonolith) { Point[] arrCoordinateAppleNew = new Point[countApple]; Random random = new Random(); bool check = true; if (arrCoordinateApple.Length < countApple) { for (int i = 0; i < arrCoordinateApple.Length; i++) { arrCoordinateAppleNew[i] = arrCoordinateApple[i]; } while (check) { for (int i = countApple - 1; i > arrCoordinateApple.Length - 1; i--)//Думал повторяющийся код обернуть в метод, но тут в условии знаки разные, поэтому не получилось { arrCoordinateAppleNew[i].X = random.Next(36, 684); arrCoordinateAppleNew[i].Y = random.Next(16, 560); } if (checkCollisApple(arrCoordinateAppleNew, arrCoordinateHurdles)) { continue; } if (checkCollisApple(arrCoordinateAppleNew, arrCoordinateMonolith)) { continue; } if (checkCollisApple(arrCoordinateAppleNew, arrCoordinateRiver)) { continue; } if (checkCollisApple(arrCoordinateAppleNew, arrCoordinateAppleNew)) { continue; } if (checkCollisApple(arrCoordinateAppleNew, transfCoordKolToArr(kolobok))) { continue; } check = false; } return(arrCoordinateAppleNew); } return(arrCoordinateApple); }
private void CheckEntityBounds(Kolobok kolobok) { List <Wall> walls = (List <Wall>)data.GetWalls(); List <Tank> tanks = (List <Tank>)data.GetTanks(); List <River> rivers = (List <River>)data.GetRivers(); if (kolobok.posX < 0) { kolobok.Direction = RotateFlipType.Rotate90FlipNone; } else if (kolobok.posX > MapWidth - kolobok.SpriteSize[0]) { kolobok.Direction = RotateFlipType.Rotate270FlipNone; } foreach (Wall wall in walls) { if (boxCollides(wall, kolobok.posX, kolobok.posY, kolobok.SpriteSize)) { if (kolobok.Direction == RotateFlipType.Rotate180FlipNone) { kolobok.Direction = RotateFlipType.RotateNoneFlipNone; } else if (kolobok.Direction == RotateFlipType.RotateNoneFlipNone) { kolobok.Direction = RotateFlipType.Rotate180FlipNone; } else if (kolobok.Direction == RotateFlipType.Rotate270FlipNone) { kolobok.Direction = RotateFlipType.Rotate90FlipNone; } else if (kolobok.Direction == RotateFlipType.Rotate90FlipNone) { kolobok.Direction = RotateFlipType.Rotate270FlipNone; } } } foreach (River river in rivers) { if (boxCollides(river.posX, river.posY, river.SpriteSize, kolobok.posX, kolobok.posY, kolobok.SpriteSize)) { if (kolobok.Direction == RotateFlipType.Rotate180FlipNone) { kolobok.Direction = RotateFlipType.RotateNoneFlipNone; kolobok.posY -= 10; } else if (kolobok.Direction == RotateFlipType.RotateNoneFlipNone) { kolobok.Direction = RotateFlipType.Rotate180FlipNone; kolobok.posY += 10; } else if (kolobok.Direction == RotateFlipType.Rotate270FlipNone) { kolobok.Direction = RotateFlipType.Rotate90FlipNone; kolobok.posX += 10; } else if (kolobok.Direction == RotateFlipType.Rotate90FlipNone) { kolobok.Direction = RotateFlipType.Rotate270FlipNone; kolobok.posX -= 10; } } } foreach (Tank tank in tanks) { if ((tank.posX != kolobok.posX || tank.posY != kolobok.posY) && boxCollides(tank.posX, tank.posY, tank.SpriteSize, kolobok.posX, kolobok.posY, kolobok.SpriteSize)) { GameOver = true; } } if (kolobok.posY < 0) { kolobok.Direction = RotateFlipType.Rotate180FlipNone; } else if (kolobok.posY > MapHeight - kolobok.SpriteSize[1]) { kolobok.Direction = RotateFlipType.RotateNoneFlipNone; } }
private List <Bullet> CheckEntityBounds(List <Bullet> bullets) { List <Wall> walls = (List <Wall>)data.GetWalls(); List <Bullet> bulletsTemp = new List <Bullet>(bullets); List <Tank> tanks = (List <Tank>)data.GetTanks(); List <Tank> tanksTemp = (List <Tank>)data.GetTanks(); foreach (Bullet bullet in bullets) { if (bullet.posX < 0) { bulletsTemp.Remove(bullet); break; } else if (bullet.posX > MapWidth - bullet.SpriteSize[0]) { bulletsTemp.Remove(bullet); break; } if (bullet.posY < 0) { bulletsTemp.Remove(bullet); break; } else if ((bullet.posY > MapHeight - bullet.SpriteSize[1]) && !(bullet.Direction == RotateFlipType.Rotate270FlipNone || bullet.Direction == RotateFlipType.Rotate90FlipNone)) { bulletsTemp.Remove(bullet); break; } foreach (Wall wall in walls) { if (boxCollides(wall.posX, wall.posY, wall.SpriteSize, bullet)) { wall.Strength--; bulletsTemp.Remove(bullet); Explosions.Add(new Explosion() { posX = bullet.posX, posY = bullet.posY }); break; } } if (bullet.enemyFire == false) { foreach (Tank tank in tanks) { if (boxCollides(tank.posX, tank.posY, tank.SpriteSize, bullet)) { tanksTemp.Remove(tank); bulletsTemp.Remove(bullet); break; } } } else { Kolobok kolobok = data.GetKolobok(); if ((boxCollides(kolobok.posX, kolobok.posY, kolobok.SpriteSize, bullet))) { GameOver = true; } } } data.UpdateTanks(tanksTemp); return(bulletsTemp); }
public void ResetKolobok() { kolobok = new Kolobok(x, y, width, height, speed, score, direction); }
private void buttonStart_Click(object sender, EventArgs e) { b = new Bitmap(pictureBox1.Width, pictureBox1.Height); pictureBox1.Image = b; walls = new List <BrickWall>(); for (int i = 0; i < 13; i++) { walls.Add(new BrickWall(50 + i * 20, 50)); walls.Add(new BrickWall(50 + i * 20, 70)); } for (int i = 0; i < 10; i++) { walls.Add(new BrickWall(50, 140 + i * 20)); walls.Add(new BrickWall(70, 140 + i * 20)); } for (int i = 0; i < 9; i++) { walls.Add(new BrickWall(140 + i * 20, 160)); walls.Add(new BrickWall(140 + i * 20, 180)); } water = new Water(160, 260, 160, 40); player = new Kolobok(340, 340, speed); tanks = new List <Tank>(); for (int i = 0, x = 0; i < countOfTanks; i++, x += 45) { tanks.Add(new Tank(x, 0, speed)); } apples = new List <Apple>(); for (int i = 0; i < countOfApples; i++) { Point pos = GetRandomPosition(); apples.Add(new Apple(pos.X, pos.Y)); } bulletsOfPlayer = new List <Bullet>(); bulletsOfTanks = new List <Bullet>(); detonations = new List <Detonation>(); timerOfGame.Enabled = true; timerTankDirectionSwitchAndResumeUpdate.Enabled = true; score = 0; entities = new List <Entity>(); entities.Add(player); entities.AddRange(tanks); entities.AddRange(detonations); entities.AddRange(apples); entities.Add(water); entities.AddRange(walls); resume = new Resume(); resume.StartPosition = FormStartPosition.Manual; resume.Location = new Point(this.Location.X + this.Width, this.Location.Y); resume.dataGridView1.DataSource = entities; resume.Show(); this.Focus(); }