Rev 4 | Go to most recent revision | 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; |
||
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") |
||
4 | freddie | 80 | smokeOn = true; |
1 | freddie | 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; |
||
5 | freddie | 190 | case ("s"): |
191 | font1 = new Font(FontFamily.GenericMonospace, 8, FontStyle.Bold); |
||
192 | break; |
||
193 | case ("n"): |
||
194 | font1 = new Font(FontFamily.GenericMonospace, 13, FontStyle.Bold); |
||
195 | break; |
||
1 | freddie | 196 | default: |
197 | font1 = new Font(FontFamily.GenericMonospace, 13, FontStyle.Bold); |
||
198 | break; |
||
199 | } |
||
200 | if (hover) |
||
201 | 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); |
||
202 | else |
||
203 | 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); |
||
204 | } |
||
205 | } |
||
206 | } |
||
207 | |||
208 | } |
||
209 | |||
210 | if (smokeOn) |
||
211 | { |
||
212 | for (int i = 0; i < smokes.Count; i++) |
||
213 | g.FillEllipse(new SolidBrush(smokes[i].colour), smokes[i].loc.X - 1, smokes[i].loc.Y - 1, 2, 2); |
||
214 | } |
||
215 | |||
216 | this.BackgroundImage = (Image)img.Clone(); |
||
217 | |||
218 | g.Dispose(); |
||
219 | img.Dispose(); |
||
220 | |||
221 | } |
||
222 | |||
223 | void go() |
||
224 | { |
||
225 | Form1 game = new Form1(lang); |
||
226 | game.Show(); |
||
227 | if (pattern == "3141") |
||
228 | { |
||
229 | 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")); |
||
230 | } |
||
231 | timer1.Stop(); |
||
232 | this.Hide(); |
||
233 | } |
||
234 | |||
235 | void viewCredits() |
||
236 | { |
||
237 | scroll = 1; |
||
238 | } |
||
239 | |||
240 | void Form2KeyDown(object sender, KeyEventArgs e) |
||
241 | { |
||
242 | if (changeLang) |
||
243 | { |
||
244 | if (e.KeyCode == Keys.Up) |
||
245 | { |
||
246 | lang--; |
||
247 | if (lang < 0) |
||
248 | lang = langList.Length - 1; |
||
249 | } |
||
250 | else if (e.KeyCode == Keys.Down) |
||
251 | { |
||
252 | lang++; |
||
253 | if (lang > langList.Length - 1) |
||
254 | lang = 0; |
||
255 | } |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | if (e.KeyCode == Keys.Up) |
||
260 | { |
||
261 | sel--; |
||
262 | if (sel < 0) |
||
263 | sel = 3; |
||
264 | } |
||
265 | else if (e.KeyCode == Keys.Down) |
||
266 | { |
||
267 | sel++; |
||
268 | if (sel > 3) |
||
269 | sel = 0; |
||
270 | } |
||
271 | } |
||
272 | if (e.KeyCode == Keys.Enter) |
||
273 | { |
||
274 | if (changeLang) |
||
275 | { |
||
276 | changeLang = false; |
||
277 | pattern += lang; |
||
278 | } |
||
279 | else if (scroll == 0) |
||
280 | { |
||
281 | if (sel == 0) |
||
282 | go(); |
||
283 | else if (sel == 1) |
||
284 | viewCredits(); |
||
285 | else if (sel == 3) |
||
286 | { |
||
287 | scroll = 0; |
||
288 | changeLang = true; |
||
289 | } |
||
290 | else |
||
291 | Application.ExitThread(); |
||
292 | } |
||
293 | else |
||
294 | scroll = -10; |
||
295 | } |
||
296 | draw(); |
||
297 | } |
||
298 | |||
299 | void Timer1Tick(object sender, EventArgs e) |
||
300 | { |
||
301 | if (scroll < 1) |
||
302 | { |
||
303 | glow++; |
||
304 | if (glow > 10) |
||
305 | glow = -10; |
||
306 | } |
||
307 | if (changeLang) |
||
308 | { |
||
309 | scroll--; |
||
310 | if (scroll < -10) |
||
311 | scroll = -10; |
||
312 | } |
||
313 | else if (scroll != 0) |
||
314 | { |
||
315 | scroll++; |
||
316 | if (scroll > creditsList.Length * cDelay + 100) |
||
317 | { |
||
318 | scroll = -10; |
||
319 | } |
||
320 | } |
||
321 | |||
322 | offX += cX; |
||
323 | offY += cY; |
||
324 | |||
325 | if (offX < 0.0f) |
||
326 | { |
||
327 | cX = 0.5f; |
||
328 | offX = 0.0f; |
||
329 | } |
||
330 | else if (offX > bgImg.Width - 300.0f) |
||
331 | { |
||
332 | cX = -0.5f; |
||
333 | offX = bgImg.Width - 300.0f; |
||
334 | } |
||
335 | if (offY < 0.0f) |
||
336 | { |
||
337 | cY = 0.5f; |
||
338 | offY = 0.0f; |
||
339 | } |
||
340 | else if (offY > bgImg.Height - 300.0f) |
||
341 | { |
||
342 | cY = -0.5f; |
||
343 | offY = bgImg.Height - 300.0f; |
||
344 | } |
||
345 | |||
346 | if (smokeOn) |
||
347 | { |
||
348 | for (int i = smokes.Count - 1; i >= 0; i--) |
||
349 | { |
||
350 | if (rnd.Next(0, 18) == 0) |
||
351 | smokes.RemoveAt(i); |
||
352 | else |
||
353 | { |
||
354 | if (rnd.Next(0, 2) == 0) |
||
355 | smokes[i].loc.X--; |
||
356 | if (rnd.Next(0, 2) == 0) |
||
357 | smokes[i].loc.Y--; |
||
358 | } |
||
359 | } |
||
360 | |||
361 | int grey; |
||
362 | |||
363 | for (int i = 0; i < 10; i++) |
||
364 | { |
||
365 | if (rnd.Next(0,5) < 3) |
||
366 | { |
||
367 | grey = rnd.Next(50, 200); |
||
368 | if (hover) |
||
369 | smokes.Add(new smoke(new Point(187, 275), Color.FromArgb(200, 0, 0, grey))); |
||
370 | else |
||
371 | smokes.Add(new smoke(new Point(187, 275), Color.FromArgb(200, grey, grey, grey))); |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | |||
376 | draw(); |
||
377 | } |
||
378 | |||
379 | void Form2FormClosing(object sender, FormClosingEventArgs e) |
||
380 | { |
||
381 | Application.ExitThread(); |
||
382 | } |
||
383 | |||
384 | void Form2MouseClick(object sender, MouseEventArgs e) |
||
385 | { |
||
386 | if (Math.Abs(e.X - 193) < 3 && Math.Abs(e.Y - 285) < 3) |
||
387 | { |
||
388 | System.Diagnostics.Process p = new System.Diagnostics.Process(); |
||
389 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); |
||
390 | psi.FileName = "http://tim32.org"; |
||
391 | p.StartInfo = psi; |
||
392 | p.Start(); |
||
393 | } |
||
394 | } |
||
395 | |||
396 | void Form2MouseMove(object sender, MouseEventArgs e) |
||
397 | { |
||
398 | if (Math.Abs(e.X - 193) < 3 && Math.Abs(e.Y - 285) < 3) |
||
399 | hover = true; |
||
400 | else |
||
401 | hover = false; |
||
402 | } |
||
403 | } |
||
404 | } |