技能表现

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Test01
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
FrameTimer.Interval = Common.UPDATE_INTERVAL;

buttonStateList.Capacity = Keys.D9 - Keys.D0;
for (int i = 0; i < buttonStateList.Capacity; ++i )
{
buttonStateList.Add(0);
}

gs = Graphics.FromImage(bmp);
gs.SmoothingMode = SmoothingMode.AntiAlias;
}
static Graphics gs;
Bitmap bmp = new Bitmap(3000,3000);

private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
if (Keys.D1 <= e.KeyCode && e.KeyCode <= Keys.D9)
{
buttonStateList[e.KeyCode - Keys.D1] = 1;
}
}
private void FrameTimer_Tick(object sender, EventArgs e)
{
this.OnFrame();
List<Unit> unitlist = BattleField.Instance.unitList;
gs.Clear(Color.White);
sx = -1;
foreach (Unit unit in unitlist)
{
sx++;
if (!unit.IsAlive()) continue;
Vec2i points = unit.GetPosProp().getPos();
drs(unit,800+points.x, points.y-440);

}
this.CreateGraphics().DrawImage(bmp, 0, 0);
}

void OnFrame()
{
for (int i = 0; i < buttonStateList.Count; ++i)
{
RenderLayerCmd cmd = new RenderLayerCmd();
if (buttonStateList[i] > 0)
{
if (i < 5)
{
cmd.cmd = CmdType.SKILL;
cmd.unitId = BattleField.Instance.unitList[i].guid;
AppEntrance.PushCommand(cmd);
}
else
{
switch (i + 1)
{
case 7:
cmd.cmd = CmdType.PAUSE;
AppEntrance.PushCommand(cmd);
break;
case 8:
cmd.cmd = CmdType.RESUME;
AppEntrance.PushCommand(cmd);
break;
case 9:
cmd.cmd = CmdType.NEXT_REGION;
AppEntrance.PushCommand(cmd);
break;
}
}

buttonStateList[i] = 0;
}
}

AppEntrance.Update();
}

List<int> buttonStateList = new List<int>();
public delegate void drawPos(Unit unit,int x,int y);
private static int sx=0;
private static int buffi = 0;
public static drawPos drs = new drawPos(delegate(Unit unit,int x, int y)
{
string id = unit.unitConfig.name;
int a = unit.GetTeamId() % 2;
int hp = unit.fightingProperty.getValue(PropertyType.HP), mp = unit.fightingProperty.getValue(PropertyType.MP);
Brush s=System.Drawing.Brushes.Red;
Pen p = new Pen(s);
if (a == 0) { s = System.Drawing.Brushes.Blue; p = new Pen(s); a = -3; }
if (unit.enemy != null&&unit.enemy.IsAlive())
{

p.EndCap = LineCap.ArrowAnchor;
Point p1 = new Point(unit.GetPosProp().getPos().x/4+20+a, unit.GetPosProp().getPos().y/4-70+a);
Point p2 = new Point(unit.enemy.GetPosProp().getPos().x/4+20+a, unit.enemy.GetPosProp().getPos().y/4-70+a);
if (unit.ai.aiState == AIState.SKILL_CASTING)
{
gs.DrawLine(p, p1, p2);
}
}
foreach(Buff buff in unit.buffList.dataList)
{
Random ran =new Random((int)(buff.type)*171271);
Color color = Color.FromArgb(ran.Next(0, 255), ran.Next(0, 255), ran.Next(0, 255));
Brush sd = new SolidBrush(color);
gs.DrawString("★", new Font("黑体", 6), sd, new PointF(x / 4 - 200+buffi*6, y / 4 + 74));
buffi++;
gs.DrawString(buff.type.ToString(), new Font("宋体", 8), sd, new PointF(700 + sx * 160 - sx / 5 * 800, 52 - buffi * 10 + sx / 5 * 350));
}
buffi = 0;
gs.DrawString("☠", new Font("黑体", 16), s, new PointF(x / 4 - 200, y / 4 + 30));
gs.DrawString(unit.fightingProperty.getValue(PropertyType.DAMAGE).ToString(), new Font("黑体", 8), s, new PointF(x / 4 - 180, y / 4 + 32));
gs.DrawString(hp.ToString()+","+mp.ToString() , new Font("宋体", 8), s, new PointF(x / 4 - 200, y / 4 + 65));
gs.DrawString(id, new Font("宋体", 8), s, new PointF(x / 4 - 180, y / 4+46));
gs.DrawString( x.ToString() + "," + y.ToString(), new Font("宋体", 8), s, new PointF(x / 4-200, y / 4+54));

bool t = true;
for (int j = 0; j < (int)PropertyType.END; j++)
{
if (unit.fightingProperty.getValue((PropertyType)j) != zu[sx,j])
{
if ((PropertyType)j==PropertyType.HP)
cha[sx,j] = unit.fightingProperty.getValue((PropertyType)j) - zu[sx,j];
zu[sx,j] = unit.fightingProperty.getValue((PropertyType)j);
}
if (t) { t = false; gs.DrawString(id, new Font("宋体", 8), s, new PointF(700 + sx * 160 - sx / 5 * 800, 52 + j * 10 + sx / 5 * 350)); }
gs.DrawString(((PropertyType)j).ToString() + ":" + zu[sx,j]+"("+cha[sx,j]+")",
new Font("宋体", 8),s, new PointF(700+sx*160-sx/5*800, 60 + j * 10+sx/5*350));
}
});
public static int[,] zu = new int[20,(int)PropertyType.END];
public static int[,] cha = new int[20,(int)PropertyType.END];
public Dictionary<int, int> notifyProperty = new Dictionary<int, int>();
private void MainForm_Load(object sender, EventArgs e)
{

}

private void MainForm_Paint(object sender, PaintEventArgs e)
{

}

private void MainForm_MouseDoubleClick(object sender, MouseEventArgs e)
{
Unit curunit;
Vec2i vec2i = new Vec2i(e.X,e.Y);
int mindist = int.MaxValue;

for (int i=0;i<BattleField.Instance.unitList.Count;i++)
{
int dist =vec2i.dist2(BattleField.Instance.unitList[i].GetPosProp().getPos());
if (dist<mindist)
{
mindist = dist;
curunit = BattleField.Instance.unitList[i];
}
}

}
}
}

原文地址:https://www.cnblogs.com/Asuphy/p/3983536.html