Rev 1 |
Rev 5 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Created by SharpDevelop.
* User: Freddie
* Date: 28/05/2010
* Time: 20:58
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;
namespace blockade
{
/// <summary>
/// Description of Form2.
/// </summary>
public partial class Form2
: Form
{
public class smoke
{
public Point loc
;
public Color colour
;
public smoke
(Point locN, Color colourN
)
{
loc
= locN
;
colour
= colourN
;
}
}
Image bgImg, fgImg
;
int sel
= 0;
int glow
= 0;
int scroll
= 0;
float offX, offY, cX, cY
;
string[] langList
;
int lang
= 0;
int cDelay
;
bool changeLang
;
string[] play
;
string[] credits
;
string[] exit
;
string[] language
;
string[] creditsList
;
string pattern
= "";
List
<smoke
> smokes
= new List
<smoke
>();
bool smokeOn
= false;
bool hover
= false;
Random rnd
= new Random
();
public Form2
()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent
();
}
void Form2Load
(object sender, EventArgs e
)
{
System.IO.StreamReader reader
= new System.IO.StreamReader(@"data/menuStart.dat",
System.Text.Encoding.UTF8);
string[] data
= reader
.ReadToEnd().Split(',');
langList
= new string[2];
bgImg
= Image
.FromFile(@"data/" + data
[0]);
fgImg
= Image
.FromFile(@"data/" + data
[1]);
cDelay
= int.Parse(data
[2]);
offX
= (bgImg
.Width - 300) / 2;
offY
= (bgImg
.Height - 300) / 2;
cX
= 0
.5f
;
cY
= 0
.5f
;
if (data
[3] == "1")
smokeOn
= true;
reader
= new System.IO.StreamReader(@"data/menuTexts.dat",
System.Text.Encoding.UTF8);
string[] lines
= reader
.ReadToEnd().Split('\n');
langList
= lines
[0].Split(':');
play
= lines
[1].Split(':');
credits
= lines
[2].Split(':');
exit
= lines
[3].Split(':');
language
= lines
[4].Split(':');
reader
= new System.IO.StreamReader(@"data/credits.dat",
System.Text.Encoding.UTF8);
creditsList
= reader
.ReadToEnd().Split('\n');
reader
.Close();
timer1
.Start();
}
void draw
()
{
Bitmap img
= new Bitmap
(300,
300);
Graphics g
= Graphics
.FromImage(img
);
if (hover
)
{
//make BLUE only array
float[][] blueArray
= {
new float[] { 0,
0,
0,
0,
0 },
new float[] { 0,
0,
0,
0,
0 },
new float[] { 0,
0,
1,
0,
0 },
new float[] { 0,
0,
0,
1,
0 },
new float[] { 0,
0,
0,
0,
1 }
};
System.Drawing.Imaging.ColorMatrix colourMatrix
= new System.Drawing.Imaging.ColorMatrix(blueArray
);
System.Drawing.Imaging.ImageAttributes imgAttributes
= new System.Drawing.Imaging.ImageAttributes();
imgAttributes
.SetColorMatrix(colourMatrix,
System.Drawing.Imaging.ColorMatrixFlag.Default,
System.Drawing.Imaging.ColorAdjustType.Default);
Bitmap bgImgN
= (Bitmap
)bgImg
;
g
.DrawImage(bgImgN,
new Rectangle
((int)-offX,
(int)-offY, bgImg
.Width, bgImg
.Height),
0,
0, bgImg
.Width, bgImg
.Height, GraphicsUnit
.Pixel, imgAttributes
);
}
else
g
.DrawImage(bgImg,
-offX,
-offY
);
g
.DrawImage(fgImg,
0,
0,
300,
300);
StringFormat sf
= new StringFormat
();
sf
.Alignment = StringAlignment
.Center;
Font font1
;
if (changeLang
)
{
font1
= new Font
(FontFamily
.GenericMonospace,
13, FontStyle
.Bold);
for (int i
= 0; i
< langList
.Length; i
++)
{
if (lang
== i
)
g
.DrawString("--> " + langList
[i
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(0 - scroll
* 25
.5f
),
255 - Math
.Abs(glow
) * 5, Math
.Abs(glow
) * 25,
0)),
150,
70 + i
* 18, sf
);
else
g
.DrawString("--> " + langList
[i
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(0 - scroll
* 25
.5f
), Color
.White)),
150,
70 + i
* 18, sf
);
}
}
else if (scroll
< 1)
{
font1
= new Font
(FontFamily
.GenericMonospace,
20, FontStyle
.Bold);
if (sel
== 0)
g
.DrawString("--> " + play
[lang
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
),
255 - Math
.Abs(glow
) * 5, Math
.Abs(glow
) * 25,
0)),
150,
80, sf
);
else
g
.DrawString("--- " + play
[lang
] + " ---", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
), Color
.White)),
150,
80, sf
);
if (sel
== 1)
g
.DrawString("--> " + credits
[lang
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
),
255 - Math
.Abs(glow
) * 5, Math
.Abs(glow
) * 25,
0)),
150,
120, sf
);
else
g
.DrawString("--- " + credits
[lang
] + " ---", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
), Color
.White)),
150,
120, sf
);
if (sel
== 2)
g
.DrawString("--> " + exit
[lang
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
),
255 - Math
.Abs(glow
) * 5, Math
.Abs(glow
) * 25,
0)),
150,
160, sf
);
else
g
.DrawString("--- " + exit
[lang
] + " ---", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
), Color
.White)),
150,
160, sf
);
if (sel
== 3)
g
.DrawString("--> " + language
[lang
] + " <--", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
),
255 - Math
.Abs(glow
) * 5, Math
.Abs(glow
) * 25,
0)),
150,
200, sf
);
else
g
.DrawString("--- " + language
[lang
] + " ---", font1,
new SolidBrush
(Color
.FromArgb((int)(255 + scroll
* 25
.5f
), Color
.White)),
150,
200, sf
);
}
else
{
Image tempImg
;
for (int i
= 0; i
< creditsList
.Length; i
++)
{
if (scroll
> i
* cDelay
&& scroll
< 100 + i
* cDelay
)
{
if (creditsList
[i
].Substring(0,
1) == "i")
{
tempImg
= Image
.FromFile(@"data/" + creditsList
[i
].Substring(1));
g
.DrawImage(tempImg,
150 - tempImg
.Width / 2,
180 - (int)(scroll
- i
* cDelay
));
}
else
{
switch (creditsList
[i
].Substring(0,
1))
{
case ("b"):
font1
= new Font
(FontFamily
.GenericMonospace,
16, FontStyle
.Bold);
break;
case ("l"):
font1
= new Font
(FontFamily
.GenericMonospace,
20, FontStyle
.Bold);
break;
default:
font1
= new Font
(FontFamily
.GenericMonospace,
13, FontStyle
.Bold);
break;
}
if (hover
)
g
.DrawString(creditsList
[i
].Substring(1), font1,
new SolidBrush
(Color
.FromArgb(255 - (int)(Math
.Abs((scroll
- i
* cDelay
) - 50) / 50
.0f
* 255
.0f
),
0,
0,
255)),
150,
200 - (int)(scroll
- i
* cDelay
), sf
);
else
g
.DrawString(creditsList
[i
].Substring(1), font1,
new SolidBrush
(Color
.FromArgb(255 - (int)(Math
.Abs((scroll
- i
* cDelay
) - 50) / 50
.0f
* 255
.0f
),
255,
255,
255)),
150,
200 - (int)(scroll
- i
* cDelay
), sf
);
}
}
}
}
if (smokeOn
)
{
for (int i
= 0; i
< smokes
.Count; i
++)
g
.FillEllipse(new SolidBrush
(smokes
[i
].colour), smokes
[i
].loc.X - 1, smokes
[i
].loc.Y - 1,
2,
2);
}
this.BackgroundImage = (Image
)img
.Clone();
g
.Dispose();
img
.Dispose();
}
void go
()
{
Form1 game
= new Form1
(lang
);
game
.Show();
if (pattern
== "3141")
{
game
.towerTypes.Add(new Form1
.towerType("Blue",
"100000",
"5000",
"10000",
"700",
"1000",
"10000",
"0",
"go.png:1",
"basicTurret.png:10:hyperTurret.png:10:protonTurret.Png:10:neutronTurret1.png:10:craverTurret1.png:10:rackerTurret1.png:10:wraverTurret1.png:10",
"single1.wav",
"2",
"250",
"5",
"Tim32 SuperSheep-0 'Lassitor'",
"Lassitor:Lassitor:Lassitor:Lassitor:Lassitor:Lassitor:Lassitor:Lassitor:Lassitor"));
}
timer1
.Stop();
this.Hide();
}
void viewCredits
()
{
scroll
= 1;
}
void Form2KeyDown
(object sender, KeyEventArgs e
)
{
if (changeLang
)
{
if (e
.KeyCode == Keys
.Up)
{
lang
--;
if (lang
< 0)
lang
= langList
.Length - 1;
}
else if (e
.KeyCode == Keys
.Down)
{
lang
++;
if (lang
> langList
.Length - 1)
lang
= 0;
}
}
else
{
if (e
.KeyCode == Keys
.Up)
{
sel
--;
if (sel
< 0)
sel
= 3;
}
else if (e
.KeyCode == Keys
.Down)
{
sel
++;
if (sel
> 3)
sel
= 0;
}
}
if (e
.KeyCode == Keys
.Enter)
{
if (changeLang
)
{
changeLang
= false;
pattern
+= lang
;
}
else if (scroll
== 0)
{
if (sel
== 0)
go
();
else if (sel
== 1)
viewCredits
();
else if (sel
== 3)
{
scroll
= 0;
changeLang
= true;
}
else
Application
.ExitThread();
}
else
scroll
= -10;
}
draw
();
}
void Timer1Tick
(object sender, EventArgs e
)
{
if (scroll
< 1)
{
glow
++;
if (glow
> 10)
glow
= -10;
}
if (changeLang
)
{
scroll
--;
if (scroll
< -10)
scroll
= -10;
}
else if (scroll
!= 0)
{
scroll
++;
if (scroll
> creditsList
.Length * cDelay
+ 100)
{
scroll
= -10;
}
}
offX
+= cX
;
offY
+= cY
;
if (offX
< 0
.0f
)
{
cX
= 0
.5f
;
offX
= 0
.0f
;
}
else if (offX
> bgImg
.Width - 300
.0f
)
{
cX
= -0
.5f
;
offX
= bgImg
.Width - 300
.0f
;
}
if (offY
< 0
.0f
)
{
cY
= 0
.5f
;
offY
= 0
.0f
;
}
else if (offY
> bgImg
.Height - 300
.0f
)
{
cY
= -0
.5f
;
offY
= bgImg
.Height - 300
.0f
;
}
if (smokeOn
)
{
for (int i
= smokes
.Count - 1; i
>= 0; i
--)
{
if (rnd
.Next(0,
18) == 0)
smokes
.RemoveAt(i
);
else
{
if (rnd
.Next(0,
2) == 0)
smokes
[i
].loc.X--;
if (rnd
.Next(0,
2) == 0)
smokes
[i
].loc.Y--;
}
}
int grey
;
for (int i
= 0; i
< 10; i
++)
{
if (rnd
.Next(0,
5) < 3)
{
grey
= rnd
.Next(50,
200);
if (hover
)
smokes
.Add(new smoke
(new Point
(187,
275), Color
.FromArgb(200,
0,
0, grey
)));
else
smokes
.Add(new smoke
(new Point
(187,
275), Color
.FromArgb(200, grey, grey, grey
)));
}
}
}
draw
();
}
void Form2FormClosing
(object sender, FormClosingEventArgs e
)
{
Application
.ExitThread();
}
void Form2MouseClick
(object sender, MouseEventArgs e
)
{
if (Math
.Abs(e
.X - 193) < 3 && Math
.Abs(e
.Y - 285) < 3)
{
System.Diagnostics.Process p
= new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi
= new System.Diagnostics.ProcessStartInfo();
psi
.FileName = "http://tim32.org";
p
.StartInfo = psi
;
p
.Start();
}
}
void Form2MouseMove
(object sender, MouseEventArgs e
)
{
if (Math
.Abs(e
.X - 193) < 3 && Math
.Abs(e
.Y - 285) < 3)
hover
= true;
else
hover
= false;
}
}
}