Exemple #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            snakeBlock1.Update();
            food1.Update();

            mySnake.Erase(gfx);
            mySnake.Update(gfx);
            for (int i = mySnake.SnakeList.Count - 1; i > 0; i--)
            {
                mySnake.SnakeList[i].Direction = mySnake.SnakeList[i - 1].Direction;
            }

            mySnake.Draw(gfx);

            if (snakeBlock1.BoundingBox.IntersectsWith(food1.BoundingBox))
            {
                food1.Erase(gfx);
                food1.X   = rand.Next(0, ClientSize.Width - food1.Diameter);
                food1.Y   = rand.Next(0, ClientSize.Height - food1.Diameter);
                lastPiece = mySnake.SnakeList[mySnake.SnakeList.Count - 1];
                newPiece  = new SnakeBlock();
                //0 = up, 1 = left, 2 = down, 3 = right
                if (lastPiece.Direction == 0) //UP
                {
                    newPiece.Load(lastPiece.X, lastPiece.Y + lastPiece.Diameter + 1, lastPiece.Diameter, Color.Blue, this.BackColor);
                }
                else if (lastPiece.Direction == 1) //LEFT
                {
                    newPiece.Load(lastPiece.X + lastPiece.Diameter + 1, lastPiece.Y, lastPiece.Diameter, Color.Blue, this.BackColor);
                }
                else if (lastPiece.Direction == 2) //DOWN
                {
                    newPiece.Load(lastPiece.X, lastPiece.Y - lastPiece.Diameter - 1, lastPiece.Diameter, Color.Blue, this.BackColor);
                }
                else if (lastPiece.Direction == 3) //RIGHT
                {
                    newPiece.Load(lastPiece.X - lastPiece.Diameter - 1, lastPiece.Y, lastPiece.Diameter, Color.Blue, this.BackColor);
                }


                newPiece.Direction = lastPiece.Direction;
                mySnake.SnakeList.Add(newPiece);
            }



            if (snakeBlock1.X > ClientSize.Width || snakeBlock1.X + snakeBlock1.Diameter < 0 || snakeBlock1.Y + snakeBlock1.Diameter < 0 || snakeBlock1.Y > ClientSize.Height)
            {
                //stupid me i forgot how to do dis
                //u lose teehee
                snakeBlock1.Erase(gfx);
                timer1.Enabled = false;
                MessageBox.Show("You lose");
                snakeBlock1.X         = 400;
                snakeBlock1.Y         = 300;
                snakeBlock1.Direction = 0;
                startButton.Visible   = true;
                mySnake.SnakeList.Clear();
                mySnake.SnakeList.Add(snakeBlock1);
                this.Refresh();
                //add gamestates(put a start comma lose introduction of the lakhro;aiwhjtroiajidoawierht_(*&KJEHE%**(Yjhlkau4tyiu**(*%#_)*$(@*_+LKDJF:L:)))
            }

            food1.Draw(gfx);
        }
Exemple #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //erase, move, draw
            gfx.Clear(BackColor);
            if (universe_size <= minuni && universe_size < olduni)
            {
                x             = 1;
                universe_size = minuni;
                olduni        = 0;
            }
            if (universe_size >= maxuni && universe_size > olduni)
            {
                x = -1;
            }
            else if (universe_size / 2 > 300)
            {
                brush = Brushes.Black;
            }
            else if (universe_size / 2 > 200)
            {
                brush = Brushes.DarkGray;
            }
            else if (universe_size / 2 > 150)
            {
                brush = Brushes.LightYellow;
            }
            else if (universe_size / 2 > 100)
            {
                brush = Brushes.Yellow;
            }
            else if (universe_size / 2 > 25)
            {
                brush = Brushes.Gold;
            }
            if (universe_size > 0)
            {
                olduni = universe_size;
            }
            if (x == 1)
            {
                universe_size = (float)Math.Pow(universe_size + 2, Math.Sqrt(1.00011));
            }
            else
            {
                universe_size = (float)Math.Pow(universe_size - 2, Math.Sqrt(1 / 1.00011));
            }
            if (Player.pieces[0].rect.IntersectsWith(food.foodbox))
            {
                Score.Text = Convert.ToString(Convert.ToInt32(Score.Text) + 10);
                Food.generate(rand, universe_size / 2, ClientSize);
                if (Player.pieces.Last()._direction == SnakePiece.Direction.Left)
                {
                    Player.pieces.Add(new SnakePiece(new Point(Player.pieces.Last()._location.X + 8, Player.pieces.Last()._location.Y), Player.pieces.Last()._size, Player.pieces.Last()._color, Player.pieces[Player.pieces.Count - 1].Direct));
                }
                if (Player.pieces.Last()._direction == SnakePiece.Direction.Right)
                {
                    Player.pieces.Add(new SnakePiece(new Point(Player.pieces.Last()._location.X - 8, Player.pieces.Last()._location.Y), Player.pieces.Last()._size, Player.pieces.Last()._color, Player.pieces[Player.pieces.Count - 1].Direct));
                }
                if (Player.pieces.Last()._direction == SnakePiece.Direction.Up)
                {
                    Player.pieces.Add(new SnakePiece(new Point(Player.pieces.Last()._location.X, Player.pieces.Last()._location.Y + 8), Player.pieces.Last()._size, Player.pieces.Last()._color, Player.pieces[Player.pieces.Count - 1].Direct));
                }
                if (Player.pieces.Last()._direction == SnakePiece.Direction.Down)
                {
                    Player.pieces.Add(new SnakePiece(new Point(Player.pieces.Last()._location.X, Player.pieces.Last()._location.Y - 8), Player.pieces.Last()._size, Player.pieces.Last()._color, Player.pieces[Player.pieces.Count - 1].Direct));
                }
                minuni       += 7;
                maxuni       += 3;
                universe_size = olduni;
                if (rand.Next(10, 12) == 10)
                {
                    antinu.generate(rand, universe_size / 2, ClientSize);
                }
            }
            gfx.FillEllipse(brush, (ClientSize.Width / 2 - universe_size / 2), (ClientSize.Height / 2 - universe_size / 2), universe_size, universe_size);
            for (int i = 1; i < Player.pieces.Count; i++)
            {
                if (Player.pieces[0].rect.IntersectsWith(Player.pieces[i].rect))
                {
                    antinu.pieces.Clear();
                    Player.pieces[0]._location = new Point(ClientSize.Width / 2 - Player.pieces[0]._size.Height / 2, ClientSize.Height / 2 - Player.pieces[0]._size.Width / 2);
                    Player.pieces.RemoveRange(1, Player.pieces.Count - 1);
                    Player.pieces[0].Direct = SnakePiece.Direction.None;
                    x             = 1;
                    universe_size = minuni;
                    olduni        = 0;
                    Food.generate(rand, universe_size / 2, ClientSize);
                    maxuni     = 700;
                    minuni     = 55;
                    Score.Text = "0";
                }
            }
            Player.Move(ClientSize);
            Player.ChangeDirection();
            if (Math.Sqrt(Math.Pow(Player.pieces[0]._location.X - (ClientSize.Width / 2), 2) + Math.Pow(Player.pieces[0]._location.Y - (ClientSize.Height / 2), 2)) > universe_size / 2 && universe_size > 55)
            {
                antinu.pieces.Clear();
                Player.pieces[0]._location = new Point(ClientSize.Width / 2 - Player.pieces[0]._size.Height / 2, ClientSize.Height / 2 - Player.pieces[0]._size.Width / 2);
                Player.pieces.RemoveRange(1, Player.pieces.Count - 1);
                Player.pieces[0].Direct = SnakePiece.Direction.None;
                x             = 1;
                universe_size = minuni;
                olduni        = 0;
                Food.generate(rand, universe_size / 2, ClientSize);
                maxuni     = 700;
                minuni     = 55;
                Score.Text = "0";
            }
            if (Math.Sqrt(Math.Pow(food.x - (ClientSize.Width / 2), 2) + Math.Pow(food.y - (ClientSize.Height / 2), 2)) > universe_size / 2 && universe_size > 15 && universe_size < olduni)
            {
                Food.generate(rand, minuni, ClientSize);
            }
            for (int i = 0; i < antinu.pieces.Count; i++)
            {
                if (Math.Sqrt(Math.Pow(antinu.pieces[i]._location.X - (ClientSize.Width / 2), 2) + Math.Pow(antinu.pieces[i]._location.Y - (ClientSize.Height / 2), 2)) > universe_size / 2 && universe_size > 15 && universe_size < olduni)
                {
                    antinu.pieces.RemoveAt(i);
                    if (rand.Next(0, 2) == 1)
                    {
                        antinu.generate(rand, universe_size / 2, ClientSize);
                    }
                }
            }

            for (int i = 0; i < antinu.pieces.Count; i++)
            {
                if (antinu.pieces[i].aunti.IntersectsWith(Player.pieces[0].rect))
                {
                    if (Player.pieces.Count > 1)
                    {
                        Score.Text = Convert.ToString(Convert.ToInt32(Score.Text) - 10);
                        antinu.pieces.RemoveAt(i);
                        Player.pieces.RemoveAt(Player.pieces.Count - 1);
                        minuni -= 7;
                        maxuni -= 3;
                    }
                    else
                    {
                        antinu.pieces.Clear();
                        Player.pieces[0]._location = new Point(ClientSize.Width / 2 - Player.pieces[0]._size.Height / 2, ClientSize.Height / 2 - Player.pieces[0]._size.Width / 2);
                        Player.pieces.RemoveRange(1, Player.pieces.Count - 1);
                        Player.pieces[0].Direct = SnakePiece.Direction.None;
                        x             = 1;
                        universe_size = minuni;
                        olduni        = 0;
                        Food.generate(rand, universe_size / 2, ClientSize);
                        maxuni     = 700;
                        minuni     = 55;
                        Score.Text = "0";
                    }
                }
            }
            antinu.Draw(gfx);
            Player.Draw(gfx);
            Food.Draw(gfx);
            bitBox.Image = map;
        }