手把手教你用C#制作RPG游戏初始化代码


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 RPG
{
public partial class Form1 : Form
{
public int a = 0;
public Form1()
{
InitializeComponent();
this.BackgroundImage = Image.FromFile("backimage.jpg");
BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
Draw();
}
private void Draw()
{
Bitmap bp = new Bitmap(@"IMG/面向0.png");
// bp.SetResolution(96,96);
Image img = Image.FromHbitmap(bp.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
// Graphics g = pictureBox1.CreateGraphics();
// g.DrawImage(bp,100,100,20,20);
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
int step = 10;
if (e.KeyCode == Keys.Up)
{
Bitmap bp = new Bitmap(@"IMG/背向" a ".png");
// bp.SetResolution(96,96);
Image img = Image.FromHbitmap(bp.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img;
a ;
if (a == 3)
{
a = 0;
}
Point p= new Point(this.pictureBox1.Location.X, this.pictureBox1.Location.Y- step);
this.pictureBox1.Location = p;
}
else if (e.KeyCode == Keys.Left)
{
Bitmap bp = new Bitmap(@"IMG/左向" a ".png");
// bp.SetResolution(96,96);
Image img = Image.FromHbitmap(bp.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img;
a ;
if (a == 3)
{
a = 0;
}
Point p = new Point(this.pictureBox1.Location.X- step, this.pictureBox1.Location.Y );
this.pictureBox1.Location = p;
}
else if (e.KeyCode == Keys.Down)
{
Bitmap bp = new Bitmap(@"IMG/面向" a ".png");
// bp.SetResolution(96,96);
Image img = Image.FromHbitmap(bp.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img;
a ;
if (a == 3)
{
a = 0;
}
Point p = new Point(this.pictureBox1.Location.X, this.pictureBox1.Location.Y step);
this.pictureBox1.Location = p;
}
else if (e.KeyCode == Keys.Right)
{
Bitmap bp = new Bitmap(@"IMG/右向" a ".png");
// bp.SetResolution(96,96);
Image img = Image.FromHbitmap(bp.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img;
a ;
if (a == 3)
{
a = 0;
}
Point p = new Point(this.pictureBox1.Location.X step, this.pictureBox1.Location.Y);
this.pictureBox1.Location = p;
}
}
}
}
资源文件列表
.vs/RPG/v16/.suo , 19456
.vs/RPG/v16/Server/sqlite3/db.lock , 0
.vs/RPG/v16/Server/sqlite3/storage.ide , 577536
App.config , 189
Form1.Designer.cs , 2235
Form1.cs , 3639
Form1.resx , 5817
IMG/╙╥╧≥0.png , 11082
IMG/╙╥╧≥1.png , 11769
IMG/╙╥╧≥2.png , 11861
IMG/╫≤╧≥0.png , 10741
IMG/╫≤╧≥1.png , 11913
IMG/╫≤╧≥2.png , 12347
IMG/▒│╧≥0.png , 10347
IMG/▒│╧≥1.png , 9674
IMG/▒│╧≥2.png , 10645
IMG/├µ╧≥0.png , 10810
IMG/├µ╧≥1.png , 10027
IMG/├µ╧≥2.png , 10538
Program.cs , 515
Properties/AssemblyInfo.cs , 1314
Properties/Resources.Designer.cs , 2819
Properties/Resources.resx , 5612
Properties/Settings.Designer.cs , 1090
Properties/Settings.settings , 249
RPG.csproj , 5578
RPG.sln , 1110
backimage.jpg , 48337
bin/Debug/IMG/╙╥╧≥0.png , 11082
bin/Debug/IMG/╙╥╧≥1.png , 11769
bin/Debug/IMG/╙╥╧≥2.png , 11861
bin/Debug/IMG/╫≤╧≥0.png , 10741
bin/Debug/IMG/╫≤╧≥1.png , 11913
bin/Debug/IMG/╫≤╧≥2.png , 12347
bin/Debug/IMG/▒│╧≥0.png , 10347
bin/Debug/IMG/▒│╧≥1.png , 9674
bin/Debug/IMG/▒│╧≥2.png , 10645
bin/Debug/IMG/├µ╧≥0.png , 10810
bin/Debug/IMG/├µ╧≥1.png , 10027
bin/Debug/IMG/├µ╧≥2.png , 10538
bin/Debug/RPG.exe , 9216
bin/Debug/RPG.exe.config , 189
bin/Debug/RPG.pdb , 24064
bin/Debug/RPG.vshost.exe , 22696
bin/Debug/RPG.vshost.exe.config , 189
bin/Debug/RPG.vshost.exe.manifest , 490
bin/Debug/backimage.jpg , 48337
bin/Debug/role.png , 10810
obj/Debug/DesignTimeResolveAssemblyReferences.cache , 823
obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 8253
obj/Debug/RPG.Form1.resources , 180
obj/Debug/RPG.Properties.Resources.resources , 180
obj/Debug/RPG.csproj.FileListAbsolute.txt , 2597
obj/Debug/RPG.csproj.GenerateResource.cache , 1012
obj/Debug/RPG.csprojAssemblyReference.cache , 424
obj/Debug/RPG.csprojResolveAssemblyReference.cache , 2384
obj/Debug/RPG.exe , 9216
obj/Debug/RPG.pdb , 24064
obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs , 0
obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs , 0
obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs , 0
role.png , 10810
