I am learning to code and I have been working on a game using what I have learned to make it. So I have been making my version of R type C# game and got everything working so far but I run out of ideas how to make this part of the game work.
I wanted to make the boss appear after 5 min of game play and have the smaller opponents disappear. The boss was going to bounce around the screen like a Windows screen saver till the player destroys it (I know how to do that part since I made a pyame do that). The problem is that I can't figure out how to make the boss disappear till the 5min mark and then reappear.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace game
{
public partial class Game : Form
{
public Game()
{
InitializeComponent();
}
bool right, left, up, down, space, A;
//int Plives = 3;//player lives in game
int score;
int p = 0;
int i = 0;
playerclass pc = new playerclass();
int miss = 10;//number of missiles
void start()
{
lblgameover.Visible = false;
powerarmour.Visible = false;
}
void Lives()
{
if (pc.Plives > 0)
pc.Plives -=1;
if (pc.Plives == 3)
{
life1.Visible = true;
life2.Visible = true;
life3.Visible = true;
}
else if (pc.Plives == 2)
{
life1.Visible = false;
life2.Visible = true;
life3.Visible = true;
}
else if (pc.Plives == 1)
{
life1.Visible = false;
life2.Visible = false;
life3.Visible = true;
}
else if (pc.Plives == 0)
{
life1.Visible = false;
life2.Visible = false;
life3.Visible = false;
}
}
void Health()
{
Random hpup = new Random();
i++;
int hp;
healthup.Left -= 8;
if (i == 100 && healthup.Left < 0)
{
hp = hpup.Next(50, 500);
healthup.Location = new Point(1200, hp);
// if (healthup.Left < 0)
}
if (i == 500)
i = 0;
}
void HitorMiss()
{
foreach (Control j in this.Controls)
{
foreach (Control i in this.Controls)
{
if (j is PictureBox && j.Tag == "shot" || j is PictureBox && j.Tag == "missile")
{
if (i is PictureBox && i.Tag == "enemies")
{
if (j.Bounds.IntersectsWith(i.Bounds))
{
}
}
}
}
}
if (Player.Bounds.IntersectsWith(e1.Bounds) || Player.Bounds.IntersectsWith(e1laser.Bounds) || Player.Bounds.IntersectsWith(e2.Bounds) || Player.Bounds.IntersectsWith(e2laser.Bounds) || Player.Bounds.IntersectsWith(e3.Bounds) || Player.Bounds.IntersectsWith(e3laser.Bounds))
{
if (healthbar.Value <= 0)
{
Lives();
}
if (pc.Plives == 0)
{
timer1.Stop();
lblgameover.Visible = true;
lblgameover.Text = "Game over";
PictureBox bullet = new PictureBox();
bullet.SizeMode = PictureBoxSizeMode.AutoSize;
bullet.Image = Properties.Resources.Shoot;
bullet.BackColor = System.Drawing.Color.Transparent;
((PictureBox)Player).Image = Properties.Resources.explosion;
}
else
healthbar.Value -= 10;
}
if (Player.Bounds.IntersectsWith(healthup.Bounds))
{
if (healthbar.Value <= 90)
{
healthbar.Value += 10;
}
}
}
void BossShoot()
{
e4laser.Left -= 50;
e5laser.Left -= 50;
if (e4laser.Left < 0 || e4laser.Left < 0)
{
e4laser.Left = powerarmour.Left;
e4laser.Top = powerarmour.Top + 25;
e5laser.Left = powerarmour.Left;
e5laser.Top = powerarmour.Top + 60;
}
}
private int _bossTimerIntervalMins => 5;
void Boss()
{
var bossTimer = new System.Timers.Timer();
bossTimer.Start();
//
e4laser.Visible = false;
e5laser.Visible = false;
powerarmour.Visible = false;
//
bossTimer.Interval = _bossTimerIntervalMins * 60 * 1000;
bossTimer.Elapsed += timer1_Tick;
powerarmour.Visible = true;
e4laser.Visible = true;
e5laser.Visible = true;
}
void Playermovement()
{
if (right == true)
{
if (Player.Left < 900)
{
Player.Left += 20;
}
}
if (left == true)
{
if (Player.Left > 5)
{
Player.Left -= 15;
}
}
if (up == true)
{
if (Player.Top > 20)
{
Player.Top -= 20;
}
}
if (down == true)
{
if (Player.Top < 550)
{
Player.Top += 20;
}
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
right = true;
}
if (e.KeyCode == Keys.Left)
{
left = true;
}
if (e.KeyCode == Keys.Up)
{
up = true;
}
if (e.KeyCode == Keys.Down)
{
down = true;
}
if (e.KeyCode == Keys.Space)
{
space = true;
Shot();
}
if (e.KeyCode == Keys.A)
{
if (nomissiles.Value >= 10)
{
miss--;
nomissiles.Value -= 10;
A = true;
Missile();
}
}
}
void Missile()
{
PictureBox m = new PictureBox();
m.SizeMode = PictureBoxSizeMode.AutoSize;
m.Image = Properties.Resources.Missile1;
m.BackColor = System.Drawing.Color.Transparent;
m.Tag = "missile";
m.Left = Player.Left + 100;//moves bullet left or right
m.Top = Player.Top + 55;//55 is perfect
this.Controls.Add(m);
m.BringToFront();
}
void movemissile()
{
foreach (Control y in this.Controls)
{
if (y is PictureBox && y.Tag == "missile")
{
y.Left += 100;//x.Top -= 10;
if (y.Top > 900)//<100
{
this.Controls.Remove(y);
}
}
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
right = false;
}
if (e.KeyCode == Keys.Left)
{
left = false;
}
if (e.KeyCode == Keys.Up)
{
up = false;
}
if (e.KeyCode == Keys.Down)
{
down = false;
}
if (e.KeyCode == Keys.Space)
{
space = false;
}
if (e.KeyCode == Keys.A)
{
A = false;
}
}
void Shot()//positions where players laser shows on the screen
{
PictureBox ammo = new PictureBox();
ammo.SizeMode = PictureBoxSizeMode.AutoSize;
ammo.Image = Properties.Resources.Shoot;
ammo.BackColor = System.Drawing.Color.Transparent;
ammo.Tag = "shot";
ammo.Left = Player.Left + 100;//moves bullet left or right
ammo.Top = Player.Top + 55;//55 is perfect
this.Controls.Add(ammo);
ammo.BringToFront();
}
void MoveShot()
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "shot")
{
x.Left += 100;//x.Top -= 10;
if (x.Top > 900)//<100
{
this.Controls.Remove(x);
}
}
}
e1laser.Left -= 30;
if (e1laser.Left < 0)
{
e1laser.Left = e1.Left;
e1laser.Top = e1.Top + 25;
}
e2laser.Left -= 30;
if (e2laser.Left < 0)
{
e2laser.Left = e2.Left;
e2laser.Top = e2.Top + 25;
}
e3laser.Left -= 30;
if (e3laser.Left < 0)
{
e3laser.Left = e3.Left;
e3laser.Top = e3.Top + 25;
}
}
void Enemies_move()
{
int a, b, c;
Random rnd = new Random();
e1.Left -= 15;
if (e1.Left < 0)
{
a = rnd.Next(30, 560);
e1.Location = new Point(1200, a);
}
//
e2.Left -= 15;
if (e2.Left < 0)
{
b = rnd.Next(30, 560);
e2.Location = new Point(1200, b);
}
e3.Left -= 15;
if (e3.Left < 0)
{
c = rnd.Next(30, 560);
e3.Location = new Point(1200, c);
}
}
private void Game_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
start();
Boss();
Health();
MoveShot();
Playermovement();
Enemies_move();
HitorMiss();
movemissile();
}
}
}