diff --git a/1/1.cs b/1/1.cs index 7292400..1ff063a 100644 --- a/1/1.cs +++ b/1/1.cs @@ -59,6 +59,7 @@ namespace LaptopSimulator2015.Levels public int installerProgressSteps => 500; public Color backColor => Color.Black; public string[] credits => new string[] { "Level1 Icon made by Oliver Scholtz from www.iconfinder.com" }; + public bool isLowQuality => false; List enemies; List bullets; diff --git a/2/2.cs b/2/2.cs index c45b4bd..815b6db 100644 --- a/2/2.cs +++ b/2/2.cs @@ -60,6 +60,8 @@ namespace LaptopSimulator2015.Levels public int installerProgressSteps => 500; public Color backColor => Color.Black; public string[] credits => new string[] { "Level2 Icon made by Intel" }; + public bool isLowQuality => false; + List enemies; Vector2 player; int lives; diff --git a/3/3.cs b/3/3.cs index d13d6b8..0bd3cec 100644 --- a/3/3.cs +++ b/3/3.cs @@ -63,6 +63,7 @@ namespace LaptopSimulator2015.Levels public int installerProgressSteps => 500; public Color backColor => Color.Black; public string[] credits => new string[] { "Level3 Icon made by NVidia" }; + public bool isLowQuality => false; Vector2 center; Vector2 cannon; @@ -97,13 +98,14 @@ namespace LaptopSimulator2015.Levels { firing = false; List targetsToRemove = new List(); + Rect tr = new Rect(targ, new Vector2(power, power), true); for (int i = 0; i < targets.Count; i++) { - if (targets[i].distanceFromSquared(targ) <= Math.Pow(power + 10, 2)) + if (targets[i].distanceToRectSquared(tr) <= 400) targetsToRemove.Add(targets[i]); } targets = targets.Except(targetsToRemove.Distinct()).Distinct().ToList(); - g.g.FillRectangle(new SolidBrush(Color.White), new Rectangle(Misc.d2i(targ.X - power / 2), Misc.d2i(targ.Y - power / 2), Misc.d2i(power), Misc.d2i(power))); + g.DrawRectangle(tr, Color.White); power = 10; } targ = new Vector2(center); @@ -113,9 +115,9 @@ namespace LaptopSimulator2015.Levels if (Input.Down) cannonL -= 100 / power; if (Input.Right) - playerRot += 80 / power; - if (Input.Left) playerRot -= 80 / power; + if (Input.Left) + playerRot += 80 / power; while (playerRot > 360) playerRot -= 360; while (playerRot < 0) @@ -147,28 +149,28 @@ namespace LaptopSimulator2015.Levels public void draw(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime) { - //g.g.FillRectangle(new SolidBrush(Color.Green), player); - g.DrawRectangle(new RectangleF(center.toPointF(), new SizeF(10, 10)), Color.Green, transform:false); - g.g.DrawLine(new Pen(new SolidBrush(Color.Green), 5), center.toPoint(), cannon.toPoint()); + g.DrawRectangle(new RectangleF(center.toPointF(), new SizeF(10, 10)), Color.Green); + g.DrawLine(center, cannon, Color.Green, 5); for (int i = 0; i < targets.Count; i++) { - g.g.DrawEllipse(new Pen(new SolidBrush(Color.Red), 6), new RectangleF(Misc.d2f(targets[i].X - 10), Misc.d2f(targets[i].Y - 10), 20, 20)); - g.g.DrawEllipse(new Pen(new SolidBrush(Color.White), 6), new RectangleF(Misc.d2f(targets[i].X - 7), Misc.d2f(targets[i].Y - 7), 14, 14)); - g.g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Misc.d2f(targets[i].X - 3), Misc.d2f(targets[i].Y - 3), 6, 6)); - g.g.DrawLine(new Pen(new SolidBrush(Color.Gray), 3), Misc.d2f(targets[i].X - 13), Misc.d2f(targets[i].Y - 15), Misc.d2f(targets[i].X + 13), Misc.d2f(targets[i].Y - 15)); - g.g.DrawLine(new Pen(new SolidBrush(Color.Red), 3), Misc.d2f(targets[i].X - 13), Misc.d2f(targets[i].Y - 15), Misc.d2f(targets[i].X + ((((double)targets[i].Tag) * 0.2) - 12.9) + 0.1), Misc.d2f(targets[i].Y - 15)); + g.DrawRectangle(new Rect(targets[i], new Vector2(20, 20), true), Color.AliceBlue); + + g.g.DrawEllipse(new Pen(new SolidBrush(Color.Red), 6), new RectangleF(Misc.d2f(targets[i].X - 10), Misc.d2f(minigamePanel.Height - 10 - targets[i].Y), 20, 20)); + g.g.DrawEllipse(new Pen(new SolidBrush(Color.White), 6), new RectangleF(Misc.d2f(targets[i].X - 7), Misc.d2f(minigamePanel.Height - 7 - targets[i].Y), 14, 14)); + g.g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Misc.d2f(targets[i].X - 3), Misc.d2f(minigamePanel.Height - 3 - targets[i].Y), 6, 6)); + + g.DrawLine(new Vector2(targets[i].X - 13, targets[i].Y + 15), new Vector2(targets[i].X + 13, targets[i].Y + 15), Color.Gray, 3); + g.DrawLine(new Vector2(targets[i].X - 13, targets[i].Y + 15), new Vector2(targets[i].X + ((((double)targets[i].Tag) * 0.2) - 12.9) + 0.1, targets[i].Y + 15), Color.Red, 3); } if (firing) { - //g.g.DrawRectangle(new Pen(new SolidBrush(Color.Green), 1), new Rectangle(Misc.d2i(targ.X - power / 2), Misc.d2i(targ.Y - power / 2), Misc.d2i(power), Misc.d2i(power))); - g.DrawRectangle(new RectangleF(targ.toPointF(), new SizeF(Misc.d2f(power), Misc.d2f(power))), Color.Green, filled: false, transform: false); - g.g.DrawLine(new Pen(new SolidBrush(Color.Green), 1), new PointF(Misc.d2i(targ.X), Misc.d2i(targ.Y - power / 2)), new PointF(Misc.d2i(targ.X), Misc.d2i(targ.Y + power / 2))); - g.g.DrawLine(new Pen(new SolidBrush(Color.Green), 1), new PointF(Misc.d2i(targ.X - power / 2), Misc.d2i(targ.Y)), new PointF(Misc.d2i(targ.X + power / 2), Misc.d2i(targ.Y))); + g.DrawRectangle(new Rect(targ, new Vector2(power, power), true), Color.Green, filled: false); + g.DrawLine(targ + new Vector2(-power / 2, 0), targ + new Vector2(power / 2, 0), Color.Green, 1); + g.DrawLine(targ + new Vector2(0, -power / 2), targ + new Vector2(0, power / 2), Color.Green, 1); } else { - //g.g.FillRectangle(new SolidBrush(Color.Green), new RectangleF(Misc.d2f(targ.X - 2.5f), Misc.d2f(targ.Y - 2.5f), 5, 5)); - g.DrawRectangle(new RectangleF(targ.toPointF(), new SizeF(5, 5)), Color.Green, transform: false); + g.DrawRectangle(new RectangleF(targ.toPointF(), new SizeF(5, 5)), Color.Green); } } } diff --git a/3g/3.cs b/3g/3.cs index 459baf7..5571543 100644 --- a/3g/3.cs +++ b/3g/3.cs @@ -77,6 +77,7 @@ namespace LaptopSimulator2015.Goals public Color backColor => Color.Black; public string[] credits => new string[]{ "Testexetrisathlon Icon made by Freepik from www.flaticon.com" }; + public bool isLowQuality => true; public static int[,] grid = new int[23, 10]; public static int[,] droppedtetrominoeLocationGrid = new int[23, 10]; @@ -203,11 +204,11 @@ namespace LaptopSimulator2015.Goals if (grid[y, x] == 1 | droppedtetrominoeLocationGrid[y, x] == 1) g.DrawRectangle(new RectangleF(x * 10, y * 10, 10, 10), Color.White, false, false); } - g.g.DrawLine(new Pen(Color.DarkGray), new Point(0, (y + 1) * 10), new Point(10 * 10, (y + 1) * 10)); + g.DrawLine(new Point(0, (y + 1) * 10), new Point(10 * 10, (y + 1) * 10), Color.DarkGray, 1, false); } for (int x = 0; x < 10; x++) { - g.g.DrawLine(new Pen(Color.DarkGray), new Point((x + 1) * 10, 0), new Point((x + 1) * 10, 23 * 10)); + g.DrawLine(new Point((x + 1) * 10, 0), new Point((x + 1) * 10, 23 * 10), Color.DarkGray, 1, false); } g.DrawSizedString("Level " + level, 10, new PointF(150, 10), Brushes.White, false); g.DrawSizedString("Score " + score, 10, new PointF(150, 30), Brushes.White, false); diff --git a/4/4.cs b/4/4.cs index 3346f55..84865ec 100644 --- a/4/4.cs +++ b/4/4.cs @@ -56,6 +56,7 @@ namespace LaptopSimulator2015.Levels public Panel desktopIcon { get; set; } public int installerProgressSteps => 500; public Color backColor => Color.Black; + public bool isLowQuality => false; public string[] credits => new string[] { "Level4 Icon made by Microsoft" }; Random rnd; diff --git a/Base/Base.csproj b/Base/Base.csproj index 5e5a783..a5462f2 100644 --- a/Base/Base.csproj +++ b/Base/Base.csproj @@ -53,6 +53,12 @@ + + + {23DE4AE0-5075-4CCC-8440-4D131CA0FBBA} + W32 + + diff --git a/Base/Drawing.cs b/Base/Drawing.cs index dd6c0a8..5dd50be 100644 --- a/Base/Drawing.cs +++ b/Base/Drawing.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Base { - public class GraphicsWrapper : IDisposable + public sealed class GraphicsWrapper : IDisposable { BufferedGraphics _g; Color backColor; @@ -127,7 +127,7 @@ namespace Base /// /// Render and dispose /// - public virtual void Dispose() + public void Dispose() { g.Flush(); _g.Render(); diff --git a/Base/Input.cs b/Base/Input.cs index bc1df33..710b72e 100644 --- a/Base/Input.cs +++ b/Base/Input.cs @@ -1,4 +1,5 @@ -using System; +using CC_Functions.W32; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; @@ -9,10 +10,8 @@ using System.Windows.Input; namespace Base { - public class Input + public static class Input { - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] - private static extern short GetKeyState(int keyCode); /// /// Check whether the Key is pressed /// @@ -22,17 +21,11 @@ namespace Base { try { - int state = 0; - short retVal = GetKeyState((int)key); - if ((retVal & 0x8000) == 0x8000) - state |= 1; - if ((retVal & 1) == 1) - state |= 2; - return 1 == (state & 1); + return KeyboardReader.IsKeyDown(key); } - catch (Exception e1) + catch (Exception e) { - Console.WriteLine("Invader: IsKeyDown failed:\r\n" + e1.ToString()); + Console.WriteLine("Invader: IsKeyDown failed:\r\n" + e.ToString()); return false; } } diff --git a/Base/Minigame.cs b/Base/Minigame.cs index 1bd7a97..cd08d57 100644 --- a/Base/Minigame.cs +++ b/Base/Minigame.cs @@ -32,6 +32,14 @@ namespace LaptopSimulator2015 /// int gameClock { get; } /// + /// Color to be painted to the Background before calling the draw method + /// + Color backColor { get; } + /// + /// In what quality to draw the frames + /// + bool isLowQuality { get; } + /// /// DO NOT CHANGE! INTERNAL USE ONLY! /// Panel desktopIcon { get; set; } @@ -58,10 +66,6 @@ namespace LaptopSimulator2015 /// The timer used for scheduling frames /// The amount of total displayed frames void draw(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime); - /// - /// Color to be painted to the Background before calling the draw method - /// - Color backColor { get; } } public interface Level : Minigame { diff --git a/Base/Rect.cs b/Base/Rect.cs index dc08c41..0ccb3cd 100644 --- a/Base/Rect.cs +++ b/Base/Rect.cs @@ -12,16 +12,10 @@ namespace Base /// /// Create a rect from the provided data /// - /// Bottom-left point - /// Amount to extend top-right - public Rect(Vector2 Location, Vector2 Size, bool centered = false) - { - this.Location = Location ?? throw new ArgumentNullException(nameof(Location)); - this.Size = Size ?? throw new ArgumentNullException(nameof(Size)); - this.centered = centered; - if (this.centered) - this.Location -= this.Size / 2; - } + /// Position + /// Rect's size + /// Whether the Rect should be created top-right or around the Location + public Rect(Vector2 Location, Vector2 Size, bool centered = false) : this(Location.X, Location.Y, Size.X, Size.Y, centered) { } /// /// Create a rect from the provided data @@ -30,13 +24,18 @@ namespace Base /// Y in world-coordinates /// Width /// Height + /// Whether the Rect should be created top-right or around the Location public Rect(double X, double Y, double Width, double Height, bool centered = false) { Location = new Vector2(X, Y); Size = new Vector2(Width, Height); this.centered = centered; if (this.centered) - Location -= Size / 2; + { + //Location -= Size / 2; + Location.X -= Size.X / 2; + Location.Y += Size.Y / 2; + } } /// @@ -47,17 +46,18 @@ namespace Base { Location = rect.Location; Size = rect.Size; + centered = rect.centered; } - public Rect(Rectangle rect) - { - Location = new Vector2(rect.Location); - Size = new Vector2(rect.Size); - } - public Rect(RectangleF rect) - { - Location = new Vector2(rect.Location); - Size = new Vector2(rect.Size); - } + /// + /// Copies the Rect's data + /// + /// + public Rect(Rectangle rect) : this(rect.X, rect.Y, rect.Width, rect.Height, false) { } + /// + /// Copies the Rect's data + /// + /// + public Rect(RectangleF rect) : this(rect.X, rect.Y, rect.Width, rect.Height, false) { } public double X { diff --git a/LaptopSimulator2015/FakeDesktop.cs b/LaptopSimulator2015/FakeDesktop.cs index 7f95931..9351eaf 100644 --- a/LaptopSimulator2015/FakeDesktop.cs +++ b/LaptopSimulator2015/FakeDesktop.cs @@ -66,10 +66,10 @@ namespace LaptopSimulator2015 bool tmp__mode_uiv = false; [DllImport("winmm.dll")] - public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); + static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); [DllImport("winmm.dll")] - public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume); + static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume); public FakeDesktop() { @@ -482,7 +482,7 @@ namespace LaptopSimulator2015 uint minigamePrevTime = 0; private void InvadersPanel_Paint(object sender, PaintEventArgs e) { - using (GraphicsWrapper w = new GraphicsWrapper(e.Graphics, levels[levelInd].backColor, new Rectangle(Point.Empty, minigamePanel.Size))) + using (GraphicsWrapper w = new GraphicsWrapper(e.Graphics, levels[levelInd].backColor, new Rectangle(Point.Empty, minigamePanel.Size), levels[levelInd].isLowQuality)) { w.Clear(); levels[levelInd].draw(w, minigamePanel, minigameClockT, minigameTime); @@ -658,11 +658,14 @@ namespace LaptopSimulator2015 private void optionsWindowCredit_Click(object sender, EventArgs e) { - string tmp = Path.GetTempFileName(); - File.Move(tmp, Path.ChangeExtension(tmp, "txt")); - tmp = Path.ChangeExtension(tmp, "txt"); - File.WriteAllLines(tmp, levels.SelectMany(s => s.credits).ToArray()); - Process.Start(tmp).Exited += (object sender1, EventArgs e1) => { File.Delete(tmp); }; + new Thread(() => { + string tmp = Path.GetTempFileName(); + File.Move(tmp, Path.ChangeExtension(tmp, "txt")); + tmp = Path.ChangeExtension(tmp, "txt"); + File.WriteAllLines(tmp, levels.SelectMany(s => s.credits).ToArray()); + Process.Start(tmp).WaitForExit(); + File.Delete(tmp); + }).Start(); } bool devWindowMoving = false; @@ -706,9 +709,9 @@ namespace LaptopSimulator2015 [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); - const UInt32 SWP_NOSIZE = 0x0001; - const UInt32 SWP_NOMOVE = 0x0002; - const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; + const uint SWP_NOSIZE = 0x0001; + const uint SWP_NOMOVE = 0x0002; + const uint TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); diff --git a/LaptopSimulator2015/Program.cs b/LaptopSimulator2015/Program.cs index 5120b7a..c30b8f0 100644 --- a/LaptopSimulator2015/Program.cs +++ b/LaptopSimulator2015/Program.cs @@ -15,6 +15,7 @@ namespace LaptopSimulator2015 class Program { public static Splash splash; + [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); diff --git a/LevelTest/Program.cs b/LevelTest/Program.cs index 45cf8a2..fa0b50c 100644 --- a/LevelTest/Program.cs +++ b/LevelTest/Program.cs @@ -32,7 +32,7 @@ namespace LevelTest } else { - string[] tmp = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories).Where(s => Path.GetFileName(s) != "Base.dll").ToArray(); + string[] tmp = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories).Where(s => Path.GetFileName(s) != "Base.dll" && Path.GetFileName(s) != "CC-Functions.W32.dll").ToArray(); if (tmp.Length == 0) using (FolderBrowserDialog openFileDialog = new FolderBrowserDialog()) { @@ -42,7 +42,7 @@ namespace LevelTest throw new Exception("Please select a folder"); } } - Minigame[] levels = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories).Where(s => Path.GetFileName(s) != "Base.dll") + Minigame[] levels = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories).Where(s => Path.GetFileName(s) != "Base.dll" && Path.GetFileName(s) != "CC-Functions.W32.dll") .Select(s => Assembly.LoadFrom(s)).SelectMany(s => s.GetTypes()).Distinct() .Where(p => typeof(Minigame).IsAssignableFrom(p)).Distinct().Except(new Type[] { typeof(Minigame), typeof(Level), typeof(Goal) }) .Select(s => (Minigame)Activator.CreateInstance(s)).OrderBy(lv => lv.availableAfter).ToArray(); diff --git a/ToDo.txt b/ToDo.txt index ae5e6e0..99b69a0 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -1 +1,2 @@ -Fully implement new graphics on Goal and Level 3 \ No newline at end of file +Implement drawing ellipses (Level 3) +Fix Physics weirdness in Level 3 \ No newline at end of file diff --git a/tmp1/3g.dll b/tmp1/3g.dll new file mode 100644 index 0000000..e5f5667 Binary files /dev/null and b/tmp1/3g.dll differ diff --git a/tmp3/LevelTest.exe b/tmp3/LevelTest.exe new file mode 100644 index 0000000..4eeafb2 Binary files /dev/null and b/tmp3/LevelTest.exe differ