internal Ball.CollidedSide CollisionWith(Ball ball) { Ball.CollidedSide result = Ball.CollidedSide.None; for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++) { if (Cells[i][j] != null) { if (Cells[i][j].CollisionRect.Intersects( ball.CollisionRect)) { //See which side of the cell we hit if (Cells[i][j].CollisionRect.Top < ball.CollisionRect.Top && Cells[i][j].CollisionRect.Bottom >= ball.CollisionRect.Bottom) result = Ball.CollidedSide.LeftRight; else result = Ball.CollidedSide.TopBottom; Cells[i][j] = null; game.Player.Score += game.ConfigManager.scorePerCellDefault; CellsAlive--; return result; } } } } return result; }
public OknoGry() { InitializeComponent(); h = this.CreateGraphics(); surface = new Bitmap(Width, Height); g = Graphics.FromImage(surface);//surface - bufor, g-obsluga bufora, h-obsluga formy pilkaBit.MakeTransparent(Color.White); belka = new Paddle(Width / 2 - belkaBit.Width / 2, Height - belkaBit.Height - 40, belkaBit.Width, belkaBit.Height, belkaBit); pilka = new Ball(Width / 2, Height - belkaBit.Height - 40 - pilkaBit.Height, 20, 20, pilkaBit, true, 6, -6); }
private void applyBonus(int bonus, Paddle belka, Ball pilka, List<Brick>lista, OknoGry okno) { if (bonus == 2) { belka.setWidth(belka.getWidth() + 50); Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Zwiększenie belki!", 500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } else if (bonus == 3) { pilka.setSpeedX(pilka.getSpeedX() + 3); pilka.setSpeedY(pilka.getSpeedY() + 3); Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Przyspieszenie!", 500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } else if (bonus == 4) { pilka.setSpeedX(pilka.getSpeedX() - 3); pilka.setSpeedY(pilka.getSpeedY() - 3); if (pilka.getSpeedX() == 0) pilka.setSpeedX(-1); if (pilka.getSpeedY() == 0) pilka.setSpeedY(-1);//blokada przed ruchem poziomym i pionowym Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Zmiana kierunku piłki!", 500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } else if (bonus == 5) { foreach (Brick brick in lista) { brick.setY(brick.getY() + brick.getHeight()); } Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Obniżenie stropu!", 500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } else if (bonus == 6) { foreach (Brick brick in lista) { brick.setHeight(brick.getHeight() / 2); } Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Zmiana rozmiaru kafelków", 500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } else if (bonus == 7) { foreach (Brick brick in lista) { brick.setHeight(brick.getHeight() * 3 / 2); } Message bonusInfo = new Message(okno.Width / 2, okno.Height / 2, "Zwiększenie rozmiaru kafelków",500, false, Color.Black); okno.listaMessage.Add(bonusInfo);//dodanie wiadomości } }
public void Initialize() { ballRadius = 10; barSize = new Vector2(100, 10); blockSize = new Vector2(50, 10); ball=new Ball(ballRadius); bar=new Bar(barSize); blocks = new List<Block>(); for(int i=0;i<20;i++) { for (int j = 0; j < 10; j++) { blocks.Add(new Block(new Vector2(blockSize.X * i + 512 - 10 * blockSize.X + (float)0.25 * blockSize.X, 100+j*10), blockSize)); } } }
public void efektKolizji(int kolizja, Ball pilka, OknoGry okno) { switch (kolizja) { case 1: case 2: visible = false; pilka.setSpeedY(pilka.getSpeedY() * -1); break; case 3: case 4: visible = false; pilka.setSpeedX(pilka.getSpeedX() * -1); break; } if (okno.lotto.Next(100) < 10)//jeśli bonusik { BonusBrick bonus = new BonusBrick(x, y, width / 2, height / 2, true, okno.bonusBit, 1, 4, okno.lotto.Next(7)); okno.listaBonus.Add(bonus); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { ConfigManager = new ConfigManager(this); GameArea = new Rectangle(0, HUD.height, Window.ClientBounds.Width, Window.ClientBounds.Height - HUD.height); Player = new Player(this); Player.Lives = ConfigManager.playerLivesDefault; Ball = new Ball(this, Player.GetBallStartingPos()); backgroundRectangle = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height); hud = new HUD(this); controls = new ControlsManager(this); Restart(); //Starts the game with proper configuration curState = GameState.Playing; base.Initialize(); }