Changeset 1196
- Timestamp:
- 2010-07-08 14:57:18 (13 years ago)
- Location:
- 2010/27/jomiilri/Duel
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/27/jomiilri/Duel/Content/Content.contentproj
r1154 r1196 67 67 </Compile> 68 68 </ItemGroup> 69 <ItemGroup> 70 <Compile Include="ammuslaatikko1.png"> 71 <Name>ammuslaatikko1</Name> 72 <Importer>TextureImporter</Importer> 73 <Processor>TextureProcessor</Processor> 74 </Compile> 75 </ItemGroup> 69 76 </Project> -
2010/27/jomiilri/Duel/Peli.cs
r1154 r1196 9 9 PhysicsObject p2; 10 10 11 Timer ammusAjastin; 12 13 IntMeter elamaLaskuri1; 14 IntMeter elamaLaskuri2; 15 16 AssaultRifle konekivaari1; 17 AssaultRifle konekivaari2; 18 11 19 double tyontovoima = 400; 12 20 const int ruudunLeveys = 32; … … 15 23 protected override void Begin() 16 24 { 25 konekivaari1 = new AssaultRifle(20, 5); 26 konekivaari2 = new AssaultRifle(20, 5); 27 konekivaari1.Ammo.Value = 100; 28 konekivaari2.Ammo.Value = 100; 29 konekivaari1.Ammo.MaxValue = 250; 30 konekivaari2.Ammo.MaxValue = 250; 31 konekivaari1.BulletCollision = LuotiOsuu; 32 konekivaari2.BulletCollision = LuotiOsuu; 33 34 17 35 LuoKentta(); 36 LuoElamaLaskuri1(); 37 LuoElamaLaskuri2(); 38 LuoAmmusLaskuri1(); 39 LuoAmmusLaskuri2(); 40 41 18 42 AloitaPeli(); 43 19 44 IsFullScreen = true; 45 20 46 p1 = LuoHahmo1(); 21 47 p1.LinearDamping = 0.95; 48 p1.Restitution = 0.05; 49 p1.X = Screen.Left + 975; 50 p1.Y = Screen.Top - 760; 22 51 Add(p1); 23 52 24 53 p2 = LuoHahmo2(); 25 54 p2.LinearDamping = 0.95; 55 p2.Restitution = 0.05; 56 p2.X = Screen.Left + 305; 57 p2.Y = Screen.Top - 260; 26 58 Add(p2); 59 27 60 LuoOhjaimet(); 28 61 } … … 40 73 Camera.ZoomToLevel(); 41 74 } 42 75 43 76 void LuoKentta() 44 77 { 45 78 TileMap ruudut = TileMap.FromFile("TextFile1.txt"); 46 79 ruudut['I'] = LuoSeina; 80 ruudut['*'] = LuoAmmusLaatikko; 47 81 ruudut.Insert(ruudunLeveys, ruudunKorkeus); 48 82 } … … 59 93 PhysicsObject LuoHahmo1() 60 94 { 61 PhysicsObject ukko = new PhysicsObject 95 PhysicsObject ukko = new PhysicsObject(32, 32); 62 96 ukko.Image = LoadImage("pelaaja1"); 97 ukko.Add(konekivaari1); 98 ukko.Tag = "p1"; 99 63 100 return ukko; 64 101 } … … 68 105 PhysicsObject ukko = new PhysicsObject(32, 32); 69 106 ukko.Image = LoadImage("pelaaja2"); 107 ukko.Add(konekivaari2); 108 ukko.Tag = "p2"; 109 70 110 return ukko; 71 111 } … … 90 130 Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelaaja, null, p1); 91 131 Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaaTaakse, null, p1); 132 Keyboard.Listen(Key.RightControl, ButtonState.Down, Ammu, "Ammu", p1, konekivaari1); 133 134 ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, KaannaPelaajaa, null, 3, p1); 135 ControllerOne.Listen(Button.DPadRight, ButtonState.Down, KaannaPelaajaa, null, -3, p1); 136 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, LiikutaPelaajaa, null, p1); 137 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, PysaytaPelaaja, null, p1); 138 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, LiikutaPelaajaaTaakse, null, p1); 139 ControllerOne.Listen(Button.A, ButtonState.Down, Ammu, "Ammu", p1, konekivaari1); 92 140 93 141 Keyboard.Listen(Key.A, ButtonState.Down, KaannaPelaajaa, null, 3, p2); … … 96 144 Keyboard.Listen(Key.W, ButtonState.Released, PysaytaPelaaja, null, p2); 97 145 Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaajaaTaakse, null, p2); 146 Keyboard.Listen(Key.F, ButtonState.Down, Ammu, "Ammu", p2, konekivaari2); 147 148 ControllerTwo.Listen(Button.DPadLeft, ButtonState.Down, KaannaPelaajaa, null, 3, p2); 149 ControllerTwo.Listen(Button.DPadRight, ButtonState.Down, KaannaPelaajaa, null, -3, p2); 150 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, LiikutaPelaajaa, null, p2); 151 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, PysaytaPelaaja, null, p2); 152 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, LiikutaPelaajaaTaakse, null, p2); 153 ControllerTwo.Listen(Button.A, ButtonState.Down, Ammu, "Ammu", p2, konekivaari2); 154 } 155 156 void Ammu(PhysicsObject ampuja, Weapon ase) 157 { 158 PhysicsObject ammus = ase.Shoot(); 159 if (ammus != null) ammus.Tag = ampuja; 98 160 } 99 161 … … 108 170 } 109 171 172 void LuotiOsuu(PhysicsObject luoti, PhysicsObject seina) 173 { 174 if (luoti.Tag != seina) 175 { 176 if (seina.Tag.ToString() == "p2") 177 { 178 elamaLaskuri1.Value = elamaLaskuri1.Value - 4; 179 } 180 if (seina.Tag.ToString() == "p1") 181 { 182 elamaLaskuri2.Value = elamaLaskuri2.Value - 4; 183 } 184 luoti.Destroy(); 185 } 186 187 } 188 189 void LuoElamaLaskuri1() 190 { 191 elamaLaskuri1 = new IntMeter(100); 192 193 Label elamaNaytto1 = new Label(); 194 elamaNaytto1.X = Screen.Left + 100; 195 elamaNaytto1.Y = Screen.Top - 980; 196 elamaNaytto1.TextColor = Color.Red; 197 198 elamaNaytto1.BindTo(elamaLaskuri1); 199 Add(elamaNaytto1); 200 } 201 202 void LuoElamaLaskuri2() 203 { 204 elamaLaskuri2 = new IntMeter(100); 205 206 Label elamaNaytto2 = new Label(); 207 elamaNaytto2.X = Screen.Right - 100; 208 elamaNaytto2.Y = Screen.Top - 980; 209 elamaNaytto2.TextColor = Color.Red; 210 211 elamaNaytto2.BindTo(elamaLaskuri2); 212 Add(elamaNaytto2); 213 } 214 215 void LuoAmmusLaskuri1() 216 { 217 Label ammusNaytto1 = new Label(); 218 ammusNaytto1.X = Screen.Left + 200; 219 ammusNaytto1.Y = Screen.Top - 980; 220 ammusNaytto1.TextColor = Color.Black; 221 222 ammusNaytto1.BindTo(konekivaari2.Ammo); 223 Add(ammusNaytto1); 224 } 225 226 void LuoAmmusLaskuri2() 227 { 228 Label ammusNaytto2 = new Label(); 229 ammusNaytto2.X = Screen.Right - 200; 230 ammusNaytto2.Y = Screen.Top - 980; 231 ammusNaytto2.TextColor = Color.Black; 232 233 ammusNaytto2.BindTo(konekivaari1.Ammo); 234 Add(ammusNaytto2); 235 } 236 237 PhysicsObject LuoAmmusLaatikko() 238 { 239 PhysicsObject ammusLaatikko = new PhysicsObject(18, 12); 240 ammusLaatikko.Image = LoadImage("ammuslaatikko1"); 241 Add(ammusLaatikko); 242 AddCollisionHandler(ammusLaatikko, LisaaAmmuksia); 243 return ammusLaatikko; 244 } 245 246 void LisaaAmmuksia(PhysicsObject ammusLaatikko, PhysicsObject pelaaja) 247 { 248 if (konekivaari1.Ammo.Value == 250) return; 249 else 250 { 251 konekivaari1.Ammo.Value += 50; 252 ammusLaatikko.Destroy(); 253 } 254 255 } 256 257 void LuoAmmusLaatikkoAjastint() 258 { 259 ammusAjastin = new Timer(); 260 ammusAjastin.Interval = 40; 261 ammusAjastin.Trigger += LisaaAmmusLaatikoita; 262 Add(ammusAjastin); 263 ammusAjastin.Start(); 264 265 } 266 267 void LisaaAmmusLaatikoita(Timer sender) 268 { 269 PhysicsObject laatikko = LuoAmmusLaatikko(); 270 laatikko.X = RandomGen.NextDouble(Screen.Left + 100, Screen.Left - 900); 271 laatikko.Y = RandomGen.NextDouble(Screen.Top + 100, Screen.Top - 900); 272 } 110 273 } -
2010/27/jomiilri/Duel/TextFile1.txt
r1131 r1196 1 1 IIIIIIIIIIIIIIIIIIIIIIIIIIII 2 2 IIIIIIIIIIIIIIIIIIIIIIIIIIII 3 II R I II 4 II I II 3 5 II II 4 6 II II … … 15 17 II II 16 18 II II 17 II II 18 II II 19 II II 20 II II 19 II I II 20 II ** I P II 21 21 IIIIIIIIIIIIIIIIIIIIIIIIIIII 22 22 IIIIIIIIIIIIIIIIIIIIIIIIIIII
Note: See TracChangeset
for help on using the changeset viewer.