Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            // draw background
            e.Graphics.DrawImage(Properties.Resources.DragonBallBackground, backgroundBox);
            // draw logo
            e.Graphics.DrawImage(Properties.Resources.DragonBallLogo, logoBox);
            // draw goku icon
            e.Graphics.DrawImage(Properties.Resources.GokuIcon, GokuIconBox);
            // draw buu icon
            e.Graphics.DrawImage(Properties.Resources.BuuIcon, BuuIconBox);
            // draw timer
            e.Graphics.DrawString(timer.ToString(), timerFont, Brushes.Black, timerBox);
            // draw obstacle
            e.Graphics.DrawImage(Properties.Resources.DragonBallBall, dragonBallBox);
            // show player name
            e.Graphics.DrawString(PLAYERNAME_STRING, nameFont, Brushes.Black, playerNameBox);
            // show enemy name
            e.Graphics.DrawString(ENEMYNAME_STRING, nameFont, Brushes.Black, enemyNameBox);
            // draw enemy's standing pic
            if (enemyStand == true)
            {
                e.Graphics.DrawImage(Properties.Resources.BuuStand, enemyBox);
            }
            // draw player's standing pic
            if (stand == true && playerAlive == true)
            {
                e.Graphics.DrawImage(Properties.Resources.GokuStand, playerBox);
                moveRight = false;
                moveLeft  = false;
                punch     = false;
                moveUp    = false;
                moveDown  = false;
                block     = false;
                kiBlast   = false;
            }
            // move right animation
            else if (moveRight == true)
            {
                if (animationFrameCount >= 0 && animationFrameCount < 5)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight1, playerBox);
                }
                else if (animationFrameCount >= 5 && animationFrameCount < 10)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight2, playerBox);
                }
                else if (animationFrameCount >= 10 && animationFrameCount < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight3, playerBox);
                }
                else if (animationFrameCount >= 15 && animationFrameCount < 20)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight4, playerBox);
                }
            }
            // move left animatoin
            else if (moveLeft == true)
            {
                if (animationFrameCount >= 0 && animationFrameCount < 5)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunLeft1, playerBox);
                }
                else if (animationFrameCount >= 5 && animationFrameCount < 10)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunLeft2, playerBox);
                }
                else if (animationFrameCount >= 10 && animationFrameCount < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunLeft3, playerBox);
                }
                else if (animationFrameCount >= 15 && animationFrameCount < 20)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunLeft4, playerBox);
                }
            }
            // punch animation
            else if (punch == true)
            {
                if (animationFrameCount2 >= 0 && animationFrameCount2 < 3)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch1, playerBox);
                }
                else if (animationFrameCount2 >= 3 && animationFrameCount2 < 6)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch2, playerBox);
                }
                else if (animationFrameCount2 >= 6 && animationFrameCount2 < 9)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch3, playerBox);
                }
                else if (animationFrameCount2 >= 9 && animationFrameCount2 < 12)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch4, playerBox);
                }
                else if (animationFrameCount2 >= 12 && animationFrameCount2 < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch5, playerBox);
                }
                else if (animationFrameCount2 >= 15 && animationFrameCount2 < 18)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuPunch6, playerBox);
                }
            }
            // move up animation
            else if (moveUp == true)
            {
                if (animationFrameCount >= 0 && animationFrameCount < 5)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight1, playerBox);
                }
                else if (animationFrameCount >= 5 && animationFrameCount < 10)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight2, playerBox);
                }
                else if (animationFrameCount >= 10 && animationFrameCount < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight3, playerBox);
                }
                else if (animationFrameCount >= 15 && animationFrameCount < 20)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight4, playerBox);
                }
            }
            // move down animation
            else if (moveDown == true)
            {
                if (animationFrameCount >= 0 && animationFrameCount < 5)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight1, playerBox);
                }
                else if (animationFrameCount >= 5 && animationFrameCount < 10)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight2, playerBox);
                }
                else if (animationFrameCount >= 10 && animationFrameCount < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight3, playerBox);
                }
                else if (animationFrameCount >= 15 && animationFrameCount < 20)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuRunRight4, playerBox);
                }
            }
            //  block animation
            else if (block == true)
            {
                if (animationFrameCount2 >= 0 && animationFrameCount2 < 6)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuBlock1, playerBox);
                }
                else if (animationFrameCount2 >= 6 && animationFrameCount2 < 12)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuBlock2, playerBox);
                }
                else if (animationFrameCount2 >= 12 && animationFrameCount2 < 18)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuBlock3, playerBox);
                }
            }
            // ki blast animation
            else if (kiBlast == true)
            {
                if (animationFrameCount2 >= 0 && animationFrameCount2 < 3)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast1, playerBox);
                }
                else if (animationFrameCount2 >= 3 && animationFrameCount2 < 6)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast2, playerBox);
                }
                else if (animationFrameCount2 >= 6 && animationFrameCount2 < 9)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast3, playerBox);
                }
                else if (animationFrameCount2 >= 9 && animationFrameCount2 < 12)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast4, playerBox);
                }
                else if (animationFrameCount2 >= 12 && animationFrameCount2 < 15)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast5, playerBox);
                }
                else if (animationFrameCount2 >= 15 && animationFrameCount2 < 18)
                {
                    e.Graphics.DrawImage(Properties.Resources.KiBlast6, playerBox);
                }
            }
            // show enemy death animation
            if (enemyAlive == false)
            {
                if (animationFrameCount4 >= 0 && animationFrameCount4 < 150)
                {
                    e.Graphics.DrawImage(Properties.Resources.BuuDead1, enemyBox);
                }
                else if (animationFrameCount4 >= 150 && animationFrameCount4 < 300)
                {
                    enemyDeadSize     = new SizeF(125, 87);
                    enemyDeadLocation = new PointF(enemyLocation.X, enemyLocation.Y + 38);
                    enemyDeadBox      = new RectangleF(enemyDeadLocation, enemyDeadSize);
                    e.Graphics.DrawImage(Properties.Resources.BuuDead2, enemyDeadBox);
                }
                else if (animationFrameCount4 >= 300 && animationFrameCount4 < 500)
                {
                    // change form
                    Form3 frmWin = new Form3();
                    frmWin.Show();
                    this.Hide();
                }
            }
            // show player death animation
            if (playerAlive == false)
            {
                if (animationFrameCount4 >= 0 && animationFrameCount4 < 150)
                {
                    e.Graphics.DrawImage(Properties.Resources.GokuDead1, playerBox);
                }
                else if (animationFrameCount4 >= 150 && animationFrameCount4 < 300)
                {
                    playerDeadSize     = new SizeF(125, 100);
                    playerDeadLocation = new PointF(playerLocation.X, playerLocation.Y + 25);
                    playerDeadBox      = new RectangleF(playerDeadLocation, playerDeadSize);
                    e.Graphics.DrawImage(Properties.Resources.GokuDead2, playerDeadBox);
                }
                else if (animationFrameCount4 >= 300 && animationFrameCount4 < 500)
                {
                    // change form
                    Form4 frmLose = new Form4();
                    frmLose.Show();
                    this.Hide();
                }
            }
            // draw player's projectile
            if (isProjectileInMotion == true)
            {
                e.Graphics.DrawImage(Properties.Resources.Ki, projectileBox);
            }

            if (isProjectile2InMotion == true)
            {
                enemyStand = false;
                // draw enemy's projectile
                e.Graphics.DrawImage(Properties.Resources.BuuKi, projectile2Box);
                // enemy shoot projectile animation
                if (animationFrameCount >= 0 && animationFrameCount < 10)
                {
                    e.Graphics.DrawImage(Properties.Resources.BuuBlast1, enemyBox);
                }
                else if (animationFrameCount >= 10 && animationFrameCount < 20)
                {
                    e.Graphics.DrawImage(Properties.Resources.BuuBlast2, enemyBox);
                }
            }
        }
Ejemplo n.º 2
0
        void GameTimer()
        {
            isGameRunning = true;
            lastRunTime   = Environment.TickCount;

            // run every 25 ms
            while (isGameRunning == true)
            {
                // control the interval
                if (Environment.TickCount - lastRunTime >= timerInterval)
                {
                    lastRunTime = Environment.TickCount;
                    // move the player and check boundaries
                    if (moveRight == true)
                    {
                        x = x + 30;
                        playerBox.Location = new PointF(x, y);
                        CheckRightBoundary();
                        CheckBallLeftBoundary();
                    }
                    else if (moveLeft == true)
                    {
                        x = x - 30;
                        playerBox.Location = new PointF(x, y);
                        CheckLeftBoundary();
                        CheckBallRightBoundary();
                    }
                    else if (moveUp == true)
                    {
                        y = y - 30;
                        playerBox.Location = new PointF(x, y);
                        CheckTopBoundary();
                        CheckBallBottomBoundary();
                    }
                    else if (moveDown == true)
                    {
                        y = y + 30;
                        playerBox.Location = new PointF(x, y);
                        CheckBottomBoundary();
                        CheckBallTopBoundary();
                    }
                    // calculate player punch damage
                    else if (punch == true && playerBox.IntersectsWith(enemyBox))
                    {
                        enemyHp            = enemyHp - playerPunchDamage;
                        progressBar2.Value = (int)((double)enemyHp / enemyMaxHp * 100);
                    }
                    // The programs that need to be running reapeatily
                    CheckEnemyHp();
                    CheckPlayerHp();
                    ControlAnimation();
                    MovePrjectile();
                    CreateNewProjectile2();
                    MoveProjectile2();
                    MoveEnemy();
                    enemyKiDamage  = 10;
                    playerLocation = new PointF(x, y);
                    Refresh();
                }
                // loop for timer
                if (Environment.TickCount - lastRunTime3 >= timerInterval3)
                {
                    lastRunTime3 = Environment.TickCount;
                    if (timer >= 1)
                    {
                        timer--;
                    }
                    else if (timer <= 0)
                    {
                        // stop everything
                        isGameRunning         = false;
                        gameEnded             = true;
                        isProjectile2InMotion = false;
                        isProjectile2InMotion = false;
                        enemyStand            = true;
                        kiBlast = false;
                        // change form
                        Form4 frmLose = new Form4();
                        frmLose.Show();
                        this.Hide();
                    }
                    Refresh();
                }
                // stop program from freezing
                Application.DoEvents();
            }
        }