- Timestamp:
- 2012-06-05 09:50:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/23/HannesM/Pong/Pong/Pong/Pong.cs
r2765 r2784 14 14 PhysicsObject pallo; 15 15 16 PhysicsObject vasenReuna; 17 PhysicsObject oikeaReuna; 18 16 19 PhysicsObject maila1; 17 20 PhysicsObject maila2; 21 22 IntMeter pelaajan1Pisteet; 23 IntMeter pelaajan2Pisteet; 18 24 19 25 public override void Begin() … … 22 28 AsetaOhjaimet(); 23 29 AloitaPeli(); 30 LisaaLaskuri(); 24 31 } 25 32 … … 27 34 { 28 35 pallo = new PhysicsObject(30, 30); 29 pallo.Shape = Shape. Circle;30 pallo.Color = Color. Red;36 pallo.Shape = Shape.Hexagon; 37 pallo.Color = Color.Green; 31 38 pallo.X = -200; 32 39 pallo.Y = 0; … … 38 45 39 46 Level.BackgroundColor = Color.Black; 40 Level.CreateBorders(1.0, false); 47 48 vasenReuna = Level.CreateLeftBorder(); 49 vasenReuna.Restitution = 1.0; 50 vasenReuna.IsVisible = false; 51 oikeaReuna = Level.CreateRightBorder(); 52 oikeaReuna.Restitution = 1.0; 53 oikeaReuna.IsVisible = false; 54 PhysicsObject ylaReuna = Level.CreateTopBorder(); 55 ylaReuna.Restitution = 1.0; 56 ylaReuna.KineticFriction = 0.0; 57 ylaReuna.IsVisible = false; 58 PhysicsObject alaReuna = Level.CreateBottomBorder(); 59 alaReuna.Restitution = 1.0; 60 alaReuna.IsVisible = false; 61 alaReuna.KineticFriction = 0.0; 62 41 63 42 64 Camera.ZoomToLevel(); … … 44 66 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 45 67 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 68 69 AddCollisionHandler(pallo, PallonTormays); 70 46 71 } 47 72 void AloitaPeli() … … 53 78 { 54 79 PhysicsObject maila = PhysicsObject.CreateStaticObject(10.0, 100.0); 80 maila.Color = Color.Gold; 55 81 maila.Shape = Shape.Rectangle; 56 82 maila.X = x; … … 78 104 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 79 105 { 106 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 107 { 108 maila.Velocity = Vector.Zero; 109 return; 110 } 111 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 112 { 113 maila.Velocity = Vector.Zero; 114 return; 115 116 } 117 80 118 maila.Velocity = nopeus; 119 } 120 void LisaaLaskuri() 121 { 122 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left +100, Screen.Top - 100); 123 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100, Screen.Top - 100); 124 } 125 IntMeter LuoPisteLaskuri(double x, double y) 126 { 127 IntMeter laskuri = new IntMeter(0); 128 laskuri.MaxValue = 5; 129 Label naytto = new Label(); 130 naytto.BindTo(laskuri); 131 naytto.X = x; 132 naytto.Y = y; 133 naytto.TextColor = Color.Red; 134 naytto.BorderColor = Level.BackgroundColor; 135 naytto.Color = Level.BackgroundColor; 136 Add(naytto); 137 138 return laskuri; 139 140 } 141 void PallonTormays(PhysicsObject pallo, PhysicsObject kohde) 142 { 143 if (kohde == oikeaReuna) 144 { 145 pelaajan1Pisteet.Value += 1; 146 } 147 else if (kohde == vasenReuna) 148 { 149 pelaajan2Pisteet.Value += 1; 150 } 81 151 } 82 152
Note: See TracChangeset
for help on using the changeset viewer.