示例#1
0
 public void RemoveLaser(Classes.laser l)
 {
     lasers.Remove(l);
 }
示例#2
0
        private void GameScreen_Paint(object sender, PaintEventArgs e)
        {
            if (!started)
            {
                Font s = new Font(Font.FontFamily, 20);

                e.Graphics.DrawString("Press Space to Play!", s, new SolidBrush(Color.White), (this.Width - 300) / 2, 100);
            }
            switch (curntMech)
            {
            case "none":
                //e.Graphics.DrawRectangle(playerPen, player.hb);
                break;

            case "teleporter":
                break;

            case "superJump":
                break;

            case "gravity":
                break;
            }


            e.Graphics.DrawRectangle(playerPen, player.hb);
            if (curntMech == "teleporter")
            {
                teleporterDraw(e.Graphics, teleporterMarkerY);
            }
            foreach (Classes.rocket l in rockets)
            {
                if (l.launchingRocket && l.launchingTicks < 180)
                {
                    l.launchingTicks++;
                    e.Graphics.DrawRectangle(new Pen(Color.White), this.Width - 30, player.hb.Top + 25, 30, 25);
                }
                if (l.launchingTicks == 180 && l.launchingRocket)
                {
                    l.hb.Y            = player.y + 25;
                    l.y               = player.y + 25;
                    l.launchingRocket = false;
                }
                if (!l.launchingRocket)
                {
                    l.move();
                    e.Graphics.DrawRectangle(playerPen, l.hb);
                    if (l.hb.Right <= 0)
                    {
                        rocketToRemove = l;
                    }
                    if (player.hb.IntersectsWith(l.hb))
                    {
                        //GameOver();
                        if (!endGame && curntMech == "none")
                        {
                            endGame    = true;
                            spdStorage = backgroundMoveSpd;
                            bounce     = (this.Height - player.y) / 2;
                        }
                        else if (curntMech != "none")
                        {
                            toClearLsers = true;
                            grounded     = false;
                            curntMech    = "none";
                        }
                    }
                }
            }

            foreach (Classes.laser l in lasers)
            {
                l.move();
                e.Graphics.DrawRectangle(playerPen, l.hb);
                if (l.hb.Right <= 0)
                {
                    laserToRemove = l;
                }
                if (player.hb.IntersectsWith(l.hb))
                {
                    //GameOver();
                    if (!endGame && curntMech == "none")
                    {
                        spdStorage = backgroundMoveSpd;
                        endGame    = true;
                        bounce     = (this.Height - player.y) / 2;
                    }
                    else if (curntMech != "none")
                    {
                        toClearLsers = true;
                        grounded     = false;
                        curntMech    = "none";
                    }
                }
            }
            if (toClearLsers)
            {
                lasers.Clear();
                rockets.Clear();
                toClearLsers = false;
            }
            List <Classes.coin> delete = new List <Classes.coin>();

            foreach (Classes.coin c in coins)
            {
                if (c.hb.IntersectsWith(player.hb))
                {
                    coinScore++;
                    //coinToRemove = c;
                    delete.Add(c);
                }
                else
                {
                    c.move();
                    e.Graphics.FillEllipse(coinBrush, c.hb);
                    if (c.hb.Right <= 0)
                    {
                        //coinToRemove = c;
                        delete.Add(c);
                    }
                }
            }
            foreach (Classes.mechToken m in MTokens)
            {
                if (m.hb.IntersectsWith(player.hb))
                {
                    MTokenToRemove = m;
                    curntMech      = m.type;
                    lasers.Clear();
                    rockets.Clear();
                }
                else
                {
                    m.move();
                    e.Graphics.FillRectangle(coinBrush, m.hb);
                    if (m.hb.Right <= 0)
                    {
                        MTokenToRemove = m;
                    }
                }
                if (upgrades["xray"])
                {
                    string s = "";
                    Font   f = new Font(Font.FontFamily, 20);
                    if (m.type == "teleporter")
                    {
                        s = "T";
                    }
                    else if (m.type == "superJump")
                    {
                        s = "S";
                    }
                    else if (m.type == "gravity")
                    {
                        s = "G";
                    }
                    e.Graphics.DrawString(s, f, new SolidBrush(Color.Black), m.hb.X + 10, m.hb.Y + 10);
                }
            }
            e.Graphics.DrawString("Coins " + coinScore, Font, new SolidBrush(Color.White), 0, 10);
            e.Graphics.DrawString("Distance " + actualDist, Font, new SolidBrush(Color.White), 0, 20);
            RemoveLaser(laserToRemove);
            RemoveCoin(delete);
            RemoveMToken(MTokenToRemove);
            MTokenToRemove = null;
            coinToRemove   = null;
            laserToRemove  = null;
        }
示例#3
0
        private void GameScreen_Paint(object sender, PaintEventArgs e)
        {
            SolidBrush g = new SolidBrush(Color.Green);
            SolidBrush b = new SolidBrush(Color.SkyBlue);

            e.Graphics.FillRectangle(g, 0, this.Height - 100, this.Width, 100);
            e.Graphics.FillRectangle(b, 0, 0, this.Width, this.Height - 100);

            e.Graphics.DrawRectangle(new Pen(Color.Black), cloudX, 50, 100, 50);
            if (!started)
            {
                Font s = new Font(Font.FontFamily, 20);

                e.Graphics.DrawString("Press Space to Play!", s, new SolidBrush(Color.Black), (this.Width - 300) / 2, 100);
            }
            if (!up && !grounded)
            {
                frame = 9;
            }
            if (up && curntMech != "superJump")
            {
                frame = 8;
            }
            if (grounded && !up && tick % 4 == 0)
            {
                frame++;
            }
            if (curntMech == "superJump" && tick % 4 == 0)
            {
                frame++;
            }
            if (endGame)
            {
                frame = 10;
            }
            switch (curntMech)
            {
            case "none":
                frameCount = gifImage.GetFrameCount(dimension);
                if (frame >= 8 && grounded && !up && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(gifImage, player.hb);
                gifImage.SelectActiveFrame(dimension, frame);

                break;

            case "teleporter":
                e.Graphics.DrawImage(Properties.Resources.teleporter, player.hb.X, player.hb.Y);
                break;

            case "superJump":
                frameCount = spImage.GetFrameCount(dimension);
                if (frame >= 8 && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(spImage, player.x, player.y);
                spImage.SelectActiveFrame(spdimension, frame);

                break;

            case "gravity":
                frameCount = gImage.GetFrameCount(dimension);
                if (frame >= 8 && grounded && !up && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(gImage, player.x, player.y);
                gImage.SelectActiveFrame(gdimension, frame);

                break;
            }



            if (curntMech == "teleporter")
            {
                teleporterDraw(e.Graphics, teleporterMarkerY);
            }
            foreach (Classes.rocket l in rockets)
            {
                if (l.launchingRocket && l.launchingTicks < 180)
                {
                    l.launchingTicks++;
                    l.hb.Y = player.y + 25;
                    l.y    = player.y + 25;
                    e.Graphics.DrawImage(l.i, l.hb);
                }
                if (l.launchingTicks == 180 && l.launchingRocket)
                {
                    l.hb.Y            = player.y + 25;
                    l.y               = player.y + 25;
                    l.launchingRocket = false;
                }
                if (!l.launchingRocket)
                {
                    l.move();
                    e.Graphics.DrawImage(l.i, l.hb);
                    if (l.hb.Right <= 0)
                    {
                        rocketToRemove = l;
                    }
                    if (player.hb.IntersectsWith(l.hb))
                    {
                        //GameOver();
                        if (!endGame && curntMech == "none")
                        {
                            endGame = true;
                            death.Stop();
                            death.Play();
                            spdStorage = backgroundMoveSpd;
                            bounce     = (this.Height - player.y) / 2;
                        }
                        else if (curntMech != "none")
                        {
                            broken.Stop();
                            broken.Play();
                            toClearLsers = true;
                            grounded     = false;
                            curntMech    = "none";
                        }
                    }
                }
            }

            foreach (Classes.laser l in lasers)
            {
                l.move();
                e.Graphics.DrawImage(l.i, l.hb);
                if (l.hb.Right <= 0)
                {
                    laserToRemove = l;
                }
                if (player.hb.IntersectsWith(l.hb))
                {
                    //GameOver();
                    if (!endGame && curntMech == "none")
                    {
                        death.Stop();
                        death.Play();
                        spdStorage = backgroundMoveSpd;
                        endGame    = true;
                        bounce     = (this.Height - player.y) / 2;
                    }
                    else if (curntMech != "none")
                    {
                        broken.Stop();
                        broken.Play();
                        toClearLsers = true;
                        grounded     = false;
                        curntMech    = "none";
                    }
                }
            }
            if (toClearLsers)
            {
                lasers.Clear();
                rockets.Clear();
                toClearLsers = false;
            }
            List <Classes.coin> delete = new List <Classes.coin>();

            foreach (Classes.coin c in coins)
            {
                if (c.hb.IntersectsWith(player.hb))
                {
                    coinScore++;
                    //coinToRemove = c;
                    delete.Add(c);
                }
                else
                {
                    c.move();
                    e.Graphics.FillEllipse(coinBrush, c.hb);
                    if (c.hb.Right <= 0)
                    {
                        //coinToRemove = c;
                        delete.Add(c);
                    }
                }
            }
            foreach (Classes.mechToken m in MTokens)
            {
                if (m.hb.IntersectsWith(player.hb))
                {
                    MTokenToRemove = m;
                    curntMech      = m.type;
                    lasers.Clear();
                    rockets.Clear();
                    broken.Play();
                }
                else
                {
                    m.move();
                    e.Graphics.FillRectangle(coinBrush, m.hb);
                    if (m.hb.Right <= 0)
                    {
                        MTokenToRemove = m;
                    }
                }
                if (upgrades["xray"])
                {
                    string s = "";
                    Font   f = new Font(Font.FontFamily, 20);
                    if (m.type == "teleporter")
                    {
                        s = "T";
                    }
                    else if (m.type == "superJump")
                    {
                        s = "S";
                    }
                    else if (m.type == "gravity")
                    {
                        s = "G";
                    }
                    e.Graphics.DrawString(s, f, new SolidBrush(Color.Black), m.hb.X + 10, m.hb.Y + 10);
                }
            }
            Font fr = new Font("Arial", 16);

            e.Graphics.DrawString("Coins " + coinScore, fr, new SolidBrush(Color.Black), 0, 10);
            e.Graphics.DrawString("Distance " + actualDist + "m", fr, new SolidBrush(Color.Black), 0, 30);
            RemoveLaser(laserToRemove);
            RemoveCoin(delete);
            RemoveMToken(MTokenToRemove);
            MTokenToRemove = null;
            coinToRemove   = null;
            laserToRemove  = null;
        }
示例#4
0
        private void GameScreen_Paint(object sender, PaintEventArgs e)
        {
            //draw sky
            SolidBrush g = new SolidBrush(Color.Green);
            SolidBrush b = new SolidBrush(Color.SkyBlue);

            e.Graphics.FillRectangle(g, 0, this.Height - 100, this.Width, 100);
            e.Graphics.FillRectangle(b, 0, 0, this.Width, this.Height - 100);
            e.Graphics.DrawImage(Properties.Resources.cloud, cloudX, 50, 100, 50); //clouds

            if (!started)                                                          // display startup message
            {
                Font s = new Font(Font.FontFamily, 20);

                e.Graphics.DrawString("Press Green to Play!", s, new SolidBrush(Color.Black), (this.Width - 300) / 2, 100);
            }
            //decides animation frames
            if (!up && !grounded)
            {
                frame = 9;
            }
            if (up && curntMech != "superJump")
            {
                frame = 8;
            }
            if (grounded && !up && tick % 4 == 0)
            {
                frame++;
            }
            if (curntMech == "superJump" && tick % 4 == 0)
            {
                frame++;
            }
            if (endGame)
            {
                frame = 10;
            }

            switch (curntMech) //draws image based on mech/character
            {
            case "none":
                frameCount = gifImage.GetFrameCount(dimension);
                if (frame >= 8 && grounded && !up && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(gifImage, player.hb);
                gifImage.SelectActiveFrame(dimension, frame);
                break;

            case "teleporter":
                e.Graphics.DrawImage(Properties.Resources.teleporter, player.hb.X, player.hb.Y);
                break;

            case "superJump":
                frameCount = spImage.GetFrameCount(dimension);
                if (frame >= 8 && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(spImage, player.x, player.y);
                spImage.SelectActiveFrame(spdimension, frame);
                break;

            case "gravity":
                frameCount = gImage.GetFrameCount(dimension);
                if (frame >= 8 && grounded && !up && !endGame)
                {
                    frame = 0;
                }
                e.Graphics.DrawImage(gImage, player.x, player.y);
                gImage.SelectActiveFrame(gdimension, frame);
                break;
            }

            if (curntMech == "teleporter")
            {
                teleporterDraw(e.Graphics, teleporterMarkerY);                            // draws teleporter cursor
            }
            foreach (Classes.rocket l in rockets)
            {
                if (l.launchingRocket && l.launchingTicks < 180) // displays warning, and tracks player
                {
                    l.launchingTicks++;
                    l.hb.Y = player.y + 25;
                    l.y    = player.y + 25;
                    e.Graphics.DrawImage(l.i, l.hb);
                }
                if (l.launchingTicks == 180 && l.launchingRocket) // sets rocket to player location
                {
                    l.hb.Y            = player.y + 25;
                    l.y               = player.y + 25;
                    l.launchingRocket = false;
                }
                if (!l.launchingRocket) // shoots rocket at player
                {
                    l.move();
                    e.Graphics.DrawImage(l.i, l.hb);

                    if (l.hb.Right <= 0)
                    {
                        rocketToRemove = l;                  // out of bounds, delete
                    }
                    if (player.hb.IntersectsWith(l.hb))      // if hits player, kill player and delete
                    {
                        if (!endGame && curntMech == "none") // kill
                        {
                            endGame = true;
                            death.Stop();
                            death.Play();
                            spdStorage = backgroundMoveSpd;
                            bounce     = (this.Height - player.y) / 2;
                        }
                        else if (curntMech != "none") // destroy mech instead of killing
                        {
                            broken.Stop();
                            broken.Play();
                            toClearLsers = true; // clears all objects
                            grounded     = false;
                            curntMech    = "none";
                        }
                    }
                }
            }

            foreach (Classes.laser l in lasers)
            {
                l.move();
                e.Graphics.DrawImage(l.i, l.hb); //display laser

                if (l.hb.Right <= 0)
                {
                    laserToRemove = l;                   // remove if out of bounds
                }
                if (player.hb.IntersectsWith(l.hb))      //if hits player
                {
                    if (!endGame && curntMech == "none") // kill player
                    {
                        death.Stop();
                        death.Play();
                        spdStorage = backgroundMoveSpd;
                        endGame    = true;
                        bounce     = (this.Height - player.y) / 2;
                    }
                    else if (curntMech != "none") //destroy mech
                    {
                        broken.Stop();
                        broken.Play();
                        toClearLsers = true;
                        grounded     = false;
                        curntMech    = "none";
                    }
                }
            }

            if (toClearLsers)
            {
                lasers.Clear();
                rockets.Clear();
                toClearLsers = false;
            }

            List <Classes.coin> delete = new List <Classes.coin>(); // coins to delete

            foreach (Classes.coin c in coins)
            {
                if (c.hb.IntersectsWith(player.hb)) // if player hits coins
                {
                    coinScore++;
                    //coinToRemove = c;
                    delete.Add(c);
                }
                else
                {
                    c.move(); // move and draw
                    e.Graphics.FillEllipse(coinBrush, c.hb);

                    if (c.hb.Right <= 0) // if ooB, delete
                    {
                        delete.Add(c);
                    }
                }
            }

            foreach (Classes.mechToken m in MTokens)
            {
                if (m.hb.IntersectsWith(player.hb)) //if player hits mech token
                {
                    MTokenToRemove = m;
                    curntMech      = m.type; // set player mech to token type
                    lasers.Clear();
                    rockets.Clear();
                    broken.Play();
                }
                else
                {
                    m.move();
                    e.Graphics.FillRectangle(coinBrush, m.hb); //move and draw

                    if (m.hb.Right <= 0)                       // if ooB, delete
                    {
                        MTokenToRemove = m;
                    }
                }

                if (upgrades["xray"]) // if xray is bought, you can see the type of mech token
                {
                    string s = "";
                    Font   f = new Font(Font.FontFamily, 20);

                    if (m.type == "teleporter")
                    {
                        s = "T";
                    }
                    else if (m.type == "superJump")
                    {
                        s = "S";
                    }
                    else if (m.type == "gravity")
                    {
                        s = "G";
                    }

                    e.Graphics.DrawString(s, f, new SolidBrush(Color.Black), m.hb.X + 10, m.hb.Y + 10);
                }
            }
            //draws coin and distance
            Font fr = new Font("Arial", 16);

            e.Graphics.DrawString("Coins " + coinScore, fr, new SolidBrush(Color.Black), 0, 10);
            e.Graphics.DrawString("Distance " + actualDist + "m", fr, new SolidBrush(Color.Black), 0, 30);

            //removes objects
            RemoveLaser(laserToRemove);
            RemoveCoin(delete);
            RemoveMToken(MTokenToRemove);
            MTokenToRemove = null;
            laserToRemove  = null;
        }