当前位置:编程学习 > C#/ASP.NET >>

Point是如何定义图片的?

namespace MyGame
{
    public partial class LevelForm : Form
    {
        //定义怪物和玩家
        Hero hero;
        TurtleMonster monster;
        
        public LevelForm()
        {
            InitializeComponent();
        }
        private void LevelForm_Load(object sender, EventArgs e)
        {
            this.lblHeroBlood.Size = new Size(0, 20);
            this.lblMonsterBlood.Size = new Size(0, 20);

            this.lblHeroCurBlood.Size = new Size(0, 20);
            this.lblMonCurBlood.Size = new Size(0, 20);
            try
            {
                #region 阶段
                //实例化hero对象
                hero = new Hero();

                /////////设置玩家的属性值/////////////
                hero.HeroName = "李小侠";
                hero.OriginalBlood = 300;
                hero.AttackPower = 50;
                hero.DefendPower = 20;
                hero.Image = Image.FromFile("hero.gif");
                //设置原始位置
                hero.OriginalLocation = this.picHero.Location;
                //设置当前位置-初始状态与原始位置相同
                hero.CurrentLocation = this.picHero.Location;
                //设置玩家的大小
                hero.Size = this.picHero.Size;


                //将生命值显示到标签
                this.lblHeroBlood.Width = hero.OriginalBlood;
                this.lblHeroBlood.Height = 20;
                //用于显示受伤的标签
                this.lblHeroCurBlood.Width = hero.OriginalBlood;
                this.lblHeroCurBlood.Height = 20;
                //将图片显示到PictureBox
                this.picHero.Image = hero.Image;
                #endregion

                #region 阶段3
                //实例化怪物对象

                monster = new TurtleMonster("小龟", Image.FromFile("turtle.gif"), this.picMonster.Location, this.picMonster.Size);

                //monster.MonsterName = "小龟";
                //monster.OriginalBlood = 200;
                //monster.AttackPower = 50;
                //monster.DefendPower = 10;
                //monster.Image = Image.FromFile("turtle.gif");
                ////设置原始位置
                //monster.OriginalLocation = this.picMonster.Location;
                ////设置当前位置-初始状态与原始位置相同
                //monster.CurrentLocation = this.picMonster.Location;
                ////设置玩家的大小
                //monster.Size = this.picMonster.Size;


                //将生命值显示到标签
                this.lblMonsterBlood.Width = monster.OriginalBlood;
                this.lblMonsterBlood.Height = 20;
                this.lblMonCurBlood.Width = monster.OriginalBlood;
                this.lblMonCurBlood.Height = 20;
                //将图片显示到PictureBox
                this.picMonster.Image = monster.Image;
                #endregion

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void UpdateUI()
        {
            this.picMonster.Location = monster.CurrentLocation;
        }


        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnMonsterMove_Click(object sender, EventArgs e)
        {
            monster.Move(hero);
            UpdateUI();
        }

        private void btnMonsterReturn_Click(object sender, EventArgs e)
        {
            monster.Move();
            UpdateUI();
        }
    }
}
--------------------------------------------------------------------------------------------------------
namespace MyGame
{
    /// <summary>
    /// MyGame中的怪物类
    /// </summary>
    public class TurtleMonster
    {
        public TurtleMonster() { }
        public TurtleMonster(string name,Image image, Point originalLocation, Size size)
        {
            this.OriginalBlood = 200;
            this.AttackPower = 50;
            this.DefendPower = 10;
            this.MonsterName = name;
            this.Image = image;
            this.OriginalLocation = originalLocation;
            this.CurrentLocation = originalLocation;
            this.Size = size;
        }
        
        //怪物名字
        private string monsterName;
        public string MonsterName
        {
            get { return monsterName; }
            set { monsterName = value; }
        }
        //原始生命值
        private int originalBlood;
        public int OriginalBlood
        {
            get { return originalBlood; }
            set { originalBlood = value; }
        }
        //攻击力
        private int attackPower;
        public int AttackPower
        {
            get { return attackPower; }
            set { attackPower = value; }
        }
        //防御力
        private int defendPower;
        public int DefendPower
        {
            get { return defendPower; }
            set { defendPower = value; }
        }
        //怪物的图片
        private Image image;
        public Image Image
        {
            get { return image; }
            set { image = value; }
        }
        //原始位置
        private Point originalLocation;
        public Point OriginalLocation
        {
            get { return originalLocation; }
            set { originalLocation = value; }
        }
        //当前位置
        private Point currentLocation;
        public Point CurrentLocation
        {
            get { return currentLocation; }
            set { currentLocation = value; }
        }
        // 大小
        private Size size;
        public Size Size
        {
            get { return size; }
            set { size = value; }
        }

        /// <summary>
        /// 怪物移动的方法 
        /// </summary>
        /// <param name="hero">移动到玩家</param>
        public void Move(Hero hero)
        {
            //移动到玩家
            this.CurrentLocation = new Point(hero.OriginalLocation.X, hero.OriginalLocation.Y - hero.Size.Height);
        }
        /// <summary>
        /// 回到原位置方法
        /// </summary>
        public void Move()
        {
            //返回是将原始位置设为当前位置
            this.CurrentLocation = this.OriginalLocation;
        }
    }
} --------------------编程问答--------------------
----------------------------------------------------------------------------------------------------------
namespace MyGame
{
    /// <summary>
    /// MyGame中的玩家类
    /// </summary>
    public class Hero
    {
        public Hero() { }
        public Hero(string name, int originalBlood, int attackPower, int defendPower, 
            Image image, Point originalLocation, Size size)
        {
            this.OriginalBlood = originalBlood;
            this.HeroName = name;
            this.AttackPower = attackPower;
            this.DefendPower = defendPower;
            this.Image = image;
            this.OriginalLocation = originalLocation;
            //当前位置赋予初始位置的参数即可
            this.CurrentLocation = originalLocation;
            this.Size = size;
        }
        
        //主角名字
        private string heroName;
        public string HeroName
        {
            get { return heroName; }
            set { heroName = value; }
        }
        //原始生命值
        private int originalBlood;
        public int OriginalBlood
        {
            get { return originalBlood; }
            set { originalBlood = value; }
        }
        //攻击力
        private int attackPower;
        public int AttackPower
        {
            get { return attackPower; }
            set { attackPower = value; }
        }
        //防御力
        private int defendPower;
        public int DefendPower
        {
            get { return defendPower; }
            set { defendPower = value; }
        }
        //玩家的图片
        private Image image;
        public Image Image
        {
            get { return image; }
            set { image = value; }
        }
        //原始位置
        private Point originalLocation;
        public Point OriginalLocation
        {
            get { return originalLocation; }
            set { originalLocation = value; }
        }
        //当前位置
        private Point currentLocation;
        public Point CurrentLocation
        {
            get { return currentLocation; }
            set { currentLocation = value; }
        }
        // 大小
        private Size size;
        public Size Size
        {
            get { return size; }
            set { size = value; }
        }

        /// <summary>
        /// 移动到怪物的左下角
        /// </summary>
        /// <param name="monster">玩家所移动到的怪物对象</param>
        public void Move(TurtleMonster monster)
        {
            //移动到怪物左下角
            this.CurrentLocation = new Point(
                monster.OriginalLocation.X,
                monster.OriginalLocation.Y + monster.Size.Height);
        }

        /// <summary>
        /// 重载Move方法  返回原始位置
        /// </summary>
        public void Move()
        {
            //返回是将原始位置设为当前位置
            this.CurrentLocation = this.OriginalLocation;
        }
    }
}
------------------------------------------------------------------------------------------------------
A:  this.lblHeroBlood.Size = new Size(0, 20);
            this.lblMonsterBlood.Size = new Size(0, 20);

            this.lblHeroCurBlood.Size = new Size(0, 20);
            this.lblMonCurBlood.Size = new Size(0, 20);
这段代码是做什么用的?
B:Pint是怎么定义图片坐标的。
a:        public void Move(Hero hero)
        {
            //移动到玩家
            this.CurrentLocation = new Point(hero.OriginalLocation.X, hero.OriginalLocation.Y - hero.Size.Height);
        }
b:public void Move(TurtleMonster monster)
        {
            //移动到怪物左下角
            this.CurrentLocation = new Point(
                monster.OriginalLocation.X,
                monster.OriginalLocation.Y + monster.Size.Height);
        }

 说明:怪物图片在玩家图片上面。
a这段代码是不是说玩家图片的左下前点坐标X不变,Y减去图片的高度,就等于玩家图片左上前点的坐标。玩家图片左上前点的坐标作为怪物左下前点的坐标。
b是不是说怪物图片左上前点坐标X不变,Y加上图片的高度,就等于怪物图片左下前点的坐标。怪物图片左下前点的坐标作为玩家左上前点的坐标。

那为什么2张图片的起始坐标点不一致。怪物起始坐标是图片的左上角,玩家起始坐标是图片的左下角?
--------------------编程问答-------------------- 您不考虑图片的size?如果玩家起始坐标是图片的左上角,很可能玩家的图片会覆盖怪物的图片 --------------------编程问答-------------------- 如果2张图坐标起始点都是左上角,并以左上点坐标计算。怪物移下来:玩家的左上坐标-怪物图片的高度就是怪物图片左上点坐标该移动到的坐标点。
我问的是Point是怎么设置起始坐标点的,以哪个点作为起始坐标点?并以图片哪个坐标点作为图片最终移到的坐标点 --------------------编程问答-------------------- 谁能解释下? --------------------编程问答-------------------- 没人肯解释下吗? --------------------编程问答-------------------- 幫你頂上去 --------------------编程问答-------------------- 楼主北大青鸟的吧  嘿嘿 --------------------编程问答-------------------- 兄弟能帮忙解释下吗?谢谢了 --------------------编程问答-------------------- 唉。。。。。。。。。。。。。 --------------------编程问答-------------------- 没有用过 友情帮顶  --------------------编程问答-------------------- --------------------编程问答-------------------- 帮我顶下 --------------------编程问答-------------------- 哦也,游戏开发,,有钱途。。。赶快帮顶。。。。。。。。 --------------------编程问答-------------------- Point 把窗口的左上角设为原点(0,0)
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,