Changeset 4220
- Timestamp:
- 2013-06-25 14:54:30 (10 years ago)
- Location:
- 2013/26/AleksiP
- Files:
-
- 19 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/26/AleksiP/pingpong/pingpong/pingpong/pingpong.cs
r4198 r4220 13 13 14 14 PhysicsObject pallo; 15 PhysicsObject maila1; 16 PhysicsObject maila2; 15 17 16 PhysicsObject maila1; 17 PhysicsObject maila2; 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 18 23 19 24 public override void Begin() … … 22 27 AloitaPeli(); 23 28 AsetaOhjaimet(); 29 LisaaLaskurit(); 24 30 25 31 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 26 32 27 33 28 34 } … … 31 37 pallo = new PhysicsObject(50.0, 50.0); 32 38 Add(pallo); 39 AddCollisionHandler(pallo, KasittelePallonTormays); 33 40 pallo.Shape = Shape.Circle; 34 41 pallo.Color = Color.LightGreen; … … 36 43 pallo.X = 40.0; 37 44 38 maila1 = LuoMaila(Level.Left + 20.0, 0.0);39 maila2 = LuoMaila(Level.Right - 20.0, 0.0);45 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 46 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 40 47 41 Level.CreateBorders(1.0, false); 48 vasenReuna = Level.CreateLeftBorder(); 49 vasenReuna.Restitution = 1.0; 50 vasenReuna.KineticFriction = 0.0; 51 vasenReuna.IsVisible = false; 52 53 oikeaReuna = Level.CreateRightBorder(); 54 oikeaReuna.Restitution = 1.0; 55 oikeaReuna.KineticFriction = 0.0; 56 oikeaReuna.IsVisible = false; 57 58 PhysicsObject alaReuna = Level.CreateBottomBorder(); 59 alaReuna.Restitution = 1.0; 60 alaReuna.KineticFriction = 0.0; 61 alaReuna.IsVisible = false; 62 63 PhysicsObject ylaReuna = Level.CreateTopBorder(); 64 ylaReuna.Restitution = 1.0; 65 ylaReuna.KineticFriction = 0.0; 66 ylaReuna.IsVisible = false; 67 42 68 pallo.Restitution = (1.7); 43 69 Level.BackgroundColor = Color.Black; 44 70 Camera.ZoomToLevel(); 45 }71 } 46 72 void AloitaPeli() 47 73 { 48 Vector impulssi = new Vector( 500.0, 0.0);74 Vector impulssi = new Vector(1000.0, 0.0); 49 75 pallo.Hit(impulssi); 50 76 } 51 PhysicsObject LuoMaila(double x, double y)77 PhysicsObject LuoMaila(double x, double y) 52 78 { 53 79 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 61 87 } 62 88 89 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 90 { 91 92 if (kohde == oikeaReuna) 93 { 94 pelaajan1Pisteet.Value += 1; 95 } 96 else if (kohde == vasenReuna) 97 { 98 pelaajan2Pisteet.Value += 999999; 99 } 100 101 102 } 63 103 void AsetaOhjaimet() 64 104 { … … 79 119 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 80 120 { 121 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 122 { 123 maila.Velocity = Vector.Zero; 124 return; 125 } 126 127 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 128 { 129 maila.Velocity = Vector.Zero; 130 return; 131 } 81 132 maila.Velocity = nopeus; 82 133 } 134 135 void LisaaLaskurit() 136 { 137 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 138 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 139 } 140 141 IntMeter LuoPisteLaskuri(double x, double y) 142 { 143 IntMeter laskuri = new IntMeter(0); 144 laskuri.MaxValue = 10000000; 145 Label naytto = new Label(); 146 naytto.BindTo(laskuri); 147 naytto.X = x; 148 naytto.Y = y; 149 naytto.TextColor = Color.Red; 150 naytto.BorderColor = Level.BackgroundColor; 151 naytto.Color = Level.BackgroundColor; 152 Add(naytto); 153 154 return laskuri; 155 } 83 156 } 84
Note: See TracChangeset
for help on using the changeset viewer.