Changeset 7895 for 2016/27/KonstantinosK
- Timestamp:
- 2016-07-06 14:54:05 (5 years ago)
- Location:
- 2016/27/KonstantinosK
- Files:
-
- 110 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/27/KonstantinosK/pong/pong/pong/pong.cs
r7711 r7895 16 16 PhysicsObject maila1; 17 17 PhysicsObject maila2; 18 IntMeter pelaajan1Pisteet; 19 IntMeter pelaajan2Pisteet; 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 18 22 19 23 public override void Begin() … … 23 27 aloitapeli(); 24 28 AsetaOhjaimet(); 25 29 LisaaLaskurit(); 26 30 } 31 void LisaaLaskurit() 32 { 33 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 34 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 35 36 } 37 IntMeter LuoPisteLaskuri(double x, double y) 38 { 39 IntMeter laskuri = new IntMeter(0); 40 laskuri.MaxValue = 10; 41 Label naytto = new Label(); 42 naytto.BindTo(laskuri); 43 naytto.X = x; 44 naytto.Y = y; 45 naytto.TextColor = Color.White; 46 naytto.BorderColor = Level.Background.Color; 47 naytto.Color = Level.Background.Color; 48 Add(naytto); 49 50 51 52 return laskuri; 53 } 54 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 55 { 56 if (kohde == oikeaReuna) 57 { 58 pelaajan1Pisteet.Value += 1; 59 } 60 else if (kohde == vasenReuna) 61 { 62 pelaajan2Pisteet.Value += 1; 63 } 64 65 66 67 68 } 69 27 70 void LuoKentta() { 28 71 pallo = new PhysicsObject(40.0, 40.0); … … 33 76 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 34 77 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 35 78 AddCollisionHandler(pallo, KasittelePallonTormays); 36 79 Vector impulssi = new Vector(500.0, 0.0); 37 80 pallo.Hit(impulssi); 38 Level.CreateBorders(1.0, false); 39 pallo.Restitution = 1.0; 81 vasenReuna = Level.CreateLeftBorder(); 82 vasenReuna.Restitution = 1.0; 83 vasenReuna.IsVisible = false; 84 oikeaReuna = Level.CreateRightBorder(); 85 oikeaReuna.Restitution = 1.0; 86 oikeaReuna.IsVisible = false; 87 88 89 40 90 Level.Background.Color = Color.DarkGreen; 41 91 Camera.ZoomToLevel(); … … 68 118 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 69 119 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 120 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 70 121 } 71 122 72 123 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 73 124 { 125 126 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 127 { 128 maila.Velocity = Vector.Zero; 129 return; 130 } 131 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 132 { 133 maila.Velocity = Vector.Zero; 134 return; 135 } 136 74 137 maila.Velocity = nopeus; 75 138 }
Note: See TracChangeset
for help on using the changeset viewer.