well I am working on a space invaders like game. I am using c# and gdi+. I have managed to draw a space ship and have it shoot a bullet, I am just starting. here is my starting code.
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;
using System.Drawing.Imaging;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
}
int x = 0, y = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Left)
{
x-=5;
if(x<=-350)
{
x = -350;
}
}
if(e.KeyCode == Keys.Right)
{
x+=5;
if(x>=375)
{
x = 375;
}
}
if (e.KeyCode == Keys.Space)
{
for(int i=0; i<5;i++)
{
y -= 5;
}
if (y <= -530)
{
y = 0;
}
}
Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap ship = new Bitmap("ship.bmp", true);
Bitmap bullet = new Bitmap("bullet.bmp", true);
Graphics g1 = this.CreateGraphics();
g1.DrawImage(ship, 350+x, 530);
g1.DrawImage(bullet, 375, 520 + y);
g1.Dispose();
}
}
}
well everything works except that the bug flickers. here is my code.