Rev 5 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | freddie | 1 | /* |
2 | * Created by SharpDevelop. |
||
3 | * User: Freddie |
||
4 | * Date: 28/05/2010 |
||
5 | * Time: 20:58 |
||
6 | * |
||
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers. |
||
8 | */ |
||
9 | using System; |
||
10 | using System.Drawing; |
||
11 | using System.Collections.Generic; |
||
12 | using System.Windows.Forms; |
||
13 | |||
14 | namespace blockade |
||
15 | { |
||
16 | /// <summary> |
||
17 | /// Description of Form2. |
||
18 | /// </summary> |
||
19 | public partial class Form2 : Form |
||
20 | { |
||
21 | |||
22 | public class smoke |
||
23 | { |
||
24 | public Point loc; |
||
25 | public Color colour; |
||
26 | |||
27 | public smoke(Point locN, Color colourN) |
||
28 | { |
||
29 | loc = locN; |
||
30 | colour = colourN; |
||
31 | } |
||
32 | } |
||
33 | |||
34 | Image bgImg, fgImg; |
||
35 | int sel = 0; |
||
36 | int glow = 0; |
||
37 | int scroll = 0; |
||
38 | float offX, offY, cX, cY; |
||
39 | string[] langList; |
||
40 | int lang = 0; |
||
41 | int cDelay; |
||
42 | bool changeLang; |
||
43 | string[] play; |
||
44 | string[] credits; |
||
45 | string[] exit; |
||
46 | string[] language; |
||
47 | |||
48 | string[] creditsList; |
||
49 | |||
50 | string pattern = ""; |
||
51 | |||
52 | List<smoke> smokes = new List<smoke>(); |
||
53 | bool smokeOn = false; |
||
54 | bool hover = false; |
||
55 | Random rnd = new Random(); |
||
56 | |||
57 | public Form2() |
||
58 | { |
||
59 | // |
||
60 | // The InitializeComponent() call is required for Windows Forms designer support. |
||
61 | // |
||
62 | InitializeComponent(); |
||
63 | } |
||
64 | |||
65 | void Form2Load(object sender, EventArgs e) |
||
66 | { |
||
67 | |||
68 | System.IO.StreamReader reader = new System.IO.StreamReader(@"data/menuStart.dat", System.Text.Encoding.UTF8); |
||
69 | string[] data = reader.ReadToEnd().Split(','); |
||
70 | |||
71 | langList = new string[2]; |
||
72 | bgImg = Image.FromFile(@"data/" + data[0]); |
||
73 | fgImg = Image.FromFile(@"data/" + data[1]); |
||
74 | cDelay = int.Parse(data[2]); |
||
75 | offX = (bgImg.Width - 300) / 2; |
||
76 | offY = (bgImg.Height - 300) / 2; |
||
77 | cX = 0.5f; |
||
78 | cY = 0.5f; |
||
79 | if (data[3] == "1") |
||
80 | smokeOn = true; |
||
81 | |||
82 | reader = new System.IO.StreamReader(@"data/menuTexts.dat", System.Text.Encoding.UTF8); |
||
83 | string[] lines = reader.ReadToEnd().Split('\n'); |
||
84 | langList = lines[0].Split(':'); |
||
85 | play = lines[1].Split(':'); |
||
86 | credits = lines[2].Split(':'); |
||
87 | exit = lines[3].Split(':'); |
||
88 | language = lines[4].Split(':'); |
||
89 | |||
90 | reader = new System.IO.StreamReader(@"data/credits.dat", System.Text.Encoding.UTF8); |
||
91 | creditsList = reader.ReadToEnd().Split('\n'); |
||
92 | |||
93 | reader.Close(); |
||
94 | |||
95 | timer1.Start(); |
||
96 | } |
||
97 | |||
98 | void draw() |
||
99 | { |
||
100 | Bitmap img = new Bitmap(300, 300); |
||
101 | Graphics g = Graphics.FromImage(img); |
||
102 | |||
103 | if (hover) |
||
104 | { |
||
105 | //make BLUE only array |
||
106 | float[][] blueArray = { |
||
107 | new float[] { 0, 0, 0, 0, 0 }, |
||
108 | new float[] { 0, 0, 0, 0, 0 }, |
||
109 | new float[] { 0, 0, 1, 0, 0 }, |
||
110 | new float[] { 0, 0, 0, 1, 0 }, |
||
111 | new float[] { 0, 0, 0, 0, 1 } |
||
112 | }; |
||
113 | System.Drawing.Imaging.ColorMatrix colourMatrix = new System.Drawing.Imaging.ColorMatrix(blueArray); |
||
114 | System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes(); |
||
115 | imgAttributes.SetColorMatrix(colourMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default); |
||
116 | |||
117 | Bitmap bgImgN = (Bitmap)bgImg; |
||
118 | |||
119 | g.DrawImage(bgImgN, new Rectangle((int)-offX, (int)-offY, bgImg.Width, bgImg.Height), 0, 0, bgImg.Width, bgImg.Height, GraphicsUnit.Pixel, imgAttributes); |
||
120 | } |
||
121 | else |
||
122 | g.DrawImage(bgImg, -offX, -offY); |
||
123 | |||
124 | g.DrawImage(fgImg, 0, 0, 300, 300); |
||
125 | |||
126 | StringFormat sf = new StringFormat(); |
||
127 | sf.Alignment = StringAlignment.Center; |
||
128 | |||
129 | Font font1; |
||
130 | |||
131 | if (changeLang) |
||
132 | { |
||
133 | font1 = new Font(FontFamily.GenericMonospace, 13, FontStyle.Bold); |
||
134 | |||
135 | for (int i = 0; i < langList.Length; i++) |
||
136 | { |
||
137 | if (lang == i) |
||
138 | 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); |
||
139 | else |
||
140 | g.DrawString("--> " + langList[i] + " <--", font1, new SolidBrush(Color.FromArgb((int)(0 - scroll * 25.5f), Color.White)), 150, 70 + i * 18, sf); |
||
141 | } |
||
142 | } |
||
143 | else if (scroll < 1) |
||
144 | { |
||
145 | |||
146 | font1 = new Font(FontFamily.GenericMonospace, 20, FontStyle.Bold); |
||
147 | |||
148 | if (sel == 0) |
||
149 | 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); |
||
150 | else |
||
151 | g.DrawString("--- " + play[lang] + " ---", font1, new SolidBrush(Color.FromArgb((int)(255 + scroll * 25.5f), Color.White)), 150, 80, sf); |
||
152 | if (sel == 1) |
||
153 | 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); |
||
154 | else |
||
155 | g.DrawString("--- " + credits[lang] + " ---", font1, new SolidBrush(Color.FromArgb((int)(255 + scroll * 25.5f), Color.White)), 150, 120, sf); |
||
156 | if (sel == 2) |
||
157 | 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); |
||
158 | else |
||
159 | g.DrawString("--- " + exit[lang] + " ---", font1, new SolidBrush(Color.FromArgb((int)(255 + scroll * 25.5f), Color.White)), 150, 160, sf); |
||
160 | if (sel == 3) |
||
161 | 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); |
||
162 | else |
||
163 | g.DrawString("--- " + language[lang] + " ---", font1, new SolidBrush(Color.FromArgb((int)(255 + scroll * 25.5f), Color.White)), 150, 200, sf); |
||
164 | |||
165 | } |
||
166 | else |
||
167 | { |
||
168 | |||
169 | Image tempImg; |
||
170 | |||
171 | for (int i = 0; i < creditsList.Length; i++) |
||
172 | { |
||
173 | if (scroll > i * cDelay && scroll < 100 + i * cDelay) |
||
174 | { |
||
175 | if (creditsList[i].Substring(0, 1) == "i") |
||
176 | { |
||
177 | tempImg = Image.FromFile(@"data/" + creditsList[i].Substring(1)); |
||
178 | g.DrawImage(tempImg, 150 - tempImg.Width / 2, 180 - (int)(scroll - i * cDelay)); |
||
179 | } |
||
180 | else |
||
181 | { |
||
182 | switch (creditsList[i].Substring(0, 1)) |
||
183 | { |
||
184 | case ("b"): |
||
185 | font1 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold); |
||
186 | break; |
||
187 | case ("l"): |
||
188 | font1 = new Font(FontFamily.GenericMonospace, 20, FontStyle.Bold); |
||
189 | break; |
||
190 | default: |
||
191 | font1 = new Font(FontFamily.GenericMonospace, 13, FontStyle.Bold); |
||
192 | break; |
||
193 | } |
||
194 | if (hover) |
||
195 | 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); |
||
196 | else |
||
197 | 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); |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | |||
202 | } |
||
203 | |||
204 | if (smokeOn) |
||
205 | { |
||
206 | for (int i = 0; i < smokes.Count; i++) |
||
207 | g.FillEllipse(new SolidBrush(smokes[i].colour), smokes[i].loc.X - 1, smokes[i].loc.Y - 1, 2, 2); |
||
208 | } |
||
209 | |||
210 | this.BackgroundImage = (Image)img.Clone(); |
||
211 | |||
212 | g.Dispose(); |
||
213 | img.Dispose(); |
||
214 | |||
215 | } |
||
216 | |||
217 | void go() |
||
218 | { |
||
219 | Form1 game = new Form1(lang); |
||
220 | game.Show(); |
||
221 | if (pattern == "3141") |
||
222 | { |
||
223 | 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")); |
||
224 | } |
||
225 | timer1.Stop(); |
||
226 | this.Hide(); |
||
227 | } |
||
228 | |||
229 | void viewCredits() |
||
230 | { |
||
231 | scroll = 1; |
||
232 | } |
||
233 | |||
234 | void Form2KeyDown(object sender, KeyEventArgs e) |
||
235 | { |
||
236 | if (changeLang) |
||
237 | { |
||
238 | if (e.KeyCode == Keys.Up) |
||
239 | { |
||
240 | lang--; |
||
241 | if (lang < 0) |
||
242 | lang = langList.Length - 1; |
||
243 | } |
||
244 | else if (e.KeyCode == Keys.Down) |
||
245 | { |
||
246 | lang++; |
||
247 | if (lang > langList.Length - 1) |
||
248 | lang = 0; |
||
249 | } |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | if (e.KeyCode == Keys.Up) |
||
254 | { |
||
255 | sel--; |
||
256 | if (sel < 0) |
||
257 | sel = 3; |
||
258 | } |
||
259 | else if (e.KeyCode == Keys.Down) |
||
260 | { |
||
261 | sel++; |
||
262 | if (sel > 3) |
||
263 | sel = 0; |
||
264 | } |
||
265 | } |
||
266 | if (e.KeyCode == Keys.Enter) |
||
267 | { |
||
268 | if (changeLang) |
||
269 | { |
||
270 | changeLang = false; |
||
271 | pattern += lang; |
||
272 | } |
||
273 | else if (scroll == 0) |
||
274 | { |
||
275 | if (sel == 0) |
||
276 | go(); |
||
277 | else if (sel == 1) |
||
278 | viewCredits(); |
||
279 | else if (sel == 3) |
||
280 | { |
||
281 | scroll = 0; |
||
282 | changeLang = true; |
||
283 | } |
||
284 | else |
||
285 | Application.ExitThread(); |
||
286 | } |
||
287 | else |
||
288 | scroll = -10; |
||
289 | } |
||
290 | draw(); |
||
291 | } |
||
292 | |||
293 | void Timer1Tick(object sender, EventArgs e) |
||
294 | { |
||
295 | if (scroll < 1) |
||
296 | { |
||
297 | glow++; |
||
298 | if (glow > 10) |
||
299 | glow = -10; |
||
300 | } |
||
301 | if (changeLang) |
||
302 | { |
||
303 | scroll--; |
||
304 | if (scroll < -10) |
||
305 | scroll = -10; |
||
306 | } |
||
307 | else if (scroll != 0) |
||
308 | { |
||
309 | scroll++; |
||
310 | if (scroll > creditsList.Length * cDelay + 100) |
||
311 | { |
||
312 | scroll = -10; |
||
313 | } |
||
314 | } |
||
315 | |||
316 | offX += cX; |
||
317 | offY += cY; |
||
318 | |||
319 | if (offX < 0.0f) |
||
320 | { |
||
321 | cX = 0.5f; |
||
322 | offX = 0.0f; |
||
323 | } |
||
324 | else if (offX > bgImg.Width - 300.0f) |
||
325 | { |
||
326 | cX = -0.5f; |
||
327 | offX = bgImg.Width - 300.0f; |
||
328 | } |
||
329 | if (offY < 0.0f) |
||
330 | { |
||
331 | cY = 0.5f; |
||
332 | offY = 0.0f; |
||
333 | } |
||
334 | else if (offY > bgImg.Height - 300.0f) |
||
335 | { |
||
336 | cY = -0.5f; |
||
337 | offY = bgImg.Height - 300.0f; |
||
338 | } |
||
339 | |||
340 | if (smokeOn) |
||
341 | { |
||
342 | for (int i = smokes.Count - 1; i >= 0; i--) |
||
343 | { |
||
344 | if (rnd.Next(0, 18) == 0) |
||
345 | smokes.RemoveAt(i); |
||
346 | else |
||
347 | { |
||
348 | if (rnd.Next(0, 2) == 0) |
||
349 | smokes[i].loc.X--; |
||
350 | if (rnd.Next(0, 2) == 0) |
||
351 | smokes[i].loc.Y--; |
||
352 | } |
||
353 | } |
||
354 | |||
355 | int grey; |
||
356 | |||
357 | for (int i = 0; i < 10; i++) |
||
358 | { |
||
359 | if (rnd.Next(0,5) < 3) |
||
360 | { |
||
361 | grey = rnd.Next(50, 200); |
||
362 | if (hover) |
||
363 | smokes.Add(new smoke(new Point(187, 275), Color.FromArgb(200, 0, 0, grey))); |
||
364 | else |
||
365 | smokes.Add(new smoke(new Point(187, 275), Color.FromArgb(200, grey, grey, grey))); |
||
366 | } |
||
367 | } |
||
368 | } |
||
369 | |||
370 | draw(); |
||
371 | } |
||
372 | |||
373 | void Form2FormClosing(object sender, FormClosingEventArgs e) |
||
374 | { |
||
375 | Application.ExitThread(); |
||
376 | } |
||
377 | |||
378 | void Form2MouseClick(object sender, MouseEventArgs e) |
||
379 | { |
||
380 | if (Math.Abs(e.X - 193) < 3 && Math.Abs(e.Y - 285) < 3) |
||
381 | { |
||
382 | System.Diagnostics.Process p = new System.Diagnostics.Process(); |
||
383 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); |
||
384 | psi.FileName = "http://tim32.org"; |
||
385 | p.StartInfo = psi; |
||
386 | p.Start(); |
||
387 | } |
||
388 | } |
||
389 | |||
390 | void Form2MouseMove(object sender, MouseEventArgs e) |
||
391 | { |
||
392 | if (Math.Abs(e.X - 193) < 3 && Math.Abs(e.Y - 285) < 3) |
||
393 | hover = true; |
||
394 | else |
||
395 | hover = false; |
||
396 | } |
||
397 | } |
||
398 | } |