- Timestamp:
- 2010-07-27 11:24:20 (13 years ago)
- Location:
- 2010/30/jojumuho
- Files:
-
- 11 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/jojumuho/Pong/Peli.cs
r1279 r1302 14 14 PhysicsObject maila2; 15 15 16 PhysicsObject vasenReuna; 17 PhysicsObject oikeaReuna; 18 19 20 IntMeter pelaajan1Pisteet; 21 IntMeter pelaajan2Pisteet; 22 23 //... 16 24 protected override void Begin() 17 25 { 18 26 LuoKentta(); 19 AloitaPeli(); 20 AsetaOhjaimet(); 27 AloitaPeli(); 28 AsetaOhjaimet(); 29 LisaaLaskurit(); 21 30 } 22 31 … … 43 52 pallo.Restitution = 1.0; 44 53 Add(pallo); 45 pallo.Color = Color. Green;54 pallo.Color = Color.YellowGreen; 46 55 pallo.KineticFriction = 0.0; 47 56 … … 51 60 52 61 53 Level.CreateBorders(1.0, false); 62 vasenReuna = Level.CreateLeftBorder(); 63 vasenReuna.Restitution = 1.0; 64 vasenReuna.IsVisible = false; 65 66 oikeaReuna = Level.CreateRightBorder(); 67 oikeaReuna.Restitution = 1.0; 68 oikeaReuna.IsVisible = false; 69 70 PhysicsObject alaReuna = Level.CreateBottomBorder(); 71 72 PhysicsObject ylaReuna = Level.CreateTopBorder(); 73 54 74 Level.BackgroundColor = Color.Black; 55 75 56 Camera.ZoomToLevel(); 76 Camera.ZoomToLevel(); 77 AddCollisionHandler(pallo, KasittelePallonTormays); 78 57 79 } 58 80 PhysicsObject LuoMaila(double x, double y) … … 87 109 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 88 110 { 89 if (maila.Top > Level.Top) 111 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 112 { 113 maila.Velocity = Vector.Zero; 114 return; 115 } 116 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 90 117 { 91 118 maila.Velocity = Vector.Zero; … … 93 120 } 94 121 122 95 123 maila.Velocity = nopeus; 96 124 } 97 125 98 126 protected override void Update(Time time) 127 { 128 base.Update(time); 129 if (pallo.Velocity.Magnitude > 600) 130 { 131 while (pallo.Velocity.Magnitude > 500) 132 { 133 pallo.Velocity /= 1.1; 134 } 135 136 } 137 138 if (pallo.Velocity.Magnitude < 400) 139 { 140 while (pallo.Velocity.Magnitude < 500) 141 { 142 pallo.Velocity *= 1.1; 143 } 144 } 145 } 146 IntMeter LuoPisteLaskuri(double x, double y) 147 { 148 IntMeter laskuri = new IntMeter(0); 149 laskuri.MaxValue = 10; 150 Label naytto = new Label(); 151 naytto.BindTo( laskuri ); 152 naytto.X = x; 153 naytto.Y = y; 154 naytto.TextColor = Color.White; 155 Add(naytto); 156 return laskuri; 157 } 158 159 void LisaaLaskurit() 160 { 161 pelaajan1Pisteet = LuoPisteLaskuri( Screen.Left + 100.0, Screen.Top - 100.0 ); 162 pelaajan2Pisteet = LuoPisteLaskuri( Screen.Right - 100.0, Screen.Top - 100.0 ); 163 } 164 165 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 166 { 167 if (kohde == oikeaReuna) 168 { 169 pelaajan1Pisteet.Value += 1; 170 } 171 else if (kohde == vasenReuna) 172 { 173 pelaajan2Pisteet.Value += 1; 174 } 175 176 } 177 178 99 179 100 180 }
Note: See TracChangeset
for help on using the changeset viewer.