C#人物動畫(跑,轉,蹲,大招)
C#人物動畫(跑,轉,蹲,大招)
C#人物動畫(跑,轉,蹲,大招)
C#人物動畫(跑,轉,蹲,大招) 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 人物動畫
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int indexs=0;
Timer zou = new Timer();
Timer stand = new Timer();
Timer dun = new Timer();
Timer zhuan = new Timer();
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[0];
//站
stand.Interval = 150;
stand.Tick += Stand_Tick;
stand.Start();
this.KeyDown += Form1_KeyDown;
//走
zou.Interval = 200;
zou.Tick += Zou_Tick;
//蹲
dun.Interval = 100;
dun.Tick += Dun_Tick;
//轉
zhuan.Interval = 100;
zhuan.Tick += Zhuan_Tick;
this.KeyUp += Form1_KeyUp;
this.KeyPress += Form1_KeyPress;
}
int indean = 0;
private void Zhuan_Tick(object sender, EventArgs e)
{
pictureBox1.Image = imageList5.Images[indean];
indean++;
if (indean>=imageList5.Images.Count)
{
indean = 0;
stand.Start();
}
}
int indexd = 0;
private void Dun_Tick(object sender, EventArgs e)
{
pictureBox1.Image = imageList4.Images[indexd];
indexd++;
if (indexd>=imageList4.Images.Count)
{
stand.Start();
indexd = 0;
}
}
Random r = new Random();
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString()=="q")
{
PictureBox picture = new PictureBox();
picture.Size = new Size(70, 70);
picture.SizeMode = PictureBoxSizeMode.StretchImage;
picture.Left = pictureBox1.Left - 140;
picture.Top = r.Next(0, this.Height - 80);
this.Controls.Add(picture);
picture.Tag = 0;
Timer wuq = new Timer();
wuq.Interval = 70;
wuq.Tag = picture;
wuq.Tick += Wuq_Tick;
wuq.Start();
}
if (e.KeyChar.ToString()=="d")
{
stand.Stop();
dun.Start();
}
if (e.KeyChar.ToString()=="z")
{
stand.Stop();
zhuan.Start();
}
}
private void Wuq_Tick(object sender, EventArgs e)
{
Timer time = sender as Timer;
PictureBox box = time.Tag as PictureBox;
box.Left -= 1;
int index = (int)box.Tag;
box.Image = imageList3.Images[index];
index += 1;
box.Tag = index;
if (index>=imageList3.Images.Count)
{
time.Dispose();
box.Dispose();
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
zou.Stop();
stand.Start();
dun.Stop();
zhuan.Stop();
}
int indexz = 0;
private void Zou_Tick(object sender, EventArgs e)
{
pictureBox1.Image = imageList2.Images[indexz];
indexz++;
if (indexz>=imageList2.Images.Count)
{
indexz = 0;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Left)
{
pictureBox1.Left -= 1;
stand.Stop();
zou.Start();
}
}
private void Stand_Tick(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[indexs];
indexs++;
if (indexs>=imageList1.Images.Count)
{
indexs = 0;
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}