Changeset 2937
- Timestamp:
- 2012-06-12 10:46:41 (11 years ago)
- Location:
- 2012/24/LeeviL/Pong/Pong
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/24/LeeviL/Pong/Pong/Pong/Pong.cs
r2923 r2937 13 13 14 14 PhysicsObject pallo; 15 16 15 PhysicsObject maila1; 17 16 PhysicsObject maila2; 18 17 18 PhysicsObject oikeaReuna; 19 PhysicsObject vasenReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 23 19 24 public override void Begin() 20 25 { 21 // TODO: Kirjoita ohjelmakoodisi tähän 22 LuoKentta 26 27 LuoKentta(); 23 28 AloitaPeli(); 29 LisaaLaskurit(); 24 30 AsetaOhjaimet(); 25 31 } … … 33 39 34 40 PhysicsObject LuoMaila(double X, double Y) 35 { 36 37 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);41 { 42 43 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 38 44 maila.Shape = Shape.Rectangle; 39 45 maila.X = X; … … 44 50 return maila; 45 51 } 52 53 void LisaaLaskurit() 54 { 55 pelaajan1Pisteet = LuoPistelaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 56 pelaajan2Pisteet = LuoPistelaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 57 } 58 59 IntMeter LuoPistelaskuri(double x, double y) 60 { 61 IntMeter laskuri = new IntMeter(0); 62 laskuri.MaxValue = 10; 63 Label naytto = new Label(); 64 naytto.BindTo(laskuri); 65 naytto.X = x; 66 naytto.Y = y; 67 naytto.TextColor = Color.White; 68 naytto.BorderColor = Level.BackgroundColor; 69 naytto.Color = Level.BackgroundColor; 70 Add(naytto); 71 return laskuri; 72 } 73 46 74 47 75 void AsetaOhjaimet() … … 63 91 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 64 92 { 93 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 94 { 95 maila.Velocity = Vector.Zero; 96 return; 97 } 98 99 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 100 { 101 maila.Velocity = Vector.Zero; 102 return; 103 } 104 65 105 maila.Velocity = nopeus; 66 106 } 67 107 68 void LuoKentta () 108 void KasittlePallonTormaus(PhysicsObject pallo, PhysicsObject kohde) 109 { 110 if (kohde == oikeaReuna) 111 { 112 pelaajan1Pisteet.Value += 1; 113 114 } 115 116 else if (kohde == vasenReuna) 117 { 118 pelaajan2Pisteet.Value += 1; 119 120 } 121 122 } 123 124 void LuoKentta() 69 125 { 70 126 pallo = new PhysicsObject(40.0, 40.0); … … 75 131 pallo.Restitution = 1.0; 76 132 133 AddCollisionHandler(pallo, KasittlePallonTormaus); 134 77 135 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 78 136 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 79 137 80 Level.CreateBorders(1.0, false); 138 vasenReuna = Level.CreateLeftBorder(); 139 vasenReuna.Restitution = 1.0; 140 vasenReuna.IsVisible = false; 141 oikeaReuna = Level.CreateRightBorder(); 142 oikeaReuna.Restitution = 1.0; 143 oikeaReuna.IsVisible = false; 144 PhysicsObject alaReuna = Level.CreateBottomBorder(); 145 alaReuna.Restitution = 1.0; 146 alaReuna.IsVisible = false; 147 PhysicsObject ylaReuna = Level.CreateTopBorder(); 148 ylaReuna.Restitution = 1.0; 149 ylaReuna.IsVisible = false; 81 150 Level.BackgroundColor = Color.Black; 82 151 83 152 Camera.ZoomToLevel(); 84 85 86 87 88 153 } 89 154 }
Note: See TracChangeset
for help on using the changeset viewer.