diff --git a/1/1.cs b/1/1.cs index ec8e919..661c605 100644 --- a/1/1.cs +++ b/1/1.cs @@ -119,17 +119,17 @@ namespace LaptopSimulator2015.Levels invadersBullets = invadersBullets.Except(bulletsToRemove.Distinct()).Distinct().ToList(); speedMod += 0.1; speedMod = Math.Max(Math.Min(speedMod, 5), 1); - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) invadersPlayer.Y -= speedMod; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) invadersPlayer.X -= speedMod; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) invadersPlayer.Y += speedMod; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) invadersPlayer.X += speedMod; - if (Input.IsKeyDown(Keys.Space) & invadersCanShoot) + if (Input.Action & invadersCanShoot) { - invadersBullets.Add(new Vector2(invadersPlayer)); + invadersBullets.Add(new Vector2(0, 2.5) + invadersPlayer); invadersCanShoot = false; speedMod--; } diff --git a/2/2.cs b/2/2.cs index af3fa6a..0a2cc8c 100644 --- a/2/2.cs +++ b/2/2.cs @@ -92,13 +92,13 @@ namespace LaptopSimulator2015.Levels else enemies.Add(new Vector2(0, tst - minigamePanel.Width * 2 - minigamePanel.Height + 10)); } - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) player.Y -= 5; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) player.X -= 5; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) player.Y += 5; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) player.X += 5; List enemiesToRemove = new List(); for (int i = 0; i < enemies.Count; i++) diff --git a/3/3.cs b/3/3.cs index 038b0af..be22d72 100644 --- a/3/3.cs +++ b/3/3.cs @@ -111,7 +111,7 @@ namespace LaptopSimulator2015.Levels } cannon = new Vector2(center); cannon.moveInDirection(Misc.deg2rad(playerRot), 20); - if (Input.IsKeyDown(Keys.Space)) + if (Input.Action) { firing = true; power = Math.Min(power + 5, 100); @@ -132,13 +132,13 @@ namespace LaptopSimulator2015.Levels } targ = new Vector2(center); targ.Tag = playerRot; - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) cannonL += 100 / power; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) cannonL -= 100 / power; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) playerRot += 80 / power; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) playerRot -= 80 / power; while (playerRot > 360) playerRot -= 360; diff --git a/Base/Input.cs b/Base/Input.cs index 4ef61d6..86f77c9 100644 --- a/Base/Input.cs +++ b/Base/Input.cs @@ -37,5 +37,11 @@ namespace Base return false; return IsKeyDown(k);*/ } + + public static bool Up => IsKeyDown(Keys.Up) || IsKeyDown(Keys.W); + public static bool Left => IsKeyDown(Keys.Left) || IsKeyDown(Keys.A); + public static bool Down => IsKeyDown(Keys.Down) || IsKeyDown(Keys.S); + public static bool Right => IsKeyDown(Keys.Right) || IsKeyDown(Keys.D); + public static bool Action => IsKeyDown(Keys.Space) || IsKeyDown(Keys.Q) || IsKeyDown(Keys.E); } } diff --git a/Base/Vector2.cs b/Base/Vector2.cs index bffb9b1..13ee933 100644 --- a/Base/Vector2.cs +++ b/Base/Vector2.cs @@ -20,17 +20,17 @@ namespace Base { if (bounds_wrap) { - if (bounds.Width < 0) + if (bounds.X != 0 & bounds.Width < 0) throw new ArgumentException("bounds.Width must be greater than or equal to 0"); while (bounds.X != 0 & x_unchecked > bounds.X + bounds.Width) x_unchecked -= bounds.Width; - while (x_unchecked < bounds.X) + while (bounds.X != 0 & x_unchecked < bounds.X) x_unchecked += bounds.Width; - if (bounds.Height < 0) + if (bounds.Y != 0 & bounds.Height < 0) throw new ArgumentException("bounds.Height must be greater than or equal to 0"); while (bounds.Y != 0 & y_unchecked > bounds.Y + bounds.Height) y_unchecked -= bounds.Height; - while (y_unchecked < bounds.Y) + while (bounds.Y != 0 & y_unchecked < bounds.Y) y_unchecked += bounds.Height; } else @@ -82,16 +82,24 @@ namespace Base Y = from.Y; } - public Vector2(Vector2 from) + public Vector2(Vector2 from, bool useProperties = false) { X = from.X; Y = from.Y; + if (useProperties) + { + Tag = from.Tag; + bounds = from.bounds; + bounds_wrap = from.bounds_wrap; + } } public Point toPoint() => new Point((int)Math.Round(X), (int)Math.Round(Y)); public PointF toPointF() => new PointF(Misc.d2f(X), Misc.d2f(Y)); public double distanceFromSquared(Vector2 other) => Math.Pow(X - other.X, 2) + Math.Pow(Y - other.Y, 2); public double distanceFrom(Vector2 other) => Math.Sqrt(distanceFromSquared(other)); + public double magnitude { get { return distanceFrom(Zero); } } + public double sqrMagnitude { get { return distanceFromSquared(Zero); } } public void moveInDirection(double radians = 0, double distance = 1) { X += Math.Cos(radians) * distance; @@ -118,10 +126,23 @@ namespace Base } } + public Vector2 addTag(object Tag) { this.Tag = Tag; return this; } + public Vector2 addBounds(Rectangle bounds) { this.bounds = bounds; return this; } + public Vector2 addBoundsW(bool bounds_wrap) { this.bounds_wrap = bounds_wrap; return this; } + public override string ToString() => "{X=" + X.ToString() + ", Y=" + Y.ToString() + "}"; - public static Vector2 operator +(Vector2 left, Vector2 right) => new Vector2(left.X + right.X, left.Y + right.Y); - public static Vector2 operator -(Vector2 left, Vector2 right) => new Vector2(left.X - right.X, left.Y - right.Y); - public static Vector2 operator *(Vector2 left, Vector2 right) => new Vector2(left.X * right.X, left.Y * right.Y); + public static Vector2 operator +(Vector2 left, Vector2 right) => new Vector2(left.X + right.X, left.Y + right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator +(Vector2 left, Point right) => new Vector2(left.X + right.X, left.Y + right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator +(Vector2 left, PointF right) => new Vector2(left.X + right.X, left.Y + right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator -(Vector2 left, Vector2 right) => new Vector2(left.X - right.X, left.Y - right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator -(Vector2 left, Point right) => new Vector2(left.X - right.X, left.Y - right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator -(Vector2 left, PointF right) => new Vector2(left.X - right.X, left.Y - right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator *(Vector2 left, Vector2 right) => new Vector2(left.X * right.X, left.Y * right.Y).addTag(left.Tag).addBounds(left.bounds).addBoundsW(left.bounds_wrap); + public static Vector2 operator *(Vector2 left, Point right) => new Vector2(left.X * right.X, left.Y * right.Y); + public static Vector2 operator *(Vector2 left, PointF right) => new Vector2(left.X * right.X, left.Y * right.Y); public static Vector2 operator /(Vector2 left, Vector2 right) => new Vector2(left.X / right.X, left.Y / right.Y); + public static Vector2 operator /(Vector2 left, Point right) => new Vector2(left.X / right.X, left.Y / right.Y); + public static Vector2 operator /(Vector2 left, PointF right) => new Vector2(left.X / right.X, left.Y / right.Y); + public static Vector2 operator ^(Vector2 left, double right) => new Vector2(Math.Pow(left.X, right), Math.Pow(left.Y, right)); } } diff --git a/LaptopSimulator2015.sln b/LaptopSimulator2015.sln index 94efc92..98e07a3 100644 --- a/LaptopSimulator2015.sln +++ b/LaptopSimulator2015.sln @@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lv3_t", "lv3_t\lv3_t.csproj EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3", "3\3.csproj", "{8109040E-9D8D-43E7-A461-83475B2939C9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lv4_t", "lv4_t\lv4_t.csproj", "{22D618C0-F0A4-417F-A815-C760BF4376B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +74,10 @@ Global {8109040E-9D8D-43E7-A461-83475B2939C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {8109040E-9D8D-43E7-A461-83475B2939C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {8109040E-9D8D-43E7-A461-83475B2939C9}.Release|Any CPU.Build.0 = Release|Any CPU + {22D618C0-F0A4-417F-A815-C760BF4376B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22D618C0-F0A4-417F-A815-C760BF4376B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22D618C0-F0A4-417F-A815-C760BF4376B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22D618C0-F0A4-417F-A815-C760BF4376B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -85,6 +91,7 @@ Global {0965C803-49B2-4311-B62F-1E60DBD9185F} = {83BF22F9-3A2D-42A3-9DB0-C1E2AA1DD218} {244E68E6-90D2-447D-B380-13CA8DD3D4EC} = {69DC5824-3F89-4B47-BF1A-F25942094195} {8109040E-9D8D-43E7-A461-83475B2939C9} = {83BF22F9-3A2D-42A3-9DB0-C1E2AA1DD218} + {22D618C0-F0A4-417F-A815-C760BF4376B2} = {69DC5824-3F89-4B47-BF1A-F25942094195} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9631F8FF-AFC1-4583-9D27-6C2D97D3A2E9} diff --git a/LaptopSimulator2015/CaptchaGenerator.cs b/LaptopSimulator2015/CaptchaGenerator.cs deleted file mode 100644 index e6125e6..0000000 --- a/LaptopSimulator2015/CaptchaGenerator.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LaptopSimulator2015 -{ - /// - /// Stellt Methoden und Eigenschaften zum erzeugen eines Captchas bereit. - /// - class CaptchaGenerator : IDisposable - { - protected Random rnd; - private Bitmap _Captcha = null; - - protected const int spacePerChar = 25;//Abstand zwischen den Zeichen - - protected void DrawChar(int c, Graphics g) - { - int y = rnd.Next(8, 13); - int fontSize = this.rnd.Next(12, 18); - //move rotation point to center of image - g.TranslateTransform(spacePerChar * (c) + 10, (30 - fontSize) / 2); - g.RotateTransform(rnd.Next(this.RotateRange.Min, this.RotateRange.Max)); - g.DrawString(GetRandomChar(), GetRandomFont(fontSize), GetRandomFontBrush(), new PointF(5, y)); - g.ResetTransform(); - } - - protected Font GetRandomFont(int fontSize) - { - return new Font(new string[] { "Arial", "Consolas", "Verdena" }[this.rnd.Next(3)], fontSize); - } - protected string GetRandomChar() - { - string s = this.Chars[this.rnd.Next(this.Chars.Length)].ToString(); - this.Text += s; - return s; - } - protected Brush GetRandomFontBrush() - { - int r = rnd.Next(0, 200); - int g = rnd.Next(0, (200 - r) / 2); - int b = 200 - r - g; - if (b < 0) - b = 0; - return new SolidBrush(Color.FromArgb(r, g, b)); - } - protected Brush GetRandomBackgroundHatchBrush() - { - return new HatchBrush((HatchStyle)this.rnd.Next(53), this.GetRandomBackgroundColor(), Color.Transparent); - } - protected Color GetRandomBackgroundColor() - { - int r = rnd.Next(180, 255); - int g = rnd.Next(180, 255); - int b = rnd.Next(180, 255); - return Color.FromArgb(r, g, b); - } - protected Brush GetRandomForegroundHatchBrush() - { - return new HatchBrush((HatchStyle)this.rnd.Next(53), this.GetRandomForegroundColor(), this.GetRandomForegroundColor()); - } - protected Color GetRandomForegroundColor() - { - int r = rnd.Next(180, 255); - int g = rnd.Next(180, 255); - int b = rnd.Next(180, 255); - return Color.FromArgb(this.rnd.Next(10, 50), r, g, b); - } - - #region .ctor - - private CaptchaGenerator() - { - this.RotateRange = new CaptchaCharRotateRange(-20, 20); - this.IntegrateHatch = true; - } - - /// - /// Initialisiert eine neue Instanz der CaptchaGenerator-Klasse. - /// - /// Die Länge der Zeichenkette im Captcha. - /// Die zu verwendenden Zeichen im Captcha. - public CaptchaGenerator(int length, string chars) - : this() - { - this.rnd = new Random(); - this.Length = length; - this.Chars = chars; - this.Generate(); - } - - #endregion - - #region Methoden - - /// - /// Erzeugt ein neues, zufälliges Captcha. - /// - public void Generate() - { - this.Text = string.Empty; - - //Größe des Bildes festlegen und dieses erzeugen - int width = (this.Length + 1) * spacePerChar; - int height = 60; - _Captcha = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - using (Graphics g = Graphics.FromImage(_Captcha)) - { - Rectangle rect = new Rectangle(0, 0, width, height); - - //Hintergundmalen - g.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(width, height), GetRandomBackgroundColor(), GetRandomBackgroundColor()), rect); - if (this.IntegrateHatch) - g.FillRectangle(GetRandomBackgroundHatchBrush(), rect); - //Zeichen malen - for (int i = 0; i < this.Length; i++) - { - DrawChar(i, g); - } - //Muster über den Text malen - if (this.IntegrateHatch) - g.FillRectangle(GetRandomForegroundHatchBrush(), rect); - - } - } - - #endregion - - #region Eigenschaften - - /// - /// Ruft den angezeigten Text im Cpatcha ab. - /// - public string Text { get; private set; } - /// - /// Ruft das Captcha ab. - /// - public Bitmap Captcha - { - get { - return _Captcha; - } - } - - /// - /// Ruft die Anzahl der Zeichen im Captcha ab bzw. legt diese fest. - /// - public int Length { get; set; } - - /// - /// Ruft die Verwendbaren Zeichen im Cpatcha ab oder legt diese fest. - /// - public string Chars { get; set; } - - /// - /// Ruft den Drehbereich der einzelnen Zeichen ab oder legt diese fest. Der Idealwert liegt zwischen einschließlich -20 und 20. - /// - public CaptchaCharRotateRange RotateRange { get; set; } - - /// - /// Ruft einen Wert ab, der angibt ob ein zufälliger Hatchbruch integriert werden soll oder legt diesen fest. - /// - public bool IntegrateHatch { get; set; } - - #endregion - - #region IDisposable Member - - /// - /// Gibt alle von diesem Objekt verwendeten Resourcen wieder frei. - /// - public void Dispose() - { - if (this._Captcha != null) - this._Captcha.Dispose(); - } - - #endregion - } - - /// - /// Stellt den Bereich dar, in dem ein Zeichen im Captcha gedrht werden kann. - /// - struct CaptchaCharRotateRange - { - /// - /// Initialisiert eine neue Instanz der CaptchaCharRotateRange-Klasse. - /// - /// Die höchste Drehung in Grad nach links. - /// Die höchste Drehung in Grad nach rechts. - public CaptchaCharRotateRange(int min, int max) - : this() - { - if (min > max) - throw new ArgumentOutOfRangeException("min <= max!"); - this.Min = min; - this.Max = max; - } - /// - /// Ruft die maximale Drehung in Grad nach links ab. - /// - public int Min { get; private set; } - /// - /// Ruft die maximale Drehung in Grad nach rechts ab. - /// - public int Max { get; private set; } - } -} diff --git a/LaptopSimulator2015/FakeDesktop.cs b/LaptopSimulator2015/FakeDesktop.cs index 5a3194e..da8c663 100644 --- a/LaptopSimulator2015/FakeDesktop.cs +++ b/LaptopSimulator2015/FakeDesktop.cs @@ -9,6 +9,7 @@ using System.Media; using System.Reflection; using System.Diagnostics; using System.IO; +using System.Drawing.Drawing2D; namespace LaptopSimulator2015 { @@ -54,10 +55,7 @@ namespace LaptopSimulator2015 if (_mode == Mode.mainMenu) winMenuStart.Select(); for (int i = 0; i < levels.Count; i++) - { - levels[i].desktopIcon.Visible = levels[i].LevelNumber >= Settings.Default.level; - Console.WriteLine(levels[i].LevelNumber + " - " + _mode.ToString() + ": " + levels[i].desktopIcon.Visible.ToString()); - } + levels[i].desktopIcon.Visible = levels[i].LevelNumber <= Settings.Default.level; } } @@ -103,7 +101,7 @@ namespace LaptopSimulator2015 levels[i].desktopIcon.Size = new Size(50, 50); levels[i].desktopIcon.BackColor = Color.FromArgb(128, 128, 255); levels[i].desktopIcon.Name = "lvl" + i.ToString() + "_1"; - levels[i].desktopIcon.Visible = levels[i].LevelNumber >= Settings.Default.level; + levels[i].desktopIcon.Visible = levels[i].LevelNumber <= Settings.Default.level; tmp1.BackColor = Color.Blue; tmp1.BackgroundImageLayout = ImageLayout.Stretch; @@ -242,7 +240,9 @@ namespace LaptopSimulator2015 minigamePanel.Visible = true; minigamePanel.Enabled = true; minigameClockT.Enabled = true; +#if !DEBUG levelWindowC1.Enabled = false; +#endif g.Clear(Color.Red); g.DrawString("DANGER!", new Font("Microsoft Sans Serif", 100f), new SolidBrush(Color.White), 100, 150); g.DrawString("VIRUS DETECTED", new Font("Microsoft Sans Serif", 20f), new SolidBrush(Color.White), 0, 300); @@ -267,7 +267,7 @@ namespace LaptopSimulator2015 Settings.Default.level = closest; Settings.Default.Save(); for (int i = 0; i < levels.Count; i++) - levels[i].desktopIcon.Visible = levels[i].LevelNumber >= Settings.Default.level; + levels[i].desktopIcon.Visible = levels[i].LevelNumber <= Settings.Default.level; mode = Mode.game; } break; @@ -295,10 +295,29 @@ namespace LaptopSimulator2015 private void CaptchaPanel_Click(object sender, EventArgs e) { - CaptchaGenerator cap = new CaptchaGenerator(6, strings.captchaLetters); - cap.Generate(); - captchaPanel.BackgroundImage = cap.Captcha; - captchaBox.Tag = cap.Text; + Random rnd = new Random(); + string Chars = strings.captchaLetters; + captchaBox.Tag = ""; + captchaPanel.BackgroundImage = new Bitmap(175, 60, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + using (Graphics g = Graphics.FromImage(captchaPanel.BackgroundImage)) + { + g.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(175, 60), Color.FromArgb(rnd.Next(180, 255), rnd.Next(180, 255), rnd.Next(180, 255)), Color.FromArgb(rnd.Next(180, 255), rnd.Next(180, 255), rnd.Next(180, 255))), new Rectangle(0, 0, 175, 60)); + g.FillRectangle(new HatchBrush((HatchStyle)rnd.Next(53), Color.FromArgb(rnd.Next(180, 255), rnd.Next(180, 255), rnd.Next(180, 255)), Color.Transparent), new Rectangle(0, 0, 175, 60)); + for (int i = 0; i < 6; i++) + { + int y = rnd.Next(8, 13); + int fontSize = rnd.Next(12, 18); + g.TranslateTransform(25 * (i) + 10, (30 - fontSize) / 2); + g.RotateTransform(rnd.Next(-20, 20)); + int tmpR = rnd.Next(0, 200); + int tmpG = rnd.Next(0, (200 - tmpR) / 2); + string s = Chars[rnd.Next(Chars.Length)].ToString(); + captchaBox.Tag = (string)captchaBox.Tag + s; + g.DrawString(s, new Font(new string[] { "Arial", "Consolas", "Verdena" }[rnd.Next(3)], fontSize), new SolidBrush(Color.FromArgb(tmpR, tmpG, Math.Max(0, 200 - tmpR - tmpG))), new PointF(5, y)); + g.ResetTransform(); + } + g.FillRectangle(new HatchBrush((HatchStyle)rnd.Next(Enum.GetValues(typeof(HatchStyle)).Length), Color.FromArgb(rnd.Next(10, 50), rnd.Next(180, 255), rnd.Next(180, 255), rnd.Next(180, 255)), Color.FromArgb(rnd.Next(10, 50), rnd.Next(180, 255), rnd.Next(180, 255), rnd.Next(180, 255))), new Rectangle(0, 0, 175, 60)); + } captchaBox.Text = ""; } @@ -325,7 +344,7 @@ namespace LaptopSimulator2015 levelWindowC1.Enabled = true; } - #region Minigame +#region Minigame uint minigameTime = 0; private void InvadersPanel_Paint(object sender, PaintEventArgs e) => levels[levelInd].gameTick(e.Graphics, minigamePanel, minigameClockT, minigameTime); @@ -334,10 +353,10 @@ namespace LaptopSimulator2015 minigameTime++; minigamePanel.Invalidate(); } - #endregion +#endregion - #endregion - #region Options +#endregion +#region Options private void Options_2_DoubleClick(object sender, EventArgs e) { winDesktop.Enabled = false; @@ -393,6 +412,7 @@ namespace LaptopSimulator2015 }); Application.Exit(); } + mode = Mode.game; } bool tmpoptionsmlgcanchange = false; @@ -467,8 +487,9 @@ namespace LaptopSimulator2015 Settings.Default.subs = true; Settings.Default.level = 1; Settings.Default.Save(); + mode = Mode.game; } } - #endregion +#endregion } } \ No newline at end of file diff --git a/LaptopSimulator2015/LaptopSimulator2015.csproj b/LaptopSimulator2015/LaptopSimulator2015.csproj index 5985fe6..6c5a4c1 100644 --- a/LaptopSimulator2015/LaptopSimulator2015.csproj +++ b/LaptopSimulator2015/LaptopSimulator2015.csproj @@ -31,6 +31,8 @@ TRACE prompt 4 + false + true @@ -46,7 +48,6 @@ - Form diff --git a/lv1_t/MainForm.cs b/lv1_t/MainForm.cs index ea0c4e1..ae96fd9 100644 --- a/lv1_t/MainForm.cs +++ b/lv1_t/MainForm.cs @@ -78,17 +78,17 @@ namespace SIT invadersBullets = invadersBullets.Except(bulletsToRemove.Distinct()).Distinct().ToList(); speedMod += 0.1; speedMod = Math.Max(Math.Min(speedMod, 5), 1); - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) invadersPlayer.Y -= speedMod; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) invadersPlayer.X -= speedMod; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) invadersPlayer.Y += speedMod; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) invadersPlayer.X += speedMod; - if (Input.IsKeyDown(Keys.Space) & invadersCanShoot) + if (Input.Action & invadersCanShoot) { - invadersBullets.Add(new Vector2(invadersPlayer)); + invadersBullets.Add(new Vector2(0, 2.5) + invadersPlayer); invadersCanShoot = false; speedMod--; } diff --git a/lv2_t/MainForm.cs b/lv2_t/MainForm.cs index 6c5f955..8f6ef59 100644 --- a/lv2_t/MainForm.cs +++ b/lv2_t/MainForm.cs @@ -61,13 +61,13 @@ namespace lv2_t else enemies.Add(new Vector2(0, tst - minigamePanel.Width * 2 - minigamePanel.Height + 10)); } - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) player.Y -= 5; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) player.X -= 5; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) player.Y += 5; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) player.X += 5; List enemiesToRemove = new List(); for (int i = 0; i < enemies.Count; i++) diff --git a/lv3_t/MainForm.cs b/lv3_t/MainForm.cs index 1d4fc7f..85e7b0d 100644 --- a/lv3_t/MainForm.cs +++ b/lv3_t/MainForm.cs @@ -80,7 +80,7 @@ namespace lv3_t } cannon = new Vector2(center); cannon.moveInDirection(Misc.deg2rad(playerRot), 20); - if (Input.IsKeyDown(Keys.Space)) + if (Input.Action) { firing = true; power = Math.Min(power + 5, 100); @@ -101,13 +101,13 @@ namespace lv3_t } targ = new Vector2(center); targ.Tag = playerRot; - if (Input.IsKeyDown(Keys.W)) + if (Input.Up) cannonL += 100 / power; - if (Input.IsKeyDown(Keys.S)) + if (Input.Down) cannonL -= 100 / power; - if (Input.IsKeyDown(Keys.D)) + if (Input.Right) playerRot += 80 / power; - if (Input.IsKeyDown(Keys.A)) + if (Input.Left) playerRot -= 80 / power; while (playerRot > 360) playerRot -= 360; diff --git a/lv4_t/App.config b/lv4_t/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/lv4_t/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lv4_t/MainForm.Designer.cs b/lv4_t/MainForm.Designer.cs new file mode 100644 index 0000000..39453d6 --- /dev/null +++ b/lv4_t/MainForm.Designer.cs @@ -0,0 +1,93 @@ +namespace lv4_t +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.minigameClockT = new System.Windows.Forms.Timer(this.components); + this.button1 = new System.Windows.Forms.Button(); + this.minigamePanel = new System.Windows.Forms.Panel(); + this.minigamePanel.SuspendLayout(); + this.SuspendLayout(); + // + // minigameClockT + // + this.minigameClockT.Enabled = true; + this.minigameClockT.Interval = 17; + this.minigameClockT.Tick += new System.EventHandler(this.MinigameClockT_Tick); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(777, 0); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(23, 23); + this.button1.TabIndex = 0; + this.button1.TabStop = false; + this.button1.Text = "X"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // minigamePanel + // + this.minigamePanel.BackColor = System.Drawing.Color.Black; + this.minigamePanel.Controls.Add(this.button1); + this.minigamePanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.minigamePanel.Location = new System.Drawing.Point(0, 0); + this.minigamePanel.Name = "minigamePanel"; + this.minigamePanel.Size = new System.Drawing.Size(800, 450); + this.minigamePanel.TabIndex = 1; + this.minigamePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.MinigamePanel_Paint); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.ControlBox = false; + this.Controls.Add(this.minigamePanel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MainForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.minigamePanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Timer minigameClockT; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Panel minigamePanel; + } +} + diff --git a/lv4_t/MainForm.cs b/lv4_t/MainForm.cs new file mode 100644 index 0000000..c2adba7 --- /dev/null +++ b/lv4_t/MainForm.cs @@ -0,0 +1,196 @@ +using Base; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace lv4_t +{ + public partial class MainForm : Form + { + #region FRMBD + uint minigameTime = 0; + uint minigamePrevTime = 0; + public MainForm() + { + InitializeComponent(); + player = new Vector2(minigamePanel.Width / 2, 0); + player.bounds = new Rectangle(-5, 0, minigamePanel.Width + 10, 0); + player.bounds_wrap = true; + playerV = new Vector2(); + playerV.bounds = new Rectangle(-5, -20, 10, 40); + playerV.bounds_wrap = false; + for (int i = 0; i < 5; i++) + for (int j = 0; j < 2; j++) + platforms.Add(new Vector2(rnd.Next(minigamePanel.Width), i * (minigamePanel.Height / 5))); + } + + private void Button1_Click(object sender, EventArgs e) => Application.Exit(); + private void MinigameClockT_Tick(object sender, EventArgs e) + { + minigameTime++; + minigamePanel.Invalidate(); + } + #endregion + Random rnd = new Random(); + Vector2 player = new Vector2(); + Vector2 playerV = new Vector2(); + int jmpj; + List platforms = new List(); + private void MinigamePanel_Paint(object sender, PaintEventArgs e) + { + BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate(e.Graphics, new Rectangle(0, 0, minigamePanel.Width, minigamePanel.Height)); + Graphics g = buffer.Graphics; + try + { + g.Clear(Color.Black); + g.FillRectangle(new SolidBrush(Color.Green), player2rect()); + bool onPlatform = false; + for (int i = 0; i < platforms.Count; i++) + { + g.FillRectangle(new SolidBrush(Color.White), plat2rect(i)); + onPlatform |= isOnPlatform(i); + } + Random random = new Random(); + if (minigameTime != minigamePrevTime) + { + minigamePrevTime = minigameTime; + if (onPlatform) + playerV.Y = Math.Min(playerV.Y, 0); + else + playerV.Y += 0.05f + Math.Pow(0.9, Math.Max(playerV.Y + 1, 0)); + playerV.X /= 1.2f; + if (onPlatform) + jmpj = 10; + else + if (!Input.Up) + jmpj = 0; + if ((onPlatform || jmpj > 0) && Input.Up) + { + playerV.Y -= Math.Sqrt(jmpj); + jmpj--; + } + if (Input.Left) + playerV.X -= 5; + if (Input.Right) + playerV.X += 5; + player.X += playerV.X; + onPlatform = false; + if (playerV.Y < 0) + player.Y += playerV.Y; + else + for (int i = 0; i < playerV.Y / 2; i++) + { + for (int j = 0; j < platforms.Count; j++) + onPlatform |= isOnPlatform(j); + if (!onPlatform) + player.Y += 2; + } + List platformsToRemove = new List(); + for (int i = 0; i < platforms.Count; i++) + { + platforms[i].Y++; + if (platforms[i].Y > minigamePanel.Height) + { + platforms[i].Y = 0; + platforms[i].X = rnd.Next(minigamePanel.Width); + } + } + if (player.Y > minigamePanel.Height) + throw new Exception("The VM was shut down to prevent damage to your Machine.", new Exception("0717750f-3508-4bc2-841e-f3b077c676fe")); + } + buffer.Render(); + } + catch (Exception ex) + { + if (ex.InnerException?.Message == "0717750f-3508-4bc2-841e-f3b077c676fe") + { + minigameClockT.Enabled = false; + g.Clear(Color.Red); + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.PixelOffsetMode = PixelOffsetMode.HighQuality; + SizeF sLen = g.MeasureString("Lost.", new Font("Tahoma", 20)); + RectangleF rectf = new RectangleF(minigamePanel.Width / 2 - sLen.Width / 2, minigamePanel.Height / 2 - sLen.Height / 2, 90, 50); + g.DrawString("Lost.", new Font("Tahoma", 20), Brushes.Black, rectf); + buffer.Render(); + } + else +#if DEBUG + throw; +#else + Console.WriteLine(ex.ToString()); +#endif + } + } + + RectangleF plat2rect(int platform) => new RectangleF((platforms[platform] - new Vector2(50, 5)).toPointF(), new SizeF(100, 10)); + RectangleF player2rect() => new RectangleF((player - new Vector2(5, 5)).toPointF(), new SizeF(10, 10)); + + bool isOnPlatform(int platform) + { + calcDist(platform); + return ((double)platforms[platform].Tag) <= 20 && RectangleF.Intersect(player2rect(), plat2rect(platform)) != RectangleF.Empty && player.Y < platforms[platform].Y - 8; + } + + void calcDist(int platform) + { + RectangleF rect = plat2rect(platform); + if (player.X < rect.X) + { + if (player.Y < rect.Y) + { + Vector2 diff = player - new Vector2(rect.X, rect.Y); + platforms[platform].Tag = diff.magnitude; + } + else if (player.Y > rect.Y + rect.Height) + { + Vector2 diff = player - new Vector2(rect.X, rect.Y + rect.Height); + platforms[platform].Tag = diff.magnitude; + } + else + { + platforms[platform].Tag = rect.X - player.X; + } + } + else if (player.X > rect.X + rect.Width) + { + if (player.Y < rect.Y) + { + Vector2 diff = player - new Vector2(rect.X + rect.Width, rect.Y); + platforms[platform].Tag = diff.magnitude; + } + else if (player.Y > rect.Y + rect.Height) + { + Vector2 diff = player - new Vector2(rect.X + rect.Width, rect.Y + rect.Height); + platforms[platform].Tag = diff.magnitude; + } + else + { + platforms[platform].Tag = player.X - rect.X + rect.Width; + } + } + else + { + if (player.Y < rect.Y) + { + platforms[platform].Tag = rect.Y - player.Y; + } + else if (player.Y > rect.Y + rect.Height) + { + platforms[platform].Tag = player.Y - (rect.Y + rect.Height); + } + else + { + platforms[platform].Tag = 0d; + } + } + } + } +} diff --git a/lv4_t/MainForm.resx b/lv4_t/MainForm.resx new file mode 100644 index 0000000..7925979 --- /dev/null +++ b/lv4_t/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/lv4_t/Program.cs b/lv4_t/Program.cs new file mode 100644 index 0000000..743756f --- /dev/null +++ b/lv4_t/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace lv4_t +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/lv4_t/Properties/AssemblyInfo.cs b/lv4_t/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d0b0db0 --- /dev/null +++ b/lv4_t/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("lv4_t")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("lv4_t")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("22d618c0-f0a4-417f-a815-c760bf4376b2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/lv4_t/Properties/Resources.Designer.cs b/lv4_t/Properties/Resources.Designer.cs new file mode 100644 index 0000000..cc37acf --- /dev/null +++ b/lv4_t/Properties/Resources.Designer.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace lv4_t.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("lv4_t.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/lv4_t/Properties/Resources.resx b/lv4_t/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/lv4_t/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/lv4_t/Properties/Settings.Designer.cs b/lv4_t/Properties/Settings.Designer.cs new file mode 100644 index 0000000..fee6974 --- /dev/null +++ b/lv4_t/Properties/Settings.Designer.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace lv4_t.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get { + return defaultInstance; + } + } + } +} diff --git a/lv4_t/Properties/Settings.settings b/lv4_t/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/lv4_t/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/lv4_t/lv4_t.csproj b/lv4_t/lv4_t.csproj new file mode 100644 index 0000000..ae5959d --- /dev/null +++ b/lv4_t/lv4_t.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {22D618C0-F0A4-417F-A815-C760BF4376B2} + WinExe + lv4_t + lv4_t + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {9a9561a7-dd5f-43a5-a3f5-a95f35da204d} + Base + + + + \ No newline at end of file