Example #1
0
        private void gameTimerLoop_Tick(object sender, EventArgs e)
        {
            tick++;
            Form      form    = this.FindForm();
            Rectangle chanRec = new Rectangle(chan.x, chan.y, chan.size, chan.size);

            if (tick % 50 == 0)
            {
                //changes the speed and direction of the Onis every 50 ticks
                speeds.Clear();
                directions.Clear();

                for (int i = 0; i < oni.Count(); i++)
                {
                    speed     = random.Next(1, 9);
                    direction = random.Next(1, 5);
                    speeds.Add(speed);
                    directions.Add(direction);

                    if (directions[i] == lastdirections[i])
                    {
                        direction = random.Next(1, 4);
                    }
                    else
                    {
                    }
                }

                lastdirections.Clear();

                for (int i = 0; i < oni.Count(); i++)
                {
                    lastdirections.Add(directions[i]);
                }
            }

            if (tick == 100)
            {
                //inverts all the elements on the screen except the hero
                if (image == "nonInvert")
                {
                    this.BackgroundImage      = invertScreen;
                    healthBox.BackgroundImage = invertHealthBar;
                    oniImage = invertOni;
                    image    = "invert";
                }
                else if (image == "invert")
                {
                    this.BackgroundImage      = normalScreen;
                    healthBox.BackgroundImage = healthBar;
                    oniImage = normalOni;
                    image    = "nonInvert";
                }

                tick = 0;
            }

            if (oni.Count() > 0)
            {//moves the onis
                for (int i = 0; i < oni.Count(); i++)
                {
                    oni[i].Move(speeds[i], directions[i], form);
                }
            }

            foreach (Oni o in oni)
            {//checks to see if the onis have intersected with the hero
                Rectangle oniRec = new Rectangle(o.x, o.y, o.size, o.size);

                if (chanRec.IntersectsWith(oniRec))
                {
                    //exits the level and goes to the game over screen
                    Form1.lives           = 0;
                    Form1.win             = false;
                    gameTimerLoop.Enabled = false;
                    healthBox.Visible     = false;
                    GameOverScreen go = new GameOverScreen();
                    this.Controls.Add(go);
                }
            }
            //moving the character

            if (Form1.leftArrowDown == true && chan.x < this.Width - chan.size)
            {
                chan.Move("left");
                chan.direction = "left";
            }
            else if (Form1.rightArrowDown == true && chan.x > 0)
            {
                chan.Move("right");
                chan.direction = "right";
            }
            else if (Form1.downArrowDown == true && chan.y < this.Height - chan.size * 2)
            {
                chan.Move("down");
                chan.direction = "down";
            }
            else if (Form1.upArrowDown == true && chan.y > 0)
            {
                chan.Move("up");
                chan.direction = "up";
            }

            if (chanRec.IntersectsWith(key))
            {
                //exits the level and goes to the game over screen
                Form1.timer.Stop();
                Form1.win             = true;
                Form1.hardLevel       = true;
                gameTimerLoop.Enabled = false;
                healthBox.Visible     = false;
                GameOverScreen go = new GameOverScreen();
                this.Controls.Add(go);
            }

            Refresh();
        }
        public void Intersection()
        {
            Rectangle hyunjinRec = new Rectangle(hyunjin.x, hyunjin.y, hyunjin.size, hyunjin.size);

            foreach (Skull s in leftSkulls)
            {
                //checks for intersections with the left skulls
                Rectangle skullRec = new Rectangle(s.x, s.y, s.size, s.size);

                if (skullRec.IntersectsWith(hyunjinRec))
                {
                    hyunjin.x = Form1.heroStart;
                    hyunjin.y = this.Height / 2;

                    if (Form1.oneLife == true)
                    {
                        //exits the level and goes to the game over screen
                        Form1.timer.Stop();
                        Form1.win             = false;
                        gameLoopTimer.Enabled = false;
                        healthBox.Visible     = false;
                        lightBox.Visible      = false;
                        GameOverScreen go = new GameOverScreen();
                        this.Controls.Add(go);
                    }
                    else if (Form1.oneLife == false)
                    {
                        Form1.lives--;
                    }
                }
            }

            foreach (Skull s in downSkulls)
            {
                //checks for intersections with the down skulls
                Rectangle skullRec = new Rectangle(s.x, s.y, s.size, s.size);

                if (skullRec.IntersectsWith(hyunjinRec))
                {
                    hyunjin.x = Form1.heroStart;
                    hyunjin.y = this.Height / 2;

                    if (Form1.oneLife == true)
                    {
                        //exits the level and goes to the game over screen
                        Form1.timer.Stop();
                        Form1.win             = false;
                        gameLoopTimer.Enabled = false;
                        healthBox.Visible     = false;
                        lightBox.Visible      = false;
                        GameOverScreen go = new GameOverScreen();
                        this.Controls.Add(go);
                    }
                    else if (Form1.oneLife == false)
                    {
                        Form1.lives--;
                    }
                }
            }

            //changes the life counter
            if (Form1.lives == 3 && Form1.oneLife == false)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_Full;
            }
            else if (Form1.lives == 3 && Form1.oneLife == true)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_Full_Green;
            }
            else if (Form1.lives == 2 && Form1.oneLife == true)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_2_Green;
            }
            else if (Form1.lives == 2)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_2;
            }
            else if (Form1.lives == 1 && Form1.oneLife == true)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_1_Green;
            }
            else if (Form1.lives == 1)
            {
                healthBox.BackgroundImage = Properties.Resources.Health_Bar_1;
            }
            else if (Form1.lives == 0)
            {
                //exits the level and goes to the game over screen
                Form1.timer.Stop();
                Form1.win             = false;
                gameLoopTimer.Enabled = false;
                healthBox.Visible     = false;
                lightBox.Visible      = false;
                GameOverScreen go = new GameOverScreen();
                this.Controls.Add(go);
            }

            if (hyunjinRec.IntersectsWith(key))
            {
                //exits the level and goes to the game over screen
                Form1.timer.Stop();
                Form1.win             = true;
                Form1.mediumLevel     = true;
                gameLoopTimer.Enabled = false;
                healthBox.Visible     = false;
                lightBox.Visible      = false;
                GameOverScreen go = new GameOverScreen();
                this.Controls.Add(go);
            }
        }