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