Changeset 938 for 2010/24/vehakala/Lamari10
- Timestamp:
- 2010-06-17 11:30:29 (11 years ago)
- Location:
- 2010/24/vehakala/Lamari10
- Files:
-
- 6 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/24/vehakala/Lamari10/Content/Content.contentproj
r879 r938 55 55 </Compile> 56 56 </ItemGroup> 57 <ItemGroup> 58 <Compile Include="mailamies.png"> 59 <Name>mailamies</Name> 60 <Importer>TextureImporter</Importer> 61 <Processor>TextureProcessor</Processor> 62 </Compile> 63 </ItemGroup> 64 <ItemGroup> 65 <Compile Include="suomi.png"> 66 <Name>suomi</Name> 67 <Importer>TextureImporter</Importer> 68 <Processor>TextureProcessor</Processor> 69 </Compile> 70 </ItemGroup> 71 <ItemGroup> 72 <Compile Include="mailamies1.png"> 73 <Name>mailamies1</Name> 74 <Importer>TextureImporter</Importer> 75 <Processor>TextureProcessor</Processor> 76 </Compile> 77 </ItemGroup> 78 <ItemGroup> 79 <Compile Include="maali.png"> 80 <Name>maali</Name> 81 <Importer>TextureImporter</Importer> 82 <Processor>TextureProcessor</Processor> 83 </Compile> 84 </ItemGroup> 85 <ItemGroup> 86 <Compile Include="maal1.png"> 87 <Name>maal1</Name> 88 <Importer>TextureImporter</Importer> 89 <Processor>TextureProcessor</Processor> 90 </Compile> 91 </ItemGroup> 57 92 </Project> -
2010/24/vehakala/Lamari10/Peli.cs
r879 r938 6 6 public class Peli : PhysicsGame 7 7 { 8 PhysicsObject pelaaja; 8 PhysicsObject pelaaja2; 9 PhysicsObject pelaaja1; 10 PhysicsObject kiekko; 11 bool kiekkoPelaajalla = false; 12 string kenellaKiekko; 13 PhysicsObject maali; 14 //double maxNopeus = 200; 15 16 17 9 18 10 19 protected override void Begin() 11 20 { 12 21 LuoKentta(); 13 LisaaPelaaja();14 22 AsetaOhjaimet(); 15 16 } 17 18 void LuoKentta() 23 LuoKiekko(); 24 25 } 26 27 void LuoKentta() 19 28 { 20 29 Level.Width = 1024; 21 30 Level.Height = 768; 22 Level.CreateBorders( 1.0, false); // Laitetaan kentälle näkyvät reunat31 Level.CreateBorders(0.1, false); // Laitetaan kentälle näkyvät reunat 23 32 Level.Background.Image = LoadImage("lamaritausta"); 24 Level.Background.Size = new Vector(Level.Width, 513.0 /828.0*Level.Width);33 Level.Background.Size = new Vector(Level.Width, 513.0 / 828.0 * Level.Width); 25 34 Level.BackgroundColor = Color.White; 26 35 Camera.ZoomToLevel(0.0); 27 } 28 29 void LisaaPelaaja() 30 { 31 pelaaja = new PhysicsObject(30.0, 30.0); 32 pelaaja.Image = LoadImage("pelaajapunainen1"); 36 37 pelaaja2 = LisaaPelaaja("pelaaja2", "mailamies1", -100, 0.0); 38 pelaaja1 = LisaaPelaaja("pelaaja1", "suomi", 100.0, 0.0); 39 LuoMaali(440.0, 0); 40 41 } 42 43 PhysicsObject LisaaPelaaja(string tag, string kuva, double x, double y) 44 { 45 PhysicsObject pelaaja = new PhysicsObject(30.0, 30.0); 46 pelaaja.Image = LoadImage(kuva); 47 pelaaja.Tag = tag; 48 pelaaja.X = x; 49 pelaaja.Y = y; 33 50 Add(pelaaja); 34 } 35 36 37 void AsetaOhjaimet() 38 { 39 Keyboard.Listen(Key.Right, ButtonState.Down, Kaanny, "Käännä pelaajaa", Angle.Degrees(-2)); 40 Keyboard.Listen(Key.Left, ButtonState.Down, Kaanny, "Käännä pelaajaa", Angle.Degrees(2)); 41 Keyboard.Listen(Key.Up, ButtonState.Down, Eteenpain, "Luistele eteenpain"); 42 Keyboard.Listen(Key.Down, ButtonState.Pressed, Pysayta, "ukko pysahtyy"); 43 Keyboard.Listen(Key.Escape, ButtonState.Pressed, lopeta, "peli sammuu"); 44 } 45 46 void Kaanny(Angle kulma) 51 pelaaja.Restitution = 0.1; 52 pelaaja.AngularDamping = 0.95; 53 AddCollisionHandler(pelaaja, PelaajaTormasi); 54 return pelaaja; 55 } 56 57 58 void AsetaOhjaimet() 59 { 60 //Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, pelaaja2, new Vector(-50, 0)); 61 //Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, pelaaja2, new Vector(50, 0)); 62 //Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, pelaaja2, new Vector(0, 50)); 63 //Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, pelaaja2, new Vector(0, -50)); 64 Keyboard.Listen(Key.Left, ButtonState.Down, Kaanna, null, pelaaja2, Angle.Degrees(5)); 65 Keyboard.Listen(Key.Right, ButtonState.Down, Kaanna, null, pelaaja2, Angle.Degrees(-5)); 66 Keyboard.Listen(Key.Up, ButtonState.Down, Kiihdyta, null, pelaaja2, 5.0); 67 Keyboard.Listen(Key.Down, ButtonState.Down, Kiihdyta, null, pelaaja2, -5.0); 68 Keyboard.Listen(Key.RightShift, ButtonState.Pressed, LopetaSpinnaus, "Lopeta spinnaus", pelaaja2); 69 70 //Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelaajaa, null, pelaaja2, new Vector(-10, 0)); 71 //Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelaajaa, null, pelaaja2, new Vector(10, 0)); 72 //Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelaajaa, null, pelaaja2, new Vector(0, 10)); 73 //Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaPelaajaa, null, pelaaja2, new Vector(0, -10)); 74 75 Keyboard.Listen(Key.Space, ButtonState.Pressed, Laukaise, "laukaise kiekko", pelaaja2); 76 77 Keyboard.Listen(Key.A, ButtonState.Down, Kaanna, null, pelaaja1, Angle.Degrees(5)); 78 Keyboard.Listen(Key.D, ButtonState.Down, Kaanna, null, pelaaja1, Angle.Degrees(-5)); 79 Keyboard.Listen(Key.S, ButtonState.Down, Kiihdyta, null, pelaaja1, 5.0); 80 Keyboard.Listen(Key.W, ButtonState.Down, Kiihdyta, null, pelaaja1, -5.0); 81 82 //Keyboard.Listen(Key.A, ButtonState.Released, PysaytaPelaajaa, null, pelaaja1, new Vector(-10, 0)); 83 //Keyboard.Listen(Key.D, ButtonState.Released, PysaytaPelaajaa, null, pelaaja1, new Vector(10, 0)); 84 //Keyboard.Listen(Key.W, ButtonState.Released, PysaytaPelaajaa, null, pelaaja1, new Vector(0, 10)); 85 //Keyboard.Listen(Key.S, ButtonState.Released, PysaytaPelaajaa, null, pelaaja1, new Vector(0, -10)); 86 Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, LopetaSpinnaus, "Lopeta spinnaus", pelaaja1); 87 Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Laukaise, "laukaise kiekko", pelaaja1); 88 89 90 91 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 92 93 } 94 95 void LopetaSpinnaus(PhysicsObject pelaaja) 96 { 97 pelaaja.Velocity = Vector.Zero; 98 pelaaja.Angle = Angle.Degrees(0); 99 } 100 101 void Kiihdyta(PhysicsObject pelaaja, double length) 102 { 103 //if (pelaaja.Velocity.Magnitude < maxNopeus) 104 //{ 105 pelaaja.Velocity += Vector.FromLengthAndAngle(length, pelaaja.Angle); 106 //} 107 } 108 109 void Kaanna(PhysicsObject pelaaja, Angle kulma) 47 110 { 48 111 pelaaja.Angle += kulma; 49 112 } 50 void Eteenpain() 51 { 52 53 54 pelaaja.Push(Vector.FromLengthAndAngle(50.0, pelaaja.Angle)); 55 56 } 57 void Pysayta() 58 { 59 pelaaja.Velocity = Vector.Zero; 60 } 61 void lopeta() 62 63 { 64 Exit(); 65 } 66 67 113 114 void Laukaise(PhysicsObject pelaaja) 115 { 116 if (kiekkoPelaajalla && pelaaja.Tag.ToString() == kenellaKiekko) 117 { 118 kiekko.Hit(new Vector(500, 0)); 119 kiekkoPelaajalla = false; 120 } 121 } 122 123 void LiikutaPelaajaa(PhysicsObject pelaaja, Vector vektori) 124 { 125 pelaaja.Push(vektori); 126 } 127 128 void PysaytaPelaajaa(PhysicsObject pelaaja, Vector vektori) 129 { 130 pelaaja.Stop(); 131 } 132 void LuoKiekko() 133 { 134 kiekko = new PhysicsObject(10.0, 10.0, Shapes.Circle); 135 kiekko.Color = Color.Black; 136 kiekko.Tag = "kiekko"; 137 kiekko.Restitution = 0.6; 138 Add(kiekko); 139 AddCollisionHandler(kiekko, KasittelekiekonTormays); 140 } 141 142 143 void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 144 { 145 146 if (kohde.Tag.ToString() == "kiekko") 147 { 148 //MessageDisplay.Add("Osuttiin kiekkoon"); 149 kiekkoPelaajalla = true; 150 kenellaKiekko = tormaaja.Tag.ToString(); 151 } 152 153 if (kohde.Tag.ToString() == "pelaaja1") 154 { 155 kenellaKiekko = tormaaja.Tag.ToString(); 156 } 157 158 if (kohde.Tag.ToString() == "pelaaja2") 159 { 160 kenellaKiekko = tormaaja.Tag.ToString(); 161 } 162 163 } 164 165 protected override void Update(Time time) 166 { 167 if (kiekkoPelaajalla && kenellaKiekko == "pelaaja1") 168 { 169 kiekko.Position = pelaaja1.Position; 170 } 171 else if (kiekkoPelaajalla && kenellaKiekko == "pelaaja2") 172 { 173 kiekko.Position = pelaaja2.Position; 174 } 175 176 base.Update(time); 177 } 178 179 PhysicsObject LuoMaali(double x, double y) 180 { 181 PhysicsObject maali = PhysicsObject.CreateStaticObject(50.0, 100.0); 182 PhysicsObject tolppa1 = PhysicsObject.CreateStaticObject(50.0, 10.0); 183 PhysicsObject tolppa2 = PhysicsObject.CreateStaticObject(50.0, 10.0); 184 PhysicsObject tolppa3 = PhysicsObject.CreateStaticObject(20.0, 100.0); 185 186 187 maali.X = x; 188 maali.Y = y; 189 190 191 maali.Image = LoadImage("maal1"); 192 193 tolppa1.Shape = Shapes.Rectangle; 194 tolppa2.Shape = Shapes.Rectangle; 195 tolppa2.Shape = Shapes.Rectangle; 196 tolppa1.X = x; 197 tolppa1.Y = maali.Top; 198 tolppa1.Color = Color.Red; 199 200 201 tolppa2.X = x; 202 tolppa2.Y = maali.Bottom; 203 tolppa2.Color = Color.Red; 204 205 tolppa3.X = maali.Right; 206 //tolppa3.Y = maali; 207 tolppa3.Color = Color.Red; 208 209 maali.IgnoresCollisionResponse = true; 210 211 Add(maali); 212 Add(tolppa1); 213 Add(tolppa2); 214 Add(tolppa3); 215 216 217 218 219 220 return maali; 221 } 222 void KasittelekiekonTormays(PhysicsObject pallo, PhysicsObject kohde) 223 { 224 //kun kiekko menee maalin, peli alkaa keskeltä. 225 pallo.Destroy(); 226 if () 227 { 228 229 } 230 } 68 231 69 232 70 233 } 234 235 236 237 238 239 240 241 242 243
Note: See TracChangeset
for help on using the changeset viewer.