- Timestamp:
- 2012-06-12 13:13:03 (9 years ago)
- Location:
- 2012/24/MattiV
- Files:
-
- 31 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/24/MattiV/Pong/Pong/Pong/Pong.cs
r2926 r2945 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200);12 Vector nopeusAlas = new Vector(0, - 200);11 Vector nopeusYlos = new Vector(0, 500); 12 Vector nopeusAlas = new Vector(0, -500); 13 13 14 14 … … 16 16 PhysicsObject maila1; 17 17 PhysicsObject maila2; 18 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 19 20 IntMeter pelaajan1Pisteet; 20 21 IntMeter pelaajan2Pisteet; … … 25 26 AsetaOhjaimet(); 26 27 AloitaPeli(); 27 LisaaLaskuri(); 28 LisaaLaskuri(); 28 29 29 30 } … … 38 39 pallo.Restitution = 1.0; 39 40 Add(pallo); 41 AddCollisionHandler(pallo, KasittelePallonTormays); 40 42 41 43 maila1 = Maila(Level.Left + 20.0, 0.0); 42 44 maila2 = Maila(Level.Right - 20.0, 0.0); 43 45 44 Level.CreateBorders(1.0, false); 46 vasenReuna = Level.CreateLeftBorder(); 47 vasenReuna.Restitution = 1.0; 48 vasenReuna.IsVisible = false; 49 oikeaReuna = Level.CreateRightBorder(); 50 oikeaReuna.Restitution = 1.0; 51 oikeaReuna.IsVisible = false; 52 PhysicsObject ylaReuna = Level.CreateTopBorder(); 53 ylaReuna.Restitution = 1.0; 54 ylaReuna.IsVisible = false; 55 PhysicsObject alaReuna = Level.CreateBottomBorder(); 56 alaReuna.Restitution = 1.0; 57 alaReuna.IsVisible = false; 58 45 59 Level.BackgroundColor = Color.Black; 46 60 47 61 Camera.ZoomToLevel(); 48 62 } … … 62 76 maila.Restitution = 1.0; 63 77 Add(maila); 64 65 78 return maila; 66 79 } … … 84 97 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 85 98 { 86 if ( (nopeus.Y > 0) && (maila.Top > Level.Top))99 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 87 100 { 88 101 maila.Velocity = Vector.Zero; 89 102 return; 90 103 } 91 if ( (nopeus.Y > 0) && (maila.Top > Level.Top))104 if ( (nopeus.Y > 0) && (maila.Top > Level.Top) ) 92 105 { 93 106 maila.Velocity = Vector.Zero; … … 96 109 97 110 maila.Velocity = nopeus; 98 111 } 99 112 void LisaaLaskuri() 100 113 { 101 //... 114 pelaajan1Pisteet = LuoPisteLaskuri ( Screen.Left + 100.0, Screen.Top - 100.0); 115 pelaajan2Pisteet = LuoPisteLaskuri ( Screen.Right - 100.0, Screen.Top - 100.0); 116 102 117 } 103 IntMeter LuoPisteLaskuri( )118 IntMeter LuoPisteLaskuri(double x, double y) 104 119 { 105 IntMeter laskuri = new IntMeter( 0);120 IntMeter laskuri = new IntMeter(0); 106 121 laskuri.MaxValue = 15; 107 return laskuri;108 122 Label naytto = new Label(); 109 naytto.BindTo( laskuri);123 naytto.BindTo(laskuri); 110 124 naytto.X = x; 111 125 naytto.Y = y; … … 113 127 naytto.BorderColor = Level.BackgroundColor; 114 128 naytto.Color = Level.BackgroundColor; 115 Add( naytto);129 Add(naytto); 116 130 return laskuri; 117 131 } 132 133 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 134 { 135 if (kohde == oikeaReuna) 136 { 137 pelaajan1Pisteet.Value += 1; 138 } 139 else if (kohde == vasenReuna) 140 { 141 pelaajan2Pisteet.Value += 1; 142 } 143 } 144 } 118 145 119 146
Note: See TracChangeset
for help on using the changeset viewer.