c#飞机大战-简单功能2

本文将详细解析使用C#编程语言实现的飞机大战游戏中的一些基础功能,包括飞机移动、射击、碰撞检测等核心机制。通过实例代码和步骤说明,帮助读者理解游戏开发的基本流程和技巧。
摘要由CSDN通过智能技术生成

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 打字游戏2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Random r = new Random();
        //游戏区
        PictureBox box = new PictureBox();
        //飞机
        PictureBox fei = new PictureBox();
        //按键区
        PictureBox kai = new PictureBox();
        //子弹生成器
        Timer zi = new Timer();
        //下落
        Timer Fly = new Timer();
        //敌机生成器
        Timer zm = new Timer();
        //尾翼
        PictureBox wei = new PictureBox();
        PictureBox weiyi = new PictureBox();
        //音效
        SoundPlayer ying = new SoundPlayer();
        SoundPlayer yin = new SoundPlayer();
        //SoundPlayer yinxiao = new SoundPlayer();
        //血条
        Label xue = new Label();
        //积分器
        Label defen = new Label();
        //开始/暂停按钮
        Label ting = new Label();
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = new Size(800,500);
            this.BackColor = Color.Cyan;
            this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
            this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
            //游戏区
            
            box.Width = 600;
            box.Height = 450;
            box.Location = new Point(0,10);
            box.BackColor = Color.White;
            this.Controls.Add(box);
            //按键区
            kai.Width = 200;
            kai.Height = 400;
            kai.BackColor = Color.Blue;
            this.Controls.Add(kai);
            kai.Location = new Point(0, 10);
            kai.Left = box.Width + box.Left;
            //开始/暂停按钮
            //Label ting = new Label();
            ting.Tag = "anan";
            ting.Size = new Size(150, 40);
            ting.BackColor = Color.Yellow;
            ting.Text = "开始";
            ting.Font = new Font("", 35);
            ting.AutoSize = true;
            kai.Controls.Add(ting);
            ting.Left = kai.Width / 2 - ting.Width / 2;
            ting.Click += Ting_Click;
            //敌机生成器
            //Timer zm = new Timer();
            zm.Interval = 1000;
            zm.Tick += Zm_Tick;
            //zm.Start();
            //下落
            //Timer Fly = new Timer();
            Fly.Interval = 10;
            Fly.Tick += Fly_Tick;
            //Fly.Start();
            
            //飞机
            fei.Tag = "fei";
            fei.Image = Image.FromFile(@"../../img/Enemy2.png");
            fei.Size = new Size(60,60);
            fei.SizeMode = PictureBoxSizeMode.StretchImage;
            fei.Left = box.Width/2 - fei.Width/2;
            fei.Top = box.Height - fei.Height-40;
            fei.BackColor = Color.Transparent;
            box.Controls.Add(fei);

            //尾翼
            wei.Tag = "wei";
            wei.Size = new Size(30, 40);
            wei.Left = fei.Left + fei.Width / 2;
            wei.Top = fei.Top + fei.Height;
            wei.Image = imageList1.Images[0];
            box.Controls.Add(wei);
             weiyi.Tag = "weiji";
            weiyi.Image = imageList2.Images[0];
            w
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值