public bool collideBrick(brick brick) { if (brick.alive) { Rectangle r1 = new Rectangle(brick.x, brick.y, brick.size.Width, brick.size.Height); Rectangle r2 = new Rectangle((int)x, (int)y, size.Width, size.Height); if (r1.IntersectsWith(r2)) { return true; } } return false; }
public void room_init(int level_file) { //CLEAN UP VARIABLES game_started = false; won = false; lost = false; level_done = false; level_fail = false; room_time = 0; remaining_balls = 3; bricks = new List<brick>(); move_left = false; move_left = false; //INITIALIZE PLAYER player.x = room.Width / 2 - player.size.Width / 2; player.y = room.Height - player.size.Height - 64; //INITIALIZE BALL ball.x = player.x; ball.y = player.y - player.size.Height / 2 - ball.size.Height / 2; add_ball(); //LOADING LEVEL BRICKS LAYOUT string file = "data/level" + level_file + ".hs"; //KILL ON ERROR if (!File.Exists(file)) { MessageBox.Show("Error: Can´t load!\nReason: Missing level file(s)!"); main.Close(); } else { StreamReader sr = new StreamReader(file); string line1 = null; string line2 = null; string line3 = null; while (!sr.EndOfStream) { brick b = new brick(); b.alive = true; line1 = sr.ReadLine(); line2 = sr.ReadLine(); line3 = sr.ReadLine(); if (line1[0] != '#' || line2[0] != '#' || line3[0] != '#') { b.x = Convert.ToInt32(line1); b.y = Convert.ToInt32(line2); b.type = Convert.ToInt32(line3); if (b.type == 0) { b.value = 1; b.size = new Size(32, 16); //minimum size = 8x8 } if (b.type == 1) { b.value = 3; b.size = new Size(16, 8); //minimum size = 8x8 } b.alive = true; bricks.Add(b); } } player_msg = level_name = line1.Replace("#", ""); player_msg_time = 1; player_msg_speed = 0.01; bonus_time = Convert.ToInt32(line2.Replace("#", "")); sr.Close(); } //RIGHT PANEL DRAW - BEGIN right_paint.Clear(Color.Black); right_paint.DrawRectangle(p1, 6, 10, 86, 36); right_paint.DrawRectangle(p1, 6, 50, 86, 36); if (level_name.Length > 8) right_paint.DrawString("Level name\n" + level_name.Substring(0, 8) + "...", f1, b2, new PointF(10, 10)); else right_paint.DrawString("Level name\n" + level_name, f1, b2, new PointF(10, 10)); right_paint.DrawString("Level ID\n" + level + " / " + levels, f1, b2, new PointF(10, 50)); right_pnl.Image = right_img; //RIGHT PANEL DRAW - END }