Last active
November 1, 2017 14:51
-
-
Save bemoty/352075e4fa29c34b4c9b975274abccbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.IO; | |
using System.Media; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Windows.Forms; | |
namespace DmG_Extreme | |
{ | |
public partial class Form1 : Form | |
{ | |
[DllImport("user32.dll")] | |
static extern IntPtr GetDC(IntPtr hWnd); | |
static String url = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp\\partyhard.wav"; | |
static Random random = new Random(); | |
static IntPtr desktopDC; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
// Set env vars | |
desktopDC = GetDC(IntPtr.Zero); | |
// Init Threads | |
Thread pmusc = new Thread(new ThreadStart(playMusic)); | |
Thread drcard = new Thread(new ThreadStart(dropDickolaus)); | |
Thread drsc = new Thread(new ThreadStart(drawIcons)); | |
Thread crsc = new Thread(new ThreadStart(moveCursor)); | |
// Start Threads | |
pmusc.Start(); | |
pmusc.Join(); | |
drcard.Start(); | |
drsc.Start(); | |
crsc.Start(); | |
Thread.Sleep(12656); | |
drawTitle(); | |
// Exit | |
if (File.Exists(url)) | |
File.Delete(url); | |
Environment.Exit(0); | |
} | |
static void playMusic() | |
{ | |
SoundPlayer player = new SoundPlayer(); | |
using (Stream input = Properties.Resources.partyhard) | |
using (Stream output = File.Create(url)) | |
{ | |
writeStream(input, output); | |
} | |
player.SoundLocation = url; | |
player.Play(); | |
Thread.Sleep(8295); | |
} | |
static void moveCursor() | |
{ | |
while (true) | |
{ | |
Thread.Sleep(10); | |
Point pt = Cursor.Position; | |
Cursor.Position = new Point((pt.X + ((random.Next(53) % 3 - 1) * 2) * (random.Next(32) % 2)), pt.Y + ((random.Next(53) % 3 - 1) * 2) * (random.Next(32) % 2)); | |
} | |
} | |
public static void writeStream(Stream input, Stream output) | |
{ | |
byte[] streambuffer = new byte[8192]; | |
int bytesRead; | |
while ((bytesRead = input.Read(streambuffer, 0, streambuffer.Length)) > 0) | |
{ | |
output.Write(streambuffer, 0, bytesRead); | |
} | |
} | |
static void drawTitle() | |
{ | |
Graphics dcGFX; | |
try | |
{ | |
dcGFX = Graphics.FromHdc(desktopDC); | |
} | |
catch (OutOfMemoryException ex) | |
{ | |
Console.WriteLine(ex.Message); | |
drawTitle(); | |
return; | |
} | |
Bitmap title = new Bitmap(Properties.Resources.yea); | |
int width = Screen.PrimaryScreen.Bounds.Width / 2 - title.Width / 2; | |
int height = Screen.PrimaryScreen.Bounds.Height / 2 - title.Height / 2; | |
dcGFX.DrawImage(title, width, height); | |
} | |
static void drawIcons() | |
{ | |
Graphics dcGFX = Graphics.FromHdc(desktopDC); | |
int screenWidth = Screen.PrimaryScreen.Bounds.Width; | |
int screenHeight = Screen.PrimaryScreen.Bounds.Height; | |
Bitmap error = new Bitmap(Properties.Resources.error_red_32x32); | |
Bitmap info = new Bitmap(Properties.Resources.information_blue_32x32); | |
Bitmap warning = new Bitmap(Properties.Resources.warning_yellow_7231_32x32); | |
while (true) | |
{ | |
Thread.Sleep(50); | |
int i = random.Next(3); | |
switch (i) | |
{ | |
case (0): | |
dcGFX.DrawImage(error, random.Next(screenWidth), random.Next(screenHeight)); | |
break; | |
case (1): | |
dcGFX.DrawImage(info, random.Next(screenWidth), random.Next(screenHeight)); | |
break; | |
case (2): | |
dcGFX.DrawImage(warning, random.Next(screenWidth), random.Next(screenHeight)); | |
break; | |
} | |
} | |
} | |
static void dropDickolaus() | |
{ | |
// Set up desktop drawing | |
int screenWidth = Screen.PrimaryScreen.Bounds.Width; | |
int screenHeight = Screen.PrimaryScreen.Bounds.Height; | |
IntPtr desktopDC = GetDC(IntPtr.Zero); | |
Graphics thisGFX = Graphics.FromHdc(desktopDC); | |
// Get card bitmap | |
Bitmap faceBMP = new Bitmap(Properties.Resources.Diggo); | |
// Start positions for face | |
long faceXPos = random.Next(screenWidth); | |
long faceYPos = -100; | |
// Start upward Energy | |
int upwardEnergy = random.Next(1, 3); | |
// Random Momentum Generator | |
int rightMomentum = random.Next(10, 20); | |
int momentumModifier = random.Next(1, 4); | |
// Setup vars | |
Boolean isFalling = true; | |
Boolean isDirectionRight = true; | |
while (true) | |
{ | |
Thread.Sleep(1); | |
// advance / reduce upward energy | |
if (isFalling) | |
{ | |
upwardEnergy++; | |
faceYPos += upwardEnergy; | |
} | |
else | |
{ | |
upwardEnergy--; | |
faceYPos -= upwardEnergy; | |
} | |
// Move right/left | |
if (isDirectionRight) | |
{ | |
faceXPos += rightMomentum * momentumModifier; | |
} | |
else | |
{ | |
faceXPos -= rightMomentum * momentumModifier; | |
} | |
// Bottom of Screen | |
if (faceYPos >= (screenHeight - faceBMP.Height)) | |
{ | |
isFalling = false; | |
} | |
// Top of Screen | |
if(faceYPos <= 0) | |
{ | |
isFalling = true; | |
} | |
// upward energy <= 0 | |
if (upwardEnergy <= 0) | |
{ | |
isFalling = true; | |
} | |
// Side of Screen | |
// Right | |
if (faceXPos >= (screenWidth - faceBMP.Width)) | |
{ | |
upwardEnergy--; | |
faceYPos -= upwardEnergy; | |
isDirectionRight = false; | |
} | |
// Left | |
if (faceXPos <= 0) | |
{ | |
upwardEnergy--; | |
faceYPos -= upwardEnergy; | |
isDirectionRight = true; | |
} | |
// Bottom of screen & no energy? | |
// End simulation | |
if(faceYPos >= (screenWidth - faceBMP.Width) && upwardEnergy == 0) | |
{ | |
break; | |
} | |
thisGFX.DrawImage(faceBMP, new Point((int)faceXPos, (int)faceYPos)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment