コード例 #1
0
ファイル: Form1.cs プロジェクト: bac6536/TankTankTank
        private void resetGame()
        {
            Size body          = new Size(75, 30);
            Size gun           = new Size(38, 7);
            int  ground_Height = 100;

            ground_Rect = new Rectangle(new Point(0, map_Rect.Height - ground_Height),
                                        new Size(map_Rect.Width, ground_Height));
            int x  = body.Width / 2;
            int x2 = map_Rect.Width - body.Width / 2;
            int y  = map_Rect.Height - (ground_Height + body.Height * 3 / 4);
            int y2 = map_Rect.Height - (ground_Height + body.Height * 3 / 4);

            tank_Player = new Tank(new Point(x, y), new Point(x + body.Width / 8, y), new Rectangle(new Point(x - body.Width / 2, y - body.Height / 4), body),
                                   new Rectangle(new Point(x, y - gun.Height / 2), gun),
                                   new Rectangle(new Point(0, 0), new Size(map_Rect.Width, map_Rect.Height - ground_Height)));
            tank_Player2 = new Tank(new Point(x2, y2), new Point(x2 - body.Width / 8, y2), new Rectangle(new Point(x2 - body.Width / 2, y2 - body.Height / 4), body),
                                    new Rectangle(new Point(x2, y2 - gun.Height / 2), gun),
                                    new Rectangle(new Point(0, 0), new Size(map_Rect.Width, map_Rect.Height - ground_Height)));
            // tank_Player2.deg = 135;

            /*
             * Size body = new Size(100, 20);
             * Size turret = new Size(40, 20);
             * int ground_Height = 100;
             * ground_Rect = new RectangleF(new Point(0, (int)map_Rect.Height - ground_Height),
             *  new Size((int)map_Rect.Width, ground_Height));
             * int x = body.Width / 2;
             * int y = (int)map_Rect.Height - (ground_Height + body.Height + turret.Height / 2 + 1);
             * tank_Player = new Tank(new Point(x, y), new Rectangle(new Point(x - body.Width / 2, y + turret.Height / 2), body),
             *  new Rectangle(new Point(x - turret.Width / 2, y - turret.Height / 2), turret),
             *  new Rectangle(new Point(0, 0), new Size((int)map_Rect.Width, (int)map_Rect.Height - ground_Height)));
             */
            gauge_Player          = new ProgressBar();
            gauge_Player.Step     = 1;
            gauge_Player.Size     = new Size(300, 20);
            gauge_Player.Style    = ProgressBarStyle.Continuous;
            gauge_Player_Pos      = new Point(50, this.ClientRectangle.Height - 80);
            gauge_Player.Location = gauge_Player_Pos;
            gauge_Player.Visible  = true;
            this.Controls.Add(gauge_Player);

            gauge_Player2          = new ProgressBar();
            gauge_Player2.Step     = 1;
            gauge_Player2.Size     = new Size(300, 20);
            gauge_Player2.Style    = ProgressBarStyle.Continuous;
            gauge_Player_Pos2      = new Point(50, this.ClientRectangle.Height - 80);
            gauge_Player2.Location = gauge_Player_Pos2;
            gauge_Player2.Visible  = true;
            this.Controls.Add(gauge_Player2);

            hp_Player           = new ProgressBar();
            hp_Player.Size      = new Size(75, 15);
            hp_Player.Style     = ProgressBarStyle.Continuous;
            hp_Player_Pos       = new Point(x - body.Width / 2, y - (tank_Player.cannon_Len + hp_Player.Height));
            hp_Player.Location  = hp_Player_Pos;
            hp_Player.ForeColor = Color.Blue;
            hp_Player.Maximum   = 2000;
            hp_Player.Value     = 2000;
            hp_Player.Visible   = true;
            this.Controls.Add(hp_Player);


            hp_Player2           = new ProgressBar();
            hp_Player2.Size      = new Size(75, 15);
            hp_Player2.Style     = ProgressBarStyle.Continuous;
            hp_Player_Pos2       = new Point(x2 - body.Width / 2, y2 - (tank_Player2.cannon_Len + hp_Player2.Height));
            hp_Player2.Location  = hp_Player_Pos2;
            hp_Player2.ForeColor = Color.Blue;
            hp_Player2.Maximum   = 2000;
            hp_Player2.Value     = 2000;
            hp_Player2.Visible   = true;
            this.Controls.Add(hp_Player2);

            Size terrain_Size = new Size(120, 40);

            terrain_Rect = new Rectangle(new Point(this.ClientRectangle.Width / 2 - terrain_Size.Width / 2, this.ClientRectangle.Height - (ground_Height + terrain_Size.Height)),
                                         terrain_Size);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: bac6536/TankTankTank
        private void operateTank(Tank tank_Obj, ProgressBar gauge, Point gauge_Pos)
        {
            int    speed;
            double deg;
            bool   bDraw;

            while (bRunning)
            {
                speed = 5;
                Point tank_Body_Pos = tank_Obj.body_Rect.Location;
                Point tank_Gun_Pos  = tank_Obj.gun_Rect.Location;
                if (tank_Obj.L)
                {
                    tank_Obj.center.X  -= speed;
                    tank_Obj.gun_Axis.X = tank_Obj.center.X + tank_Obj.body_Rect.Width / 8;
                    tank_Body_Pos.X    -= speed;
                    tank_Gun_Pos.X     -= speed;
                    if (tank_Obj.center.X < tank_Obj.body_Rect.Width / 2)
                    {
                        tank_Obj.center.X   = tank_Obj.body_Rect.Width / 2;
                        tank_Obj.gun_Axis.X = tank_Obj.center.X + tank_Obj.body_Rect.Width / 8;
                        tank_Body_Pos.X     = 0;
                        tank_Gun_Pos.X      = tank_Obj.body_Rect.Width / 2;
                    }
                }
                else if (tank_Obj.R)
                {
                    tank_Obj.center.X  += speed;
                    tank_Obj.gun_Axis.X = tank_Obj.center.X + tank_Obj.body_Rect.Width / 8;
                    tank_Body_Pos.X    += speed;
                    tank_Gun_Pos.X     += speed;
                    if (tank_Obj.gun_Axis.X + tank_Obj.gun_Rect.Width > terrain_Rect.Left)
                    {
                        tank_Obj.center.X   = terrain_Rect.Left - tank_Obj.gun_Rect.Width;
                        tank_Obj.gun_Axis.X = tank_Obj.center.X + tank_Obj.body_Rect.Width / 8;
                        tank_Body_Pos.X     = tank_Obj.center.X - tank_Obj.gun_Rect.Width;
                        tank_Gun_Pos.X      = tank_Obj.map_Rect.Width - tank_Obj.body_Rect.Width / 2;
                    }
                    if (tank_Obj.center.X > tank_Obj.map_Rect.Width - tank_Obj.body_Rect.Width / 2)
                    {
                        tank_Obj.center.X   = tank_Obj.map_Rect.Width - tank_Obj.body_Rect.Width / 2;
                        tank_Obj.gun_Axis.X = tank_Obj.center.X + tank_Obj.body_Rect.Width / 8;
                        tank_Body_Pos.X     = tank_Obj.map_Rect.Width - tank_Obj.body_Rect.Width;
                        tank_Gun_Pos.X      = tank_Obj.map_Rect.Width - tank_Obj.body_Rect.Width / 2;
                    }
                }
                tank_Obj.body_Rect.Location = tank_Body_Pos;
                tank_Obj.gun_Rect.Location  = tank_Gun_Pos;
                gauge_Pos.X    = tank_Obj.center.X - tank_Obj.body_Rect.Width / 2;
                gauge.Location = gauge_Pos;
                deg            = 1;
                if (tank_Obj.U)
                {
                    tank_Obj.deg -= deg;
                    if (tank_Obj.deg < 0)
                    {
                        tank_Obj.deg = 0;
                    }
                }
                else if (tank_Obj.D)
                {
                    tank_Obj.deg += deg;
                    if (tank_Obj.deg > 90)
                    {
                        tank_Obj.deg = 90;
                    }
                }
                bDraw = tank_Obj.U || tank_Obj.D || tank_Obj.L || tank_Obj.R || bRunning;
                for (int i = 0; i < tank_Obj.bullets.Count; ++i)
                {
                    bDraw |= true;

                    /*
                     * if (!tank_Obj.bullets[i].hit)
                     * {
                     *  bDraw |= true;
                     * }
                     */
                }
                if (bDraw)
                {
                    draw();
                }
                if (tank_Obj.U || tank_Obj.D || tank_Obj.L || tank_Obj.R)
                {
                    if (server_connected)
                    {
                        server.SendMessage("t " + tank_Obj.center.X.ToString() + " " +
                                           tank_Obj.center.Y.ToString() + " " +
                                           tank_Obj.gun_Axis.X.ToString() + " " +
                                           tank_Obj.gun_Axis.Y.ToString() + " " +
                                           tank_Obj.deg.ToString() + " " +
                                           tank_Obj.gun_Rect.X.ToString() + " " +
                                           tank_Obj.gun_Rect.Y.ToString() + " " +
                                           hp_Player.Value.ToString());
                    }
                    else if (client_connected)
                    {
                        client.SendMessage("t " + tank_Obj.center.X.ToString() + " " +
                                           tank_Obj.center.Y.ToString() + " " +
                                           tank_Obj.gun_Axis.X.ToString() + " " +
                                           tank_Obj.gun_Axis.Y.ToString() + " " +
                                           tank_Obj.deg.ToString() + " " +
                                           tank_Obj.gun_Rect.X.ToString() + " " +
                                           tank_Obj.gun_Rect.Y.ToString() + " " +
                                           hp_Player.Value.ToString());
                    }
                }
                Thread.Sleep(20);
            }
        }