- Timestamp:
- 2010-06-10 11:42:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/kajysail/Ping Pong/Peli.cs
r629 r662 10 10 PhysicsObject pallo; 11 11 PhysicsObject pelihahmo; 12 Timer ajastin; 13 12 14 13 protected override void Begin() 15 protected override void Begin() 14 16 { 15 17 16 18 Alku(); 17 19 Level.CreateBorders(1.05, true); 20 21 ajastin = new Timer(); 22 ajastin.Interval = 20; 23 ajastin.Trigger += Ajastinapu; 24 25 Add(ajastin); 26 ajastin.Reset(); 27 ajastin.Start(); 18 28 } 19 29 void Alku() 20 { 30 { 21 31 LuoPallo(); 22 32 LuoPeliHahmo(); 23 33 AsetaOhjaimet(); 24 AloitaPeli();25 34 35 26 36 AddCollisionHandler(pelihahmo, KasitteleOsumama); 27 28 29 37 } 30 38 31 void A loitaPeli()39 void Ajastinapu(Timer sender) 32 40 { 33 Vector impulssi = new Vector(500.0, 0.0); 34 pallo.Hit(impulssi); 41 LuoPallo(); 35 42 } 36 43 … … 39 46 pelihahmo = new PhysicsObject(50.0, 50.0); 40 47 pelihahmo.Shape = Shapes.Rectangle; 41 Add 48 Add(pelihahmo); 42 49 43 50 } … … 47 54 pallo = new PhysicsObject(100.0, 100.0); 48 55 pallo.Shape = Shapes.Circle; 49 pallo.X = 200;50 pallo.Y = 300;51 pallo.Restitution = 1.0 5;56 pallo.X = -300; 57 pallo.Y = 200; 58 pallo.Restitution = 1.01; 52 59 pallo.Image = LoadImage("piikkipallo2"); 53 60 54 61 Add(pallo); 62 63 64 Vector impulssi = new Vector(500.0, 0.0); 65 pallo.Hit(impulssi); 55 66 } 56 67 57 68 void AsetaOhjaimet() 58 69 { 59 Keyboard.Listen( 60 Keyboard.Listen( Key.Up, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo);61 Keyboard.Listen( Key.Down, ButtonState.Down, LiikutaPelihahmoAlas, "Pelaaja 1: Liikuta pelihahmoa alas", pelihahmo);62 Keyboard.Listen( Key.Down, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo);70 Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelihahmoYlos, "Pelaaja 2: Liikuta pelihahmoa ylös", pelihahmo); 71 Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); 72 Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelihahmoAlas, "Pelaaja 1: Liikuta pelihahmoa alas", pelihahmo); 73 Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); 63 74 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelihahmoOikea, "Pelaaja 1: Liikuta pelihahmoa oikealle", pelihahmo); 64 75 Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); … … 66 77 Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelihahmo, null, pelihahmo); 67 78 68 Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");69 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu");70 Keyboard.Listen( Key.U, ButtonState.Pressed, Lopeta ,"Uusi peli" );79 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 80 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 81 Keyboard.Listen(Key.U, ButtonState.Pressed, Lopeta, "Uusi peli"); 71 82 } 72 73 void LiikutaPelihahmoYlos( PhysicsObject pelihahmo)83 84 void LiikutaPelihahmoYlos(PhysicsObject pelihahmo) 74 85 { 75 Vector nopeus = new Vector( 0, 500);86 Vector nopeus = new Vector(0, 500); 76 87 pelihahmo.Velocity = nopeus; 77 88 } … … 79 90 void LiikutaPelihahmoAlas(PhysicsObject pelihahmo) 80 91 { 81 Vector nopeus = new Vector( 0, -500);92 Vector nopeus = new Vector(0, -500); 82 93 pelihahmo.Velocity = nopeus; 83 94 } … … 101 112 102 113 void KasitteleOsumama(PhysicsObject osuja, PhysicsObject osuttu) 103 { 114 { 115 if (osuja == pelihahmo) 116 { 117 MessageDisplay.Add("Hävisit! aloita uusi peli painamalla U:ta."); 118 } 104 119 Explosion rajahdys = new Explosion(100); 105 rajahdys.Position = pelihahmo.Position;120 rajahdys.Position = osuja.Position; 106 121 Add(rajahdys); 107 osuja.Destroy(); 108 MessageDisplay.Add("Hävisit! aloita uusi peli painamalla U:ta."); 122 osuja.Destroy(); 109 123 } 110 124 … … 114 128 pelihahmo.Destroy(); 115 129 116 pallo.Destroy();117 Alku();118 130 131 ClearAll(); 132 Alku(); 119 133 } 120 134 }
Note: See TracChangeset
for help on using the changeset viewer.