private void GameScreen_Paint(object sender, PaintEventArgs e) { SolidBrush g = new SolidBrush(Color.Green); SolidBrush b = new SolidBrush(Color.SkyBlue); e.Graphics.FillRectangle(g, 0, this.Height - 100, this.Width, 100); e.Graphics.FillRectangle(b, 0, 0, this.Width, this.Height - 100); e.Graphics.DrawRectangle(new Pen(Color.Black), cloudX, 50, 100, 50); if (!started) { Font s = new Font(Font.FontFamily, 20); e.Graphics.DrawString("Press Space to Play!", s, new SolidBrush(Color.Black), (this.Width - 300) / 2, 100); } if (!up && !grounded) { frame = 9; } if (up && curntMech != "superJump") { frame = 8; } if (grounded && !up && tick % 4 == 0) { frame++; } if (curntMech == "superJump" && tick % 4 == 0) { frame++; } if (endGame) { frame = 10; } switch (curntMech) { case "none": frameCount = gifImage.GetFrameCount(dimension); if (frame >= 8 && grounded && !up && !endGame) { frame = 0; } e.Graphics.DrawImage(gifImage, player.hb); gifImage.SelectActiveFrame(dimension, frame); break; case "teleporter": e.Graphics.DrawImage(Properties.Resources.teleporter, player.hb.X, player.hb.Y); break; case "superJump": frameCount = spImage.GetFrameCount(dimension); if (frame >= 8 && !endGame) { frame = 0; } e.Graphics.DrawImage(spImage, player.x, player.y); spImage.SelectActiveFrame(spdimension, frame); break; case "gravity": frameCount = gImage.GetFrameCount(dimension); if (frame >= 8 && grounded && !up && !endGame) { frame = 0; } e.Graphics.DrawImage(gImage, player.x, player.y); gImage.SelectActiveFrame(gdimension, frame); break; } if (curntMech == "teleporter") { teleporterDraw(e.Graphics, teleporterMarkerY); } foreach (Classes.rocket l in rockets) { if (l.launchingRocket && l.launchingTicks < 180) { l.launchingTicks++; l.hb.Y = player.y + 25; l.y = player.y + 25; e.Graphics.DrawImage(l.i, l.hb); } if (l.launchingTicks == 180 && l.launchingRocket) { l.hb.Y = player.y + 25; l.y = player.y + 25; l.launchingRocket = false; } if (!l.launchingRocket) { l.move(); e.Graphics.DrawImage(l.i, l.hb); if (l.hb.Right <= 0) { rocketToRemove = l; } if (player.hb.IntersectsWith(l.hb)) { //GameOver(); if (!endGame && curntMech == "none") { endGame = true; death.Stop(); death.Play(); spdStorage = backgroundMoveSpd; bounce = (this.Height - player.y) / 2; } else if (curntMech != "none") { broken.Stop(); broken.Play(); toClearLsers = true; grounded = false; curntMech = "none"; } } } } foreach (Classes.laser l in lasers) { l.move(); e.Graphics.DrawImage(l.i, l.hb); if (l.hb.Right <= 0) { laserToRemove = l; } if (player.hb.IntersectsWith(l.hb)) { //GameOver(); if (!endGame && curntMech == "none") { death.Stop(); death.Play(); spdStorage = backgroundMoveSpd; endGame = true; bounce = (this.Height - player.y) / 2; } else if (curntMech != "none") { broken.Stop(); broken.Play(); toClearLsers = true; grounded = false; curntMech = "none"; } } } if (toClearLsers) { lasers.Clear(); rockets.Clear(); toClearLsers = false; } List <Classes.coin> delete = new List <Classes.coin>(); foreach (Classes.coin c in coins) { if (c.hb.IntersectsWith(player.hb)) { coinScore++; //coinToRemove = c; delete.Add(c); } else { c.move(); e.Graphics.FillEllipse(coinBrush, c.hb); if (c.hb.Right <= 0) { //coinToRemove = c; delete.Add(c); } } } foreach (Classes.mechToken m in MTokens) { if (m.hb.IntersectsWith(player.hb)) { MTokenToRemove = m; curntMech = m.type; lasers.Clear(); rockets.Clear(); broken.Play(); } else { m.move(); e.Graphics.FillRectangle(coinBrush, m.hb); if (m.hb.Right <= 0) { MTokenToRemove = m; } } if (upgrades["xray"]) { string s = ""; Font f = new Font(Font.FontFamily, 20); if (m.type == "teleporter") { s = "T"; } else if (m.type == "superJump") { s = "S"; } else if (m.type == "gravity") { s = "G"; } e.Graphics.DrawString(s, f, new SolidBrush(Color.Black), m.hb.X + 10, m.hb.Y + 10); } } Font fr = new Font("Arial", 16); e.Graphics.DrawString("Coins " + coinScore, fr, new SolidBrush(Color.Black), 0, 10); e.Graphics.DrawString("Distance " + actualDist + "m", fr, new SolidBrush(Color.Black), 0, 30); RemoveLaser(laserToRemove); RemoveCoin(delete); RemoveMToken(MTokenToRemove); MTokenToRemove = null; coinToRemove = null; laserToRemove = null; }
public void RemoveCoin(Classes.coin l) { coins.Remove(l); }
private void GameScreen_Paint(object sender, PaintEventArgs e) { if (!started) { Font s = new Font(Font.FontFamily, 20); e.Graphics.DrawString("Press Space to Play!", s, new SolidBrush(Color.White), (this.Width - 300) / 2, 100); } switch (curntMech) { case "none": //e.Graphics.DrawRectangle(playerPen, player.hb); break; case "teleporter": break; case "superJump": break; case "gravity": break; } e.Graphics.DrawRectangle(playerPen, player.hb); if (curntMech == "teleporter") { teleporterDraw(e.Graphics, teleporterMarkerY); } foreach (Classes.rocket l in rockets) { if (l.launchingRocket && l.launchingTicks < 180) { l.launchingTicks++; e.Graphics.DrawRectangle(new Pen(Color.White), this.Width - 30, player.hb.Top + 25, 30, 25); } if (l.launchingTicks == 180 && l.launchingRocket) { l.hb.Y = player.y + 25; l.y = player.y + 25; l.launchingRocket = false; } if (!l.launchingRocket) { l.move(); e.Graphics.DrawRectangle(playerPen, l.hb); if (l.hb.Right <= 0) { rocketToRemove = l; } if (player.hb.IntersectsWith(l.hb)) { //GameOver(); if (!endGame && curntMech == "none") { endGame = true; spdStorage = backgroundMoveSpd; bounce = (this.Height - player.y) / 2; } else if (curntMech != "none") { toClearLsers = true; grounded = false; curntMech = "none"; } } } } foreach (Classes.laser l in lasers) { l.move(); e.Graphics.DrawRectangle(playerPen, l.hb); if (l.hb.Right <= 0) { laserToRemove = l; } if (player.hb.IntersectsWith(l.hb)) { //GameOver(); if (!endGame && curntMech == "none") { spdStorage = backgroundMoveSpd; endGame = true; bounce = (this.Height - player.y) / 2; } else if (curntMech != "none") { toClearLsers = true; grounded = false; curntMech = "none"; } } } if (toClearLsers) { lasers.Clear(); rockets.Clear(); toClearLsers = false; } List <Classes.coin> delete = new List <Classes.coin>(); foreach (Classes.coin c in coins) { if (c.hb.IntersectsWith(player.hb)) { coinScore++; //coinToRemove = c; delete.Add(c); } else { c.move(); e.Graphics.FillEllipse(coinBrush, c.hb); if (c.hb.Right <= 0) { //coinToRemove = c; delete.Add(c); } } } foreach (Classes.mechToken m in MTokens) { if (m.hb.IntersectsWith(player.hb)) { MTokenToRemove = m; curntMech = m.type; lasers.Clear(); rockets.Clear(); } else { m.move(); e.Graphics.FillRectangle(coinBrush, m.hb); if (m.hb.Right <= 0) { MTokenToRemove = m; } } if (upgrades["xray"]) { string s = ""; Font f = new Font(Font.FontFamily, 20); if (m.type == "teleporter") { s = "T"; } else if (m.type == "superJump") { s = "S"; } else if (m.type == "gravity") { s = "G"; } e.Graphics.DrawString(s, f, new SolidBrush(Color.Black), m.hb.X + 10, m.hb.Y + 10); } } e.Graphics.DrawString("Coins " + coinScore, Font, new SolidBrush(Color.White), 0, 10); e.Graphics.DrawString("Distance " + actualDist, Font, new SolidBrush(Color.White), 0, 20); RemoveLaser(laserToRemove); RemoveCoin(delete); RemoveMToken(MTokenToRemove); MTokenToRemove = null; coinToRemove = null; laserToRemove = null; }