Changeset 1310 for 2010/30/nilaiton/Pong
- Timestamp:
- 2010-07-27 11:26:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/nilaiton/Pong/Peli.cs
r1287 r1310 10 10 11 11 PhysicsObject pallo; 12 PhysicsObject vasenReuna; 13 PhysicsObject oikeaReuna; 12 14 13 15 PhysicsObject maila1; 14 16 PhysicsObject maila2; 17 IntMeter pelaajan1Pisteet; 18 IntMeter pelaajan2Pisteet; 15 19 16 20 protected override void Begin() … … 18 22 LuoKentta(); 19 23 AsetaOhjaimet(); 20 24 LisaaLaskurit(); 21 25 AloitaPeli(); 22 26 23 27 24 28 25 29 26 30 } … … 29 33 { 30 34 pallo = new PhysicsObject(40.0, 40.0); 31 pallo.Shape = Shapes. Circle;35 pallo.Shape = Shapes.Triangle; 32 36 Add(pallo); 33 37 pallo.X = -200.0; 34 38 pallo.Y = 0.0; 35 39 pallo.CanRotate = true; 40 pallo.KineticFriction = 0.0; 36 41 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 37 42 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 43 pallo.Color = Color.Fuchsia; 44 pallo.Velocity = new Vector ( 20.0, 20.0); 45 46 PhysicsObject pallo2; 47 48 pallo2 = new PhysicsObject(60.0, 60.0); 49 pallo2.Shape = Shapes.Triangle; 50 Add(pallo2); 51 pallo2.X = -200.0; 52 pallo2.Y = 0.0; 53 pallo2.CanRotate = true; 54 pallo2.KineticFriction = 0.0; 55 56 pallo2.Color = Color.SkyBlue; 57 pallo2.Velocity = new Vector(20.0, 20.0); 58 pallo2.Restitution = 1.0; 59 AddCollisionHandler(pallo, KasittelePallonTormays); 60 61 vasenReuna = Level.CreateLeftBorder(); 62 vasenReuna.Restitution = 1.0; 63 vasenReuna.IsVisible = false; 64 oikeaReuna = Level.CreateRightBorder(); 65 oikeaReuna.Restitution = 1.0; 66 oikeaReuna.IsVisible = false; 67 PhysicsObject ylaReuna = Level.CreateTopBorder(); 68 ylaReuna.Restitution = 1.0; 69 ylaReuna.IsVisible = false; 70 PhysicsObject alaReuna = Level.CreateBottomBorder(); 71 alaReuna.Restitution = 1.0; 72 alaReuna.IsVisible = false; 38 73 39 74 40 Level.CreateBorders(1.0,false); 75 76 41 77 pallo.Restitution = 1.0; 42 Level.BackgroundColor = Color. DarkRed;78 Level.BackgroundColor = Color.TransparentBlack; 43 79 Camera.ZoomToLevel(); 44 80 45 81 AddCollisionHandler(pallo, KasittelePallonTormays); 82 46 83 47 84 } … … 54 91 { 55 92 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 56 maila.Shape = Shapes. Circle;93 maila.Shape = Shapes.Rectangle; 57 94 maila.X = x; 58 95 maila.Y = y; 59 96 maila.Restitution = 1.0; 60 97 Add(maila); 98 maila.Color = Color.Aqua; 61 99 62 100 return maila; … … 82 120 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 83 121 { 122 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 123 { 124 maila.Velocity = Vector.Zero; 125 return; 126 } 84 127 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 85 128 { … … 88 131 } 89 132 90 maila.Velocity = nopeus; 133 maila.Velocity = nopeus; 134 135 } 136 void LisaaLaskurit() 137 { 138 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 139 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 140 141 } 142 IntMeter LuoPisteLaskuri(double x, double y) 143 { 144 IntMeter laskuri = new IntMeter(0); 145 laskuri.MaxValue = 10; 146 Label naytto = new Label(500,500); 147 naytto.BindTo(laskuri); 148 naytto.X = x; 149 naytto.Y = y; 150 naytto.TextColor = Color.OrangeRed; 151 152 Add(naytto); 153 return laskuri; 154 } 155 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 156 { 157 if (kohde == oikeaReuna) 158 { 159 pelaajan1Pisteet.Value += 1; 160 } 161 else if (kohde == vasenReuna) 162 { 163 pelaajan2Pisteet.Value += 1; 164 } 91 165 } 92 166
Note: See TracChangeset
for help on using the changeset viewer.