void BallAndDeskContact(SuperBall ball) { ball.top_step = -ball.top_step; if (ball.Left - desk.Left < desk_ex_areas) { ball.left_step -= 3; } else if (ball.Left >= desk.Left + desk.Width - desk_ex_areas) { ball.left_step += 3; } }
void BrickContact(SuperBrick brick) { if (brick.include_fireballpack) { SuperBall pack = new SuperBall(matilda1, "3_fireballs_pack.png", brick.Left + brick.Width / 2 - 25 / 2, brick.Top, 25, 25, "firepack"); fireballs_pack.Add(pack); } if (brick.multi_live) { brick.count_live--; if (brick.count_live > 0) { return; } } brick.Dispose(); bricks.Remove(brick); }
private void matilda1_OnConnection(SuperImage a, SuperImage b) { //Отбиваемся от шариков доской if (a.Name == "Шарик" && b.Name == "доска") { BallAndDeskContact((SuperBall)a); } if (a.Name == "доска" && b.Name == "Шарик") { BallAndDeskContact((SuperBall)b); } // получаем снаряды if (a.Name == "firepack" && b.Name == "доска") { a.Dispose(); fireballs_pack.Remove(a); bullet_count += 3; } if (a.Name == "доска" && b.Name == "firepack") { b.Dispose(); fireballs_pack.Remove(b); bullet_count += 3; } // попадание снарядами if (a.Name == "Кирпич" && b.Name == "fire!") { b.Dispose(); bullets.Remove(b); BrickContact((SuperBrick)a); CheckVictory(); } if (a.Name == "fire!" && b.Name == "Кирпич") { a.Dispose(); bullets.Remove(a); BrickContact((SuperBrick)b); CheckVictory(); } if (a.Name == "Кирпич" && b.Name == "Шарик") { SuperBall Ball = (SuperBall)b; Ball.top_step *= -1; BrickContact((SuperBrick)a); CheckVictory(); } if (a.Name == "Шарик" && b.Name == "Кирпич") { SuperBall Ball = (SuperBall)a; Ball.top_step *= -1; BrickContact((SuperBrick)b); CheckVictory(); } }
//Создание шариков при старте private void стартToolStripMenuItem_Click(object sender, EventArgs e) { if (timer.Enabled) { return; } if (first_start) { first_start = false; } else { foreach (SuperBrick a in bricks) { a.Dispose(); } bricks.Clear(); CreateBreacks(); } for (int i = 0; i < count_balls; i++) { SuperBall ball = new SuperBall( matilda1, "4_ball.png", ClientRectangle.Width / 2 - size_ball / 2, ClientRectangle.Height / 2 - size_ball / 2, size_ball, size_ball, "Шарик"); int offset = matilda1.RandomInt(1, start_speed); int route = matilda1.RandomInt(0, 1); if (route == 0) { ball.left_step = offset; ball.top_step = start_speed * 2 - offset; } else { ball.top_step = offset; ball.left_step = start_speed * 2 - offset; } /* * ball.left_step = matilda1.RandomInt(-27, 27); * ball.top_step = matilda1.RandomInt(-27, 27);*/ balls.Add(ball); } iSecond = 0; label1.Text = iSecond.ToString(); iLevel = 1; label4.Text = iLevel.ToString(); tSecond.Start(); tLevel.Start(); lStopGame.Hide(); timer.Start(); }
private void timer1_Tick(object sender, EventArgs e) { // Запускаем цикл с перемещением шариков for (int i = balls.Count - 1; i >= 0; i--) { SuperBall ball = balls[i]; ball.Top += ball.top_step; if (ball.Top <= menuStrip1.Height) { ball.top_step = -ball.top_step; } if (ball.Top > ClientRectangle.Height - ball.Height + 5) // на 5px увеличил, так как если долго играть, то шаг станет очень большим, и при условии отбивания о дощечку все равно шарик может вылететь за границы экрана { ball.Dispose(); balls.RemoveAt(i); if (balls.Count <= 0) { StopGame("СТОП ИГРА", Color.Black); break; } } ball.Left += ball.left_step; if (ball.Left <= 0) { ball.left_step = -ball.left_step; } if (ball.Left >= ClientRectangle.Width - ball.Width) { ball.left_step = -ball.left_step; } } for (int i = fireballs_pack.Count - 1; i >= 0; i--) { fireballs_pack[i].Top += speed_bonuses; if (fireballs_pack[i].Top >= ClientRectangle.Height - fireballs_pack[i].Height) { fireballs_pack[i].Dispose(); fireballs_pack.RemoveAt(i); } } for (int i = bullets.Count - 1; i >= 0; i--) { bullets[i].Top -= speed_bonuses; if (bullets[i].Top <= menuStrip1.Height) { bullets[i].Dispose(); bullets.RemoveAt(i); } } }