Changeset 608 for 2010/23/kajysail/Ping Pong/Peli.cs
- Timestamp:
- 2010-06-09 11:59:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/kajysail/Ping Pong/Peli.cs
r562 r608 8 8 public class Peli : PhysicsGame 9 9 { 10 PhysicsObject pallo; 11 PhysicsObject pelihahmo; 10 12 11 13 protected override void Begin() 12 14 { 13 PhysicsObject pallo = new PhysicsObject(100.0, 100.0); 15 LuoPallo(); 16 LuoPeliHahmo(); 17 AsetaOhjaimet(); 18 AloitaPeli(); 19 20 Level.CreateBorders( 1.05, false ); 21 AddCollisionHandler(pallo, KasittelePallonOsuma); 22 } 23 24 void AloitaPeli() 25 { 26 Vector impulssi = new Vector(500.0, 0.0); 27 pallo.Hit(impulssi); 28 } 29 30 void LuoPeliHahmo() 31 { 32 pelihahmo = PhysicsObject.CreateStaticObject(50.0, 50.0); 33 pelihahmo.Shape = Shapes.Rectangle; 34 Add (pelihahmo); 35 36 } 37 38 void LuoPallo() 39 { 40 pallo = new PhysicsObject(100.0, 100.0); 14 41 pallo.Shape = Shapes.Circle; 15 42 pallo.X = 200; 16 43 pallo.Y = 300; 17 44 pallo.Restitution = 1.05; 18 19 Add ( pallo ); 45 pallo.Image = LoadImage("piikkipallo2"); 20 46 21 Vector impulssi = new Vector(500.0, 0.0);22 pallo.Hit(impulssi);47 Add(pallo); 48 } 23 49 24 Level.CreateBorders( 1.05, false ); 50 void AsetaOhjaimet() 51 { 52 Keyboard.Listen( Key.Up, ButtonState.Down, LiikutaPelihahmoYlos, "Pelaaja 2: Liikuta pelihahmoa ylös", pelihahmo); 53 Keyboard.Listen( Key.Up, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo ); 54 Keyboard.Listen( Key.Down, ButtonState.Down, LiikutaPelihahmoAlas, "Pelaaja 1: Liikuta pelihahmoa alas", pelihahmo ); 55 Keyboard.Listen( Key.Down, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo ); 56 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelihahmoOikea, "Pelaaja 1: Liikuta pelihahmoa oikealle", pelihahmo); 57 Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); 58 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelihahmoVasen, "Pelaaja 1: Liikuta pelihahmoa vasemmalle", pelihahmo); 59 Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); 60 61 Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet" ); 62 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu" ); 63 } 64 65 void LiikutaPelihahmoYlos( PhysicsObject pelihahmo ) 66 { 67 Vector nopeus = new Vector( 0, 500 ); 68 pelihahmo.Velocity = nopeus; 69 } 70 71 void LiikutaPelihahmoAlas(PhysicsObject pelihahmo) 72 { 73 Vector nopeus = new Vector( 0, -500 ); 74 pelihahmo.Velocity = nopeus; 75 } 76 77 void LiikutaPelihahmoVasen(PhysicsObject pelihahmo) 78 { 79 Vector nopeus = new Vector(-500, 0); 80 pelihahmo.Velocity = nopeus; 81 } 82 83 void LiikutaPelihahmoOikea(PhysicsObject pelihahmo) 84 { 85 Vector nopeus = new Vector(500, 0); 86 pelihahmo.Velocity = nopeus; 87 } 88 89 void PysaytaPelihahmo(PhysicsObject pelihahmo) 90 { 91 pelihahmo.Velocity = Vector.Zero; 92 } 93 94 void KasittelePallonOsuma(PhysicsObject pallo, PhysicsObject kohde) 95 { 96 if (kohde == pelihahmo) 97 { 98 Kuolema(); 99 } 100 } 101 102 void Kuolema() 103 { 25 104 } 26 105 }
Note: See TracChangeset
for help on using the changeset viewer.