龙空技术网

C# 超级小玛丽小游戏,练一练,娱乐一下自己吧。

快乐鲤渔 78

前言:

眼前看官们对“超级玛丽gameover音乐”都比较注重,朋友们都想要学习一些“超级玛丽gameover音乐”的相关资讯。那么小编在网上网罗了一些关于“超级玛丽gameover音乐””的相关文章,希望各位老铁们能喜欢,同学们快快来学习一下吧!

按下空格键控制跳起动作:

        private void Form1_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.Space && !isJumping && !gameOver)            {                                jumpSpeed = -10;            }        }
显示图片与得分情况:
       private void Form1_Paint(object sender, PaintEventArgs e)        {            e.Graphics.FillRectangle(Brushes.SkyBlue, 0, 0, ClientSize.Width, ClientSize.Height);            e.Graphics.DrawImage(Properties.Resources._1, 50, marioY, MarioSize, MarioSize);//图片            e.Graphics.FillRectangle(Brushes.Red, objectX, objectY, ObjectSize, ObjectSize);            e.Graphics.DrawString($"得分:{score}", Font, Brushes.Black, 10, 10);        }    
窗体初始化:
         private const int MarioSize = 50;        private const int ObjectSize = 50;        private const int ObjectSpeed = 10;        private int marioY;        private int objectX;        private int objectY;        private bool isJumping;        private int jumpSpeed;        private bool gameOver;        private int score;        public Form1()        {            InitializeComponent();            marioY = ClientSize.Height - MarioSize;            objectX = ClientSize.Width;            objectY = ClientSize.Height - ObjectSize;            isJumping = false;            jumpSpeed = 10;            gameOver = false;            score = 0;            timer1.Interval = 1000 / 60; // 每秒60帧            timer1.Enabled = true;        }
添加时间控件:
private void timer1_Tick(object sender, EventArgs e)        {            if (!gameOver)            {                objectX -= ObjectSpeed;                if (objectX < -ObjectSize)                {                    objectX = ClientSize.Width + ObjectSize;                    objectY = ClientSize.Height - ObjectSize - new Random().Next(50, 150);                    score++;                }                if (isJumping)                {                    marioY -= jumpSpeed;                    jumpSpeed--;                    if (marioY >= ClientSize.Height - MarioSize)                    {                        isJumping = false;                        marioY = ClientSize.Height - MarioSize;                        jumpSpeed = 10;                    }                }                else                {                    marioY += jumpSpeed;                    jumpSpeed = Math.Min(jumpSpeed + 1, 20);                    if (marioY + MarioSize > ClientSize.Height)//停在底部                    {                        marioY = ClientSize.Height - MarioSize;                    }                }                if (objectX < 100 && objectX > 0 && marioY + MarioSize > objectY)                {                    gameOver = true;                    timer1.Enabled = false;                    MessageBox.Show($"游戏结束!得分:{score}");                }                                Invalidate();            }

#头条创作挑战赛##大湾区寻宝#

标签: #超级玛丽gameover音乐 #超级玛丽game over音乐