コード例 #1
0
ファイル: GameScreen.cs プロジェクト: sahil901/Scuffed_Contra
        private void StartFunction(int x)
        {
            if (x == 0)
            {
                //main boy
                joe = new character(playerBrush, playerX, playerY, 30, 50, 3);

                ai = new character(aiBrush, 850, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 1100, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 1200, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 1300, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 1400, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 1800, 295, 30, 50, 2);
                aiList.Add(ai);

                ai = new character(aiBrush, 2000, 295, 30, 50, 2);
                aiList.Add(ai);

                chasm = new character(aiBrush, 1000, 295, 1000, 1000, 0);
                chasmList.Add(chasm);

                chasm = new character(aiBrush, 100, 295, 100, 100, 0);
                chasmList.Add(chasm);
            }
        }
コード例 #2
0
ファイル: GameScreen.cs プロジェクト: sahil901/Scuffed_Contra
        //game loop tick
        public void GameLoop_Tick(object sender, EventArgs e)
        {
            //check timer
            eTime = timeWatch.ElapsedMilliseconds;

            // MOVE - Looks like Joe is moving
            if (rightArrowDown)
            {
                foreach (character ai in aiList)
                {
                    ai.Move("left", 2);
                }
                foreach (character chasm in chasmList)
                {
                    chasm.Move("left", 2);
                }
            }

            if (spaceDown)
            {
                // create a laser that moves towards the ai since always right
                if (bulletcounter > 10)
                {
                    bullets = new character(bBrush, playerX, playerY + 15, 15, 5, 0);
                    bulletList.Add(bullets);
                    bulletcounter = 0;
                    playershootsound.Play();
                }
            }

            // decide if the ai should shoot back
            if (attackcounter > 50 && aiList[0].x <= 750)
            {
                bullets = new character(bBrush, aiList[0].x, aiList[0].y + 15, 15, 5, 0);
                aiBList.Add(bullets);
                attackcounter = 0;
            }

            // shoot and remove bullets made by the player
            if (bulletList.Count > 0)
            {
                // Move the bullets until they are off screen
                foreach (character bullets in bulletList)
                {
                    bullets.Shoot("right", 9);

                    if (bullets.x > this.Width)
                    {
                        bulletList.Remove(bullets);
                        break;
                    }
                }
            }

            // shoot and remove the bullets made by the ai
            if (aiBList.Count > 0)
            {
                enemyshootsound.Play();
                // Move the bullets until they are off screen
                foreach (character bullets in aiBList)
                {
                    bullets.Shoot("left", 5);

                    if (bullets.x < 0)
                    {
                        aiBList.Remove(bullets);
                        break;
                    }
                }
            }

            // Make the ai boys moves slower towards the player every tick
            foreach (character ai in aiList)
            {
                ai.Move("left", 1);
            }

            // COLLISION - between objects in game
            Rectangle playerRec = new Rectangle(joe.x, joe.y, joe.width, joe.length);

            // ai checks collisions with player
            foreach (character ai in aiList)
            {
                Rectangle aiRec = new Rectangle(ai.x, ai.y, ai.width, ai.length);
                // player collison
                if (playerRec.IntersectsWith(aiRec))
                {
                    if (hitcontrol > 50)
                    {
                        score = score - 100;
                        joe.health--;
                        hitcontrol = 0;
                    }
                    break;
                }
            }

            // bullet collison creates rectangles for the bullets and checks against ai
            foreach (character bullets in bulletList)
            {
                Rectangle bRec = new Rectangle(bullets.x, bullets.y, 4, 20);

                foreach (character ai in aiList)
                {
                    Rectangle aiRec = new Rectangle(ai.x, ai.y, 30, 40);
                    if (aiRec.IntersectsWith(bRec))
                    {
                        enemydeadsound.Play();
                        ai.health--;
                        score = score + 25;
                        removecontrol++;
                        break;
                    }
                }
            }

            // ai bullet collison with player
            foreach (character bullets in aiBList)
            {
                Rectangle bRec = new Rectangle(bullets.x, bullets.y, 4, 20);
                if (playerRec.IntersectsWith(bRec))
                {
                    //   playerdeadsound.Play();
                    joe.health--;
                    score = score - 50;
                    airemovecontrol++;
                    break;
                }
            }

            // see if joe dies
            if (joe.health <= 0)
            {
                GameOver go = new GameOver();
                GameLoop.Enabled = false;
                Form f = this.FindForm();
                f.Controls.Remove(this);
                go.Location = new Point((f.Width - go.Width) / 2, (f.Height - go.Height) / 2);
                //add game over screen
                f.Controls.Add(go);
            }

            //checking to see if ai needs to get hit
            foreach (character ai in aiList)
            {
                if (ai.health <= 0)
                {
                    aiList.Remove(ai);
                    break;
                }
            }

            //pause screen escdown
            if (escDown)
            {
                GameLoop.Stop();
                rightArrowDown = false;
                spaceDown      = false;
                escDown        = false;
                DialogResult result = PauseForm.Show();
                if (result == DialogResult.Cancel)
                {
                    GameLoop.Enabled = true;
                }

                else if (result == DialogResult.Abort)
                {
                    Application.Exit();
                }
            }

            // jumping code
            if (upArrowDown)
            {
                if (presscontrol > 55)
                {
                    playerjumpsound.Play();
                    jumpcounter  = 1;
                    presscontrol = 0;
                }
            }

            // if jumpcounter should be used, use it
            if (jumpcounter > 0)
            {
                joe.Jump(3, 0);
                jumpcounter++;
                if (jumpcounter >= 20)
                {
                    jumpcounter = 0;
                    downcounter = 1;
                    joe.Jump(0, 0);
                }
            }

            // if downcounter should be use, use it
            if (downcounter > 0)
            {
                joe.Jump(0, 3);
                downcounter++;
                if (downcounter >= 20)
                {
                    jumpcounter = 0;
                    downcounter = 0;
                    joe.Jump(0, 0);
                }
            }

            // do see if the bullet should be removed
            if (removecontrol > 0)
            {
                bulletList.Remove(bullets);
                removecontrol = 0;
            }
            if (airemovecontrol > 0)
            {
                aiBList.Remove(bullets);
                airemovecontrol = 0;
            }

            // find the current time for the timer
            tTime = (sTime - eTime) / 1000;

            //add every tick for shot  and press timing
            bulletcounter++;
            attackcounter++;
            presscontrol++;
            hitcontrol++;

            // get random number

            //Redraw the screen
            Refresh();
        }