Advertisement
RastHacker

Form2.cs

Oct 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace Matrix4
  14. {
  15.     public partial class Form2 : Form
  16.     {
  17.         Timer _spawnTimer = new Timer();
  18.         Timer _checkTimers = new Timer();
  19.         List<Spawn> _spawnList = new List<Spawn>();
  20.         List<Timer> _timerList = new List<Timer>();
  21.        
  22.         private Graphics _myGrpahics;
  23.  
  24.         public Form2()
  25.         {
  26.             InitializeComponent();
  27.  
  28.             _spawnTimer.Interval = 500;
  29.             _spawnTimer.Tick += _spawnTimer_Tick;
  30.  
  31.             _checkTimers.Interval = 100;
  32.             _checkTimers.Tick += _checkTimers_Tick;
  33.  
  34.             this.Paint += Form2_Paint;
  35.         }
  36.  
  37.         private void _checkTimers_Tick(object sender, EventArgs e)
  38.         {
  39.             if (!_spawnTimer.Enabled)
  40.             {
  41.                 int _result = 0;
  42.  
  43.                 foreach (Timer timer in _timerList)
  44.                 {
  45.                     if (timer.Enabled)
  46.                     {
  47.                         _result += 1;
  48.                     }
  49.                 }
  50.  
  51.                 if (_result > 0)
  52.                 {
  53.                     Console.WriteLine(_result + " Timers left for " + _spawnList.Count + " Spawns");
  54.                 }
  55.             }
  56.         }
  57.  
  58.         private void _spawnTimer_Tick(object sender, EventArgs e)
  59.         {
  60.             for (int i = 0; i < 3; i+=1)
  61.             {
  62.                 Spawn _spawn = new Spawn(this);
  63.  
  64.                 _spawn._onSpawn = true;
  65.                 _spawn._spawned = true;
  66.                 _spawn._waitTo = false;
  67.                 _spawn._onDespawn = false;
  68.  
  69.                 Random _theRandom = new Random();
  70.  
  71.                 int _Size = _theRandom.Next(10, 30);
  72.  
  73.                 _spawn._width = _Size;
  74.                 _spawn._height = _Size;
  75.  
  76.                 _spawn._waitValue = 50;
  77.  
  78.                 int _speedIntervalSetting = (_Size * 20) / 3;
  79.  
  80.                 if (_speedIntervalSetting < 1)
  81.                 {
  82.                     _speedIntervalSetting = 1;
  83.                 }
  84.  
  85.                 _spawn._speedInterval = _speedIntervalSetting;
  86.  
  87.                 _spawn._x = _theRandom.Next(this.Width);
  88.                 _spawn._y = _theRandom.Next(-(this.Height / 2), this.Height / 2);
  89.  
  90.                 _spawn._colorValue = _theRandom.Next(90, 200);
  91.                 _spawn._currColorValue = 10;
  92.                 _spawn._colorStepValue = 35;
  93.  
  94.                 _spawn._startSpawn();
  95.  
  96.                 _spawnList.Add(_spawn);
  97.                 //Console.WriteLine("there is " + _spawnList.Count + " Spawn for now");
  98.             }
  99.         }
  100.  
  101.         private void Form2_Paint(object sender, PaintEventArgs e)
  102.         {
  103.             _myGrpahics = Graphics.FromHwnd(this.Handle);
  104.  
  105.             _checkTimers.Start();
  106.         }
  107.  
  108.         private void Form2_Load(object sender, EventArgs e)
  109.         {
  110.  
  111.         }
  112.  
  113.         private void label1_Click(object sender, EventArgs e)
  114.         {
  115.             if (_spawnTimer.Enabled)
  116.             {
  117.                 _spawnTimer.Stop();
  118.                 label1.Text = "Start";
  119.  
  120.                 Timer _waitT = new Timer();
  121.  
  122.                 _waitT.Interval = 2000;
  123.                 _waitT.Tick += delegate(object o, EventArgs args)
  124.                 {
  125.                     try
  126.                     {
  127.                         foreach (var timer in _timerList)
  128.                         {
  129.                             timer.Stop();
  130.                         }
  131.                     }
  132.                     catch (Exception)
  133.                     {
  134.  
  135.                     }
  136.  
  137.                     Console.WriteLine("All timers cleared");
  138.                     this.Invalidate();
  139.                     _waitT.Stop();
  140.                 };
  141.  
  142.                 _waitT.Start();
  143.             }
  144.             else
  145.             {
  146.                 _spawnTimer.Start();
  147.                 label1.Text = "Stop";
  148.             }
  149.         }
  150.  
  151.         private void textBox1_TextChanged(object sender, EventArgs e)
  152.         {
  153.             try
  154.             {
  155.                 _spawnTimer.Interval = Int32.Parse(textBox1.Text);
  156.                 textBox1.BackColor = Color.White;
  157.             }
  158.             catch (Exception)
  159.             {
  160.                 textBox1.BackColor = Color.Pink;
  161.             }
  162.         }
  163.  
  164.         public void addTimerToList(Timer _timer)
  165.         {
  166.             _timerList.Add(_timer);
  167.         }
  168.     }
  169.  
  170.     public class Spawn
  171.     {
  172.         Timer mainTimer = new Timer();
  173.         Graphics _myGraphics;
  174.  
  175.         private List<char> _charList = new List<char>();
  176.  
  177.         public bool _onSpawn = false;
  178.         public bool _spawned = false;
  179.         public bool _waitTo = false;
  180.         public bool _onDespawn = false;
  181.         private bool _isDespawing = false;
  182.         private bool _deSpawnFinished = false;
  183.  
  184.         public int _width;
  185.         public int _height;
  186.         public int _x;
  187.         public int _startY;
  188.         private int _endY;
  189.         public int _y;
  190.         public int _colorValue;
  191.         public int _currColorValue;
  192.         public int _waitValue;
  193.         private int _currWaitValue;
  194.         public int _colorStepValue;
  195.         public int _speedInterval = 1;
  196.         private int _maxColorValue = 0;
  197.         private int _previousColorValue = 0;
  198.         private char _theChooserChar;
  199.         private int _maxHeightValue;
  200.         private int _currRepeatCount = 0;
  201.         private int _currLocation;// = _startY - 10;
  202.         private int _curr2 = 0;
  203.  
  204.         Form2 _currForm;
  205.  
  206.         public Spawn(Form2 form1)
  207.         {
  208.             _currForm = form1;
  209.             _currForm.addTimerToList(mainTimer);
  210.  
  211.             _maxHeightValue = _currForm.Height;// + _height*2;//_currForm.Height/2;
  212.  
  213.             _myGraphics = Graphics.FromHwnd(_currForm.Handle);
  214.  
  215.             _charList = getCharList();
  216.  
  217.             mainTimer.Interval = _speedInterval;
  218.             mainTimer.Tick += MainTimer_Tick;
  219.         }
  220.  
  221.         private List<char> getCharList()
  222.         {
  223.             var _result = new List<char>();
  224.  
  225.             foreach (char c in Properties.Resources.charList.ToCharArray())
  226.             {
  227.                 _result.Add(c);
  228.             }
  229.  
  230.             return _result;
  231.         }
  232.  
  233.         private int getIndex()
  234.         {
  235.             int _result = 0;
  236.             Random _getIndexRandom = new Random();
  237.  
  238.             _result = _getIndexRandom.Next(_charList.Count - 1);
  239.  
  240.             if (_result < 0)
  241.             {
  242.                 _result = 0;
  243.             }
  244.  
  245.             return _result;
  246.         }
  247.  
  248.         private void MainTimer_Tick(object sender, EventArgs e)
  249.         {
  250.             if (_previousColorValue < _currColorValue)
  251.             {
  252.                 _maxColorValue = _currColorValue;
  253.             }
  254.             _previousColorValue = _currColorValue;
  255.  
  256.             if (_deSpawnFinished)
  257.             {
  258.                 mainTimer.Stop();
  259.             }
  260.  
  261.             if (_isDespawing)
  262.             {
  263.                 int _pathToTrace = _endY - _startY;
  264.                
  265.                 int _repeatCount = 2;
  266.  
  267.                 if (_currRepeatCount < _repeatCount)
  268.                 {
  269.                     if (_currLocation < _endY)
  270.                     {
  271.                         for (int i = 1; i < _repeatCount; i+=1)
  272.                         {
  273.                             _currLocation += (_height / 4) * 3;
  274.  
  275.                             Rectangle _main = new Rectangle(_x, _y, _width, _height);
  276.                             Rectangle _shadow = new Rectangle(_x, _currLocation, _width + (_width+0), _height+0);
  277.  
  278.                             Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular,
  279.                                 System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  280.  
  281.                             Color _selectedColor = new Color();
  282.  
  283.                             int _currCharIndex = getIndex();
  284.  
  285.                             if (_currColorValue - ((_currForm.Height / _height) * _height) > 0)
  286.                             {
  287.                                 _currColorValue = _currColorValue - (((_currForm.Height / _height) * _height) / 2);
  288.                             }
  289.                             else
  290.                             {
  291.                                 _currColorValue = 0;
  292.                             }
  293.  
  294.                             _selectedColor = Color.FromArgb(150, 0, _currColorValue, 0);
  295.  
  296.                             //_myGraphics.FillRectangle(Brushes.Black, _main);
  297.                             _myGraphics.FillRectangle(new SolidBrush(Color.FromArgb(new Random().Next(100, 200), 0, 0, 0)), _shadow);
  298.                             //_myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.White), _main);
  299.                             //_myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont,new SolidBrush(_selectedColor), _shadow);
  300.                         }
  301.  
  302.                         _curr2 += 1;
  303.                     }
  304.                     else
  305.                     {
  306.                         _currLocation = _startY-100;
  307.                         _currRepeatCount += 1;
  308.                         _curr2 = 0;
  309.                     }
  310.                 }
  311.                 else
  312.                 {
  313.                     _deSpawnFinished = true;
  314.                 }
  315.             }
  316.             else
  317.             {
  318.                 if (_y < _maxHeightValue)//+ _height*2)
  319.                 {
  320.                     _y += (_height/4)*3;
  321.  
  322.                     Rectangle _main = new Rectangle(_x, _y, _width, _height);
  323.                     Rectangle _shadow = new Rectangle(_x, _y - _height, _width, _height);
  324.  
  325.                     Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  326.  
  327.                     Color _selectedColor = new Color();
  328.  
  329.                     int _currCharIndex = getIndex();
  330.  
  331.                     if (_currColorValue - 10 > 0 && _currColorValue + 10 < 255)
  332.                     {
  333.                         _selectedColor = Color.FromArgb(0,
  334.                             new Random().Next(_currColorValue - 10, _currColorValue + 10), 0);
  335.                     }
  336.                     else
  337.                     {
  338.                         if (_currColorValue > 100)
  339.                         {
  340.                             _currColorValue = 255;
  341.                         }
  342.                         else
  343.                         {
  344.                             _currColorValue = 0;
  345.                         }
  346.                     }
  347.  
  348.                     _myGraphics.FillRectangle(Brushes.Black, _main);
  349.                     _myGraphics.FillRectangle(Brushes.Black, _shadow);
  350.                     _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.White), _main);
  351.                     _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(_selectedColor), _shadow);
  352.                 }
  353.                 else
  354.                 {
  355.                    
  356.                 }
  357.  
  358.                 if (_onSpawn)
  359.                 {
  360.                     if (_currColorValue < _colorValue)
  361.                     {
  362.                         _currColorValue += _colorStepValue;
  363.  
  364.                         Rectangle _main = new Rectangle(_x, _y, _width, _height);
  365.                         Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  366.  
  367.                         _myGraphics.FillRectangle(Brushes.Black, _main);
  368.                         _myGraphics.DrawString(_theChooserChar.ToString(), _mainFont, new SolidBrush(Color.FromArgb(0, _currColorValue, 0)), _main);
  369.                     }
  370.                     else
  371.                     {
  372.                         _onSpawn = false;
  373.                         //_spawned = true;
  374.                         _waitTo = true;
  375.                         _currWaitValue = 0;
  376.                     }
  377.                 }
  378.                 else
  379.                 {
  380.                     if (_spawned)
  381.                     {
  382.                         if (_waitTo)
  383.                         {
  384.                             if (_currWaitValue < _waitValue)
  385.                             {
  386.                                 //Console.WriteLine("Started wait to = " + _currWaitValue + " / " + _waitValue);
  387.                                 _currWaitValue += 1;
  388.                             }
  389.                             else
  390.                             {
  391.                                 //Console.WriteLine("Finished wait to");
  392.                                 _waitTo = false;
  393.                                 _endY = _y;
  394.                                 _currLocation = _startY - 100;
  395.                                 _isDespawing = true;
  396.                                 mainTimer.Interval = 1;
  397.                                 //_onDespawn = true;
  398.                             }
  399.                         }
  400.                         else
  401.                         {
  402.                             if (_onDespawn)
  403.                             {
  404.                                 if (!(_currColorValue - _colorStepValue < 0))
  405.                                 {
  406.                                     _currColorValue -= _colorStepValue;
  407.  
  408.                                     /*int _xVar = _currForm.Height / _height;
  409.                                     int _xFunc = _xVar * _height;
  410.  
  411.                                     for (int i = 1; i < _xFunc + 1; i += 1)
  412.                                     {
  413.                                         //System.Threading.Thread.Sleep(1);
  414.  
  415.                                         Rectangle _despawnShadow = new Rectangle(_x, _y + 100 - _height * i, _width, _height);
  416.                                         Font _mainFont = new Font("Microsoft Sans Serif", _width - 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  417.  
  418.                                         int _colorDespawnValue = (_maxColorValue / i);
  419.                                         int _currCharIndex = getIndex();
  420.  
  421.                                         if (!((_currColorValue - _colorDespawnValue) > 0))
  422.                                         {
  423.                                             _currColorValue = 0;
  424.                                         }
  425.  
  426.                                         _myGraphics.FillRectangle(Brushes.Black, _despawnShadow);
  427.                                         _myGraphics.DrawString(_charList[_currCharIndex].ToString(), _mainFont, new SolidBrush(Color.FromArgb(0, _currColorValue, 0)), _despawnShadow);
  428.                                     }*/
  429.                                 }
  430.                                 else
  431.                                 {
  432.                                     _currColorValue = 0;
  433.  
  434.                                     _onSpawn = false;
  435.                                     _spawned = false;
  436.                                     _waitTo = false;
  437.                                     _onDespawn = false;
  438.                                 }
  439.                             }
  440.                             else
  441.                             {
  442.                                 mainTimer.Stop();
  443.                             }
  444.                         }
  445.                     }
  446.                     else
  447.                     {
  448.  
  449.                     }
  450.                 }
  451.             }
  452.         }
  453.  
  454.         public void _startSpawn()
  455.         {
  456.             _startY = _y;
  457.             mainTimer.Start();
  458.         }
  459.     }
  460. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement