- Timestamp:
- 2010-07-08 22:47:38 (13 years ago)
- Location:
- 2010/27/anlakane/Nopeuspeli
- Files:
-
- 10 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/27/anlakane/Nopeuspeli/Nopeuspeli.csproj
r1207 r1208 59 59 <Reference Include="Jypeli2, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86"> 60 60 <SpecificVersion>False</SpecificVersion> 61 <HintPath>..\..\ lib\Jypeli2.dll</HintPath>61 <HintPath>..\..\..\..\..\npo\trunk\lib\Jypeli2.dll</HintPath> 62 62 </Reference> 63 63 <Reference Include="Microsoft.Xna.Framework, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d" /> -
2010/27/anlakane/Nopeuspeli/Peli.cs
r1207 r1208 8 8 { 9 9 List<GameObject> painikkeet; 10 List<GameObject> painamattomat; 10 11 const double painikkeenLeveys = 100; 11 12 const double painikkeenKorkeus = painikkeenLeveys; 12 13 Timer painikkeidenSytytin; 14 Timer nopeutusAjastin; 15 Timer aikaaPainaaUuttaNappia; 16 17 int painikkeidenMaara; 18 int montakoPainikettaPainettu; 13 19 14 20 protected override void Begin() 15 21 { 16 22 painikkeet = new List<GameObject>(); 23 painamattomat = new List<GameObject>(); 24 painikkeidenMaara = 4; 17 25 26 Level.Background.Image = LoadImage("tausta"); 27 Level.Background.Size = new Vector(Screen.Width, Screen.Height); 28 MessageDisplay.TextColor = Color.White; 18 29 LisaaNappaimet(); 19 30 LisaaPainikkeet(); … … 24 35 void LisaaPainikkeet() 25 36 { 26 for (int i = 0; i < 8; i++)37 for (int i = 0; i < painikkeidenMaara; i++) 27 38 { 28 39 Add(LuoPainike()); 29 40 } 30 31 41 } 32 42 … … 38 48 byte g = painike.Color.GreenComponent; 39 49 byte b = painike.Color.BlueComponent; 40 r = (byte)((double)r / 2);41 g = (byte)((double)g / 2);42 b = (byte)((double)b / 2);50 r = (byte)((double)r / 1.5); 51 g = (byte)((double)g / 1.5); 52 b = (byte)((double)b / 1.5); 43 53 painike.Color = new Color(r, g, b); 44 54 45 55 painikkeet.Add(painike); 46 painike.X = -(4 * (painikkeenLeveys + 20)) + ((painikkeet.Count) * (painikkeenLeveys + 20)) - 60; 56 painike.X = -((painikkeidenMaara / 2) * (painikkeenLeveys + 20)) + ((painikkeet.Count) * (painikkeenLeveys + 20)) - 20; 57 painike.Tag = painikkeet.Count.ToString(); 58 painike.Image = LoadImage((painikkeet.Count - 1).ToString() + "_"); 47 59 return painike; 48 60 } … … 50 62 void LisaaNappaimet() 51 63 { 64 Keyboard.Listen(Key.A, ButtonState.Pressed, NappainPainettu, null, 0); 65 Keyboard.Listen(Key.S, ButtonState.Pressed, NappainPainettu, null, 1); 66 Keyboard.Listen(Key.D, ButtonState.Pressed, NappainPainettu, null, 2); 67 Keyboard.Listen(Key.F, ButtonState.Pressed, NappainPainettu, null, 3); 68 //Keyboard.Listen(Key.J, ButtonState.Pressed, NappainPainettu, null, 4); 69 //Keyboard.Listen(Key.K, ButtonState.Pressed, NappainPainettu, null, 5); 70 //Keyboard.Listen(Key.L, ButtonState.Pressed, NappainPainettu, null, 6); 71 //Keyboard.Listen(Key., ButtonState.Pressed, NappainPainettu, null, 7); 52 72 73 } 74 75 void NappainPainettu(int painikeIndeksi) 76 { 77 if (painamattomat.Count < 1 || painamattomat[0].Tag.ToString() != (painikeIndeksi + 1).ToString()) 78 { 79 PeliPaattyy(new Timer()); 80 } 81 else 82 { 83 painamattomat.RemoveAt(0); 84 aikaaPainaaUuttaNappia.Reset(); 85 } 86 } 87 88 void PeliPaattyy(Timer t) 89 { 90 ClearTimers(); 91 for (int i = 0; i < painikkeet.Count; i++) 92 Sytyta(painikkeet[i], i); 53 93 } 54 94 … … 57 97 painikkeidenSytytin = new Timer(); 58 98 painikkeidenSytytin.Interval = 1; 59 painikkeidenSytytin.Trigger += Sytyta Painike;99 painikkeidenSytytin.Trigger += SytytaJokinPainike; 60 100 Add(painikkeidenSytytin); 61 101 painikkeidenSytytin.Start(); 102 103 nopeutusAjastin = new Timer(); 104 nopeutusAjastin.Interval = 5; 105 nopeutusAjastin.Trigger += NopeutaPelia; 106 Add(nopeutusAjastin); 107 nopeutusAjastin.Start(); 108 109 aikaaPainaaUuttaNappia = new Timer(); 110 aikaaPainaaUuttaNappia.Interval = 3; 111 aikaaPainaaUuttaNappia.Trigger += PeliPaattyy; 112 Add(aikaaPainaaUuttaNappia); 113 aikaaPainaaUuttaNappia.Start(); 62 114 } 63 115 64 void SytytaPainike(Timer t)116 void NopeutaPelia(Timer t) 65 117 { 66 int sytytettavanIndeksi = RandomGen.NextInt(0, painikkeet.Count-1); 67 Color alkuperainenVari = painikkeet[sytytettavanIndeksi].Color; 68 List<double> varit = new List<double>(); 69 double r = alkuperainenVari.RedComponent; 70 double g = alkuperainenVari.GreenComponent; 71 double b = alkuperainenVari.BlueComponent; 72 r *= 4; varit.Add(r); 73 g *= 4; varit.Add(g); 74 b *= 4; varit.Add(b); 75 for (int i = 0; i < varit.Count; i++) 76 { 77 if (varit[i] >= 255) 78 { 79 varit[i] = 255; 80 } 81 } 82 83 r = (byte)varit[0]; g = (byte)varit[1]; b = (byte)varit[2]; 84 85 MessageDisplay.Add( 86 alkuperainenVari.RedComponent.ToString() + " " + 87 alkuperainenVari.GreenComponent.ToString() + " " + 88 alkuperainenVari.BlueComponent.ToString() + " -> " + 89 r.ToString() + " " + 90 g.ToString() + " " + 91 b.ToString()); 92 painikkeet[sytytettavanIndeksi].Color = new Color((byte)r, (byte)g, (byte)b); 93 94 Timer.SingleShot(t.Interval / 1.2, delegate() { Sammuta(alkuperainenVari, sytytettavanIndeksi); }); 118 painikkeidenSytytin.Interval /= 1.2; 95 119 } 96 120 97 void S ammuta(Color vari, int i)121 void SytytaJokinPainike(Timer t) 98 122 { 99 painikkeet[i].Color = vari; 123 int sytytettavanIndeksi = RandomGen.NextInt(0, painikkeet.Count - 1); 124 Color alkuperainenVari = painikkeet[sytytettavanIndeksi].Color; 125 Sytyta(painikkeet[sytytettavanIndeksi], sytytettavanIndeksi); 126 painamattomat.Add(painikkeet[sytytettavanIndeksi]); 127 Timer.SingleShot(t.Interval / 1.4, delegate() { Sammuta(sytytettavanIndeksi); }); 100 128 } 101 129 130 void Sytyta(GameObject sytytettava, int indeksi) 131 { 132 Color alkuperainenVari = sytytettava.Color; 133 double r = alkuperainenVari.RedComponent + 164; 134 double g = alkuperainenVari.GreenComponent + 164; 135 double b = alkuperainenVari.BlueComponent + 164; 136 if (r >= 255) r = 255; 137 if (g >= 255) g = 255; 138 if (b >= 255) b = 255; 139 sytytettava.Image = LoadImage(indeksi.ToString()); 140 } 141 142 void Sammuta(int i) 143 { 144 painikkeet[i].Image = LoadImage(i.ToString() + "_"); 145 } 146 147 102 148 }
Note: See TracChangeset
for help on using the changeset viewer.