winterz
automatic restart game
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 flappy_bird_windows_form
{
public partial class Form1 : Form
{
int pipeSpeed = 8;
int gravity = 10;
int score = 0;
public Form1()
{
InitializeComponent();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
}
private void gameTimerEvent(object sender, EventArgs e)
{
flappyBird.Top += gravity;
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
scoreText.Text = "score: " + score;
if(pipeBottom.Left < -100)
{
pipeBottom.Left = 500;
score++;
}
if(pipeTop.Left < -130 )
{
pipeTop.Left = 650;
score++;
}
if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25
)
{
endGame();
}
}
private void gamekeyisdown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Space)
{
gravity = -10; }
}
private void gamekeyisup(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
gravity = 10;
}
}
private void endGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";
}
}
}
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 flappy_bird_windows_form
{
public partial class Form1 : Form
{
int pipeSpeed = 8;
int gravity = 10;
int score = 0;
public Form1()
{
InitializeComponent();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
}
private void gameTimerEvent(object sender, EventArgs e)
{
flappyBird.Top += gravity;
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
scoreText.Text = "score: " + score;
if(pipeBottom.Left < -100)
{
pipeBottom.Left = 500;
score++;
}
if(pipeTop.Left < -130 )
{
pipeTop.Left = 650;
score++;
}
if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25
)
{
endGame();
}
}
private void gamekeyisdown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Space)
{
gravity = -10; }
}
private void gamekeyisup(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
gravity = 10;
}
}
private void endGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";
}
}
}
8 replies