zoukankan      html  css  js  c++  java
  • 绘图部分

    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);
    ps = new Point(10000,10000);
    Matrix trans = new Matrix(1f,0,0,1f,0,0);
    gs.MultiplyTransform(trans);
    gs.SmoothingMode = SmoothingMode.AntiAlias;
    }
    static int tx = 0, ty =-600;
    static Graphics gs;
    static Point ps;
    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;
    ps.X = 10000; ps.Y = 10000;
    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(tx + unit.GetPosProp().getPos().x / 4 + 20 + a, ty + unit.GetPosProp().getPos().y / 4 - 70 + a);
    Point p2 = new Point(tx + unit.enemy.GetPosProp().getPos().x / 4 + 20 + a, ty + 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(tx+x / 4 - 200+buffi*6,ty+ y / 4 + 74));
    buffi++;
    //gs.TranslateTransform(-x, -y);
    gs.DrawString(buff.type.ToString(), new Font("宋体", 8), sd, new PointF( 700 + sx * 160 - sx / 5 * 800, 92 - buffi * 10 + sx / 5 * 400));
    //gs.TranslateTransform(x, y);
    }
    buffi = 0;
    //if ( ps.X > x / 4 - 200) ps.X = x / 4 - 200;
    //if ( ps.Y > y / 4 + 30) ps.X = y / 4 + 30;
    //tx = -ps.X + 100; ty = -ps.Y + 100;
    gs.DrawString("☠", new Font("黑体", 16), s, new PointF(tx + x / 4 - 200, ty + y / 4 + 30));
    gs.DrawString(unit.fightingProperty.getValue(PropertyType.DAMAGE).ToString(), new Font("黑体", 8), s, new PointF(tx + x / 4 - 180, ty + y / 4 + 32));
    gs.DrawString(hp.ToString() + "," + mp.ToString(), new Font("宋体", 8), s, new PointF(tx + x / 4 - 200, ty + y / 4 + 65));
    gs.DrawString(id, new Font("宋体", 8), s, new PointF(tx + x / 4 - 180, ty + y / 4 + 46));
    gs.DrawString(x.ToString() + "," + y.ToString(), new Font("宋体", 8), s, new PointF(tx + x / 4 - 200, ty + y / 4 + 54));
    foreach (Vec2i v in RevengeArrow.list)
    {
    gs.DrawString("*", new Font("黑体", 16), s, new PointF(tx + v.x / 4, ty + v.y / 4 - 80));
    }
    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,92 + j * 10 + sx / 5 * 400)); }
    gs.DrawString(((PropertyType)j).ToString() + ":" + zu[sx,j]+"("+cha[sx,j]+")",
    new Font("宋体", 8),s, new PointF(700+sx*160-sx/5*800, 100 + j * 10+sx/5*400));
    }

    });
    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];
    }
    }

    }
    }
    }

  • 相关阅读:
    C#操作ini配置文件和写入日志操作
    asp.net AJAX 定期刷新页面,然后,在 Timer 的事件中弹出窗口
    setInterval和setTimeout的区别
    检测远程URL是否存在
    SharePoint列表的模板类型中的BaseType参数和ListTemplate参数
    TCP中的Flag options
    jQuery基础教程摘录 Hello world
    SharePoint站点无法打开的问题
    SPQuery在引用field的时候要用internal name
    Windows Server 2008中用管理员的权限使用命令行来打开程序
  • 原文地址:https://www.cnblogs.com/Asuphy/p/4025961.html
Copyright © 2011-2022 走看看