Changeset 8915 for 2017/27/MillaK/Pong/Pong/Pong
- Timestamp:
- 2017-07-05 11:59:10 (2 years ago)
- Location:
- 2017/27/MillaK/Pong/Pong/Pong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/MillaK/Pong/Pong/Pong/Pong.cs
r8821 r8915 14 14 PhysicsObject maila1; 15 15 PhysicsObject maila2; 16 PhysicsObject OikeaReuna; 17 PhysicsObject VasenReuna; 18 IntMeter Pelaajan1pisteet; 19 IntMeter Pelaajan2pisteet; 16 20 public override void Begin() 17 21 { … … 20 24 maila2 = LuoMaila(Level.Right - 20.0,0.0); 21 25 AsetaOhjaimet(); 26 LisaaLaskurit(); 22 27 AloitaPeli(); 23 28 … … 30 35 pallo.Y = -50; 31 36 pallo.Restitution = 1.0; 37 pallo.KineticFriction = 1.0; 38 pallo.CanRotate = false; 32 39 pallo.Shape = Shape.Circle; 33 40 pallo.Color = Color.Emerald; 34 41 Add(pallo); 35 42 36 43 AddCollisionHandler(pallo, KasittelePallonTormays); 37 44 38 Level.CreateBorders(1.0, false); 45 VasenReuna = Level.CreateLeftBorder(); 46 VasenReuna.Restitution = 1.0; 47 VasenReuna.IsVisible = false; 48 OikeaReuna = Level.CreateRightBorder(); 49 OikeaReuna.Restitution = 1.0; 50 OikeaReuna.IsVisible = false; 51 PhysicsObject AlaReuna = Level.CreateBottomBorder(); 52 AlaReuna.Restitution = 1.0; 53 AlaReuna.IsVisible = false; 54 PhysicsObject YlaReuna = Level.CreateTopBorder(); 55 YlaReuna.Restitution = 1.0; 56 YlaReuna.IsVisible = false; 57 39 58 Level.Background.Color = Color.DarkYellowGreen; 40 59 … … 75 94 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 76 95 { 77 if (maila.top) 96 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 97 { 98 maila.Velocity = Vector.Zero; 99 return; 100 } 101 102 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 103 { 104 maila.Velocity = Vector.Zero; 105 return; 106 } 78 107 maila.Velocity = nopeus; 79 108 } 109 void LisaaLaskurit() 110 { 111 Pelaajan1pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 112 Pelaajan2pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100); 113 } 114 IntMeter LuoPisteLaskuri(double x, double y) 115 { 116 IntMeter laskuri = new IntMeter(0); 117 118 Label naytto = new Label(); 119 naytto.BindTo(laskuri); 120 naytto.X = x; 121 naytto.Y = y; 122 naytto.TextColor = Color.White; 123 naytto.BorderColor = Level.Background.Color; 124 naytto.Color = Level.Background.Color; 125 Add(naytto); 126 127 return laskuri; 128 } 129 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 130 { 131 132 if (kohde == OikeaReuna) 133 { 134 Pelaajan1pisteet.Value += 1; 135 136 } 137 else if (kohde == VasenReuna) 138 { 139 Pelaajan2pisteet.Value += 1; 140 } 141 } 142 const double PALLON_MIN_NOPEUS = 500; 143 144 protected override void Update(Time time) 145 { 146 if (pallo != null && Math.Abs(pallo.Velocity.X) < PALLON_MIN_NOPEUS) 147 { 148 pallo.Velocity = new Vector(pallo.Velocity.X * 1.1, pallo.Velocity.Y); 149 } 150 base.Update(time); 151 } 80 152 }
Note: See TracChangeset
for help on using the changeset viewer.