- Timestamp:
- 2016-06-28 14:59:24 (7 years ago)
- Location:
- 2016/26/PinjaV/Pong/Pong/Pong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/26/PinjaV/Pong/Pong/Pong/Pong.cs
r7545 r7557 14 14 PhysicsObject maila1; 15 15 PhysicsObject maila2; 16 PhysicsObject vasenReuna; 17 PhysicsObject oikeaReuna; 18 IntMeter pelaajan1Pisteet; 19 IntMeter pelaajan2Pisteet; 16 20 public override void Begin() 17 21 { … … 32 36 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 33 37 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 Level.CreateBorders(1.0, false); 35 Level.Background.Color = Color.Red; 38 39 vasenReuna = Level.CreateLeftBorder(); 40 vasenReuna.Restitution = 1.0; 41 vasenReuna.IsVisible = false; 42 43 oikeaReuna = Level.CreateRightBorder(); 44 oikeaReuna.Restitution = 1.0; 45 oikeaReuna.IsVisible = false; 46 47 PhysicsObject yläReuna = Level.CreateBottomBorder(); 48 yläReuna.Restitution = 1.0; 49 yläReuna.IsVisible = false; 50 51 PhysicsObject alaReuna = Level.CreateTopBorder(); 52 alaReuna.Restitution = 1.0; 53 alaReuna.IsVisible = false; 54 55 Level.Background.Color = Color.Purple; 36 56 Camera.ZoomToLevel(); 57 AddCollisionHandler(pallo, KasittelePallonTormays); 37 58 } 38 59 void AloitaPeli() … … 68 89 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 69 90 { 70 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom 91 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 71 92 { 72 93 maila.Velocity = Vector.Zero; … … 74 95 75 96 } 76 if (( nopeus.Y > 0) && (maila.Top > Level.Top)) 97 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 98 { 99 maila.Velocity = Vector.Zero; 100 return; 101 } 77 102 maila.Velocity = nopeus; 78 103 } 79 104 void LisaaLaskurit() 80 { 81 // ... 105 { 106 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 107 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 82 108 } 83 } 109 IntMeter LuoPisteLaskuri(double x, double y) 110 { 111 IntMeter laskuri = new IntMeter(0); 112 laskuri.MaxValue = 10; 113 Label naytto = new Label(); 114 naytto.BindTo(laskuri); 115 naytto.X = x; 116 naytto.Y = y; 117 naytto.TextColor = Color.White; 118 naytto.BorderColor = Level.Background.Color; 119 Add(naytto); 120 return laskuri; 121 } 122 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 123 { 124 if (kohde == oikeaReuna) 125 { 126 pelaajan1Pisteet.Value += 1; 127 } 128 else if (kohde == vasenReuna) 129 { 130 pelaajan2Pisteet.Value += 1; 131 } 132 } 133 }
Note: See TracChangeset
for help on using the changeset viewer.