Exemplo n.º 1
0
		void ICmpInitializable.OnShutdown(Component.ShutdownContext context)
		{
			if (context == ShutdownContext.Deactivate)
			{
				blocks.Remove(this);
				if (activeBlock == this) activeBlock = null;
			}
		}
Exemplo n.º 2
0
		void ICmpInitializable.OnInit(Component.InitContext context)
		{
			if (context == InitContext.Activate)
			{
				blocks.Add(this);
				activeBlock = this;
			}
		}
Exemplo n.º 3
0
        void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
        {
            if (args.CollisionData.NormalSpeed > 1.0f && this.GameObj.Transform.Vel.Length > 0.5f)
            {
                SoundInstance collisionSound = DualityApp.Sound.PlaySound(GameRes.Data.Sound.BlockCollide_Sound);
                collisionSound.Pitch = MathF.Rnd.NextFloat(0.8f, 1.25f);
                collisionSound.Volume = MathF.Clamp(args.CollisionData.NormalSpeed / 5.0f, 0.0f, 0.5f);
            }

            if (activeBlock == this && timeFirstContact == 0.0f && MathF.Abs(args.CollisionData.Normal.Y) > 0.05f)
            {
                this.timeFirstContact = Time.GameTimer;
                this.angleFirstTimeHit = this.GameObj.Transform.Angle;
                if (this.GameObj.Transform.Pos.Y <= -500) GameController.Instance.NotifyGameOver();
                this.GameObj.GetComponent<Collider>().IgnoreGravity = false;
                this.GameObj.GetComponent<Collider>().FixedAngle = false;
            }

            if (this.timeFirstContact != 0.0f && Time.GameTimer - timeFirstContact < 3000.0f && this.GameObj.Transform.Vel.Length <= 0.1f)
            {
                float angleDistFromSetup = MathF.CircularDist(this.angleFirstTimeHit, this.GameObj.Transform.Angle);
                if (angleDistFromSetup >= MathF.Pi * 0.1f) GameController.Instance.NotifyBlockFellOver(this.GameObj);
            }
        }
Exemplo n.º 4
0
 void ICmpInitializable.OnShutdown(Component.ShutdownContext context)
 {
     if (context == ShutdownContext.Deactivate)
     {
         if (instance == this)
         {
             instance = null;
             DualityApp.Keyboard.KeyDown -= this.Keyboard_KeyDown;
         }
     }
 }
Exemplo n.º 5
0
        void ICmpInitializable.OnInit(Component.InitContext context)
        {
            if (context == InitContext.Activate)
            {
                if (instance == null)
                {
                    instance = this;
                    DualityApp.Keyboard.KeyDown += this.Keyboard_KeyDown;

                    this.beginIntroTime = Time.GameTimer;

                    CommentGuy.Init(Scene.Current.AllObjects.FirstByName("Commentary").GetComponent<TextRenderer>());

                    // Play some music
                    SoundBudgetPad bgMusic = DualityApp.Sound.Music.Push(GameRes.Data.Music.tetrisloop_Sound, SoundBudgetPriority.Background, 0.0f);
                    bgMusic.Sound.Looped = true;

                    // Play some intro
                    if (this.FirstGameInSession) DualityApp.Sound.Music.Push(GameRes.Data.Music.tetrisintro_Sound, SoundBudgetPriority.Tension, 0.0f);
                }
            }
        }
Exemplo n.º 6
0
        //конструктор
        public Form1()
        {
            
            InitializeComponent();

            nextFigure = new NextFigure(this);

            //инициализация таймера
            timer = new Timer {Interval = speed};
            timer.Tick += (sender, args) =>
            {
                if (figure.Down()) ;
                else
                {
                    HorizontalRow();
                    GameOver();
                    figure = nextFigure.GetNext(this);
                }
                pictureBox1.Invalidate();
                PictureNextFigure.Invalidate();
            };

            //инициализация цвета отрисовки подквадрата
            myPen = new Pen(Color.Black)
            {
                LineJoin = LineJoin.Miter,
                Width = 2.0F
            };

            //отрисовка стакана и сетки
            pictureBox1.Image = (Image) new Bitmap(pictureBox1.Width, pictureBox1.Height);
            var g = Graphics.FromImage(pictureBox1.Image);
            var p = new Pen(Color.DarkSlateGray);
            for (var i = 0; i < 10; i++)
                g.DrawLine(p, pictureBox1.Width/10*(i + 1), 0, pictureBox1.Width/10*(i + 1), pictureBox1.Height);
            for (var i = 0; i < 20; i++)
                g.DrawLine(p, 0, pictureBox1.Height/20*(i + 1), pictureBox1.Width, pictureBox1.Height/20*(i + 1));

            //красная линия
            g.DrawLine(Pens.Red, 0, pictureBox1.Height/20*3, pictureBox1.Width, pictureBox1.Height/20*3);

            //инициализация массива/поля
            InitializeField();

            //текущий уровень сложности
            labelLevel.Text = $"Level: {level}";

            //инициализация массива координат следущей фигуры
            for (var i = 0; i < 3; i++)
                for (var j = 0; j < 4; j++)
                    smallField[i, j] = new Component((j * width) + 1, (i * width) + 1, Brushes.Black);

            //pictureBox на котором будет отображаться следущая фигура
            PictureNextFigure = new PictureBox
            {
                Location = new Point(324, 91),
                Size = new Size(101, 76),
                BackColor = Color.Black
            };

            //добавляем контрол к форме
            this.Controls.Add(PictureNextFigure);

            //обработчик перерисовки поля
            PictureNextFigure.Paint += (s, e) =>
            {
                for (var i = 0; i < 3; i++)
                    for (var j = 0; j < 4; j++)
                    {
                        //если в текущей клетке стоит фигура рисуем квадрат
                        if (smallField[i, j].brush != Brushes.Black)
                        {
                            e.Graphics.FillRectangle(smallField[i, j].brush
                            , smallField[i, j].x, smallField[i, j].y, width - 1, width - 1);
                            //и подквадрат
                            e.Graphics.DrawRectangle(myPen, smallField[i, j].x + 3, smallField[i, j].y + 3, 
                                width - 7, width - 7);
                        }
                    }
            };

            labelPause.Text = @"TETRIS";
            labelPause.Visible = true;
            soundControl.playMain();
        }
Exemplo n.º 7
0
 //инициализация массива/поля
 private void InitializeField()
 {
     for (var i = 0; i < 20; i++)
         for (var j = 0; j < 10; j++)
             field[i, j] = new Component((j * width) + 1, (i * width) + 1, Brushes.Black);
 }
Exemplo n.º 8
0
 void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args)
 {
 }