Changeset 8890 for 2017/27/LottaH/Bong/Bong
- Timestamp:
- 2017-07-04 14:57:40 (6 years ago)
- Location:
- 2017/27/LottaH/Bong/Bong/Bong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/LottaH/Bong/Bong/Bong/Bong.cs
r8829 r8890 15 15 PhysicsObject maila1; 16 16 PhysicsObject maila2; 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 23 24 25 17 26 public override void Begin() 18 27 { 19 28 LuoKentta(); 20 29 AsetaOhjaimet(); 30 LisaaLaskurit(); 21 31 AloitaPeli(); 22 // TODO: Kirjoita ohjelmakoodisi tähän23 32 24 33 … … 40 49 Add(pallo); 41 50 51 AddCollisionHandler(pallo, KasittelePallonTormays); 52 42 53 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 43 54 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 44 55 45 Level.CreateBorders(1.0, false); 56 vasenReuna = Level.CreateLeftBorder(); 57 vasenReuna.Restitution = 1.0; 58 vasenReuna.KineticFriction = 0.0; 59 vasenReuna.IsVisible = false; 60 61 oikeaReuna = Level.CreateRightBorder(); 62 oikeaReuna.Restitution = 1.0; 63 oikeaReuna.KineticFriction = 0.0; 64 oikeaReuna.IsVisible = false; 65 66 PhysicsObject ylaReuna = Level.CreateTopBorder(); 67 ylaReuna.Restitution = 1.0; 68 ylaReuna.KineticFriction = 0.0; 69 ylaReuna.IsVisible = false; 70 71 PhysicsObject alaReuna = Level.CreateBottomBorder(); 72 alaReuna.Restitution = 1.0; 73 alaReuna.IsVisible = false; 74 alaReuna.KineticFriction = 0.0; 75 46 76 Level.Background.Color = Color.Black; 47 77 … … 49 79 50 80 } 51 void AloitaPeli() 52 { 53 Vector impulssi = new Vector(500.0, 0.0); 54 pallo.Hit(impulssi); 55 } 81 56 82 PhysicsObject LuoMaila(double x, double y) 57 83 { … … 64 90 Add(maila); 65 91 return maila; 92 } 93 94 95 96 IntMeter LuoPisteLaskuri(double x, double y) 97 { 98 99 IntMeter laskuri = new IntMeter(0); 100 laskuri.MaxValue = 10; 101 102 Label naytto = new Label(); 103 naytto.BindTo(laskuri); 104 naytto.X = x; 105 naytto.Y = y; 106 naytto.TextColor = Color.White; 107 naytto.BorderColor = Level.Background.Color; 108 naytto.Color = Level.Background.Color; 109 Add(naytto); 110 111 return laskuri; 112 113 114 115 116 } 117 118 void LisaaLaskurit() 119 { 120 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 121 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 122 } 123 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 124 { 125 if (kohde == oikeaReuna) 126 { 127 pelaajan1Pisteet.Value += 1; 128 } 129 else if (kohde ==vasenReuna) 130 { 131 pelaajan2Pisteet.Value += 1; 132 } 133 } 134 void AloitaPeli() 135 { 136 Vector impulssi = new Vector(500.0, 0.0); 137 pallo.Hit(impulssi); 66 138 } 67 139 void AsetaOhjaimet() … … 86 158 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 87 159 { 160 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 161 { 162 maila.Velocity = Vector.Zero; 163 return; 164 } 165 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 166 { 167 maila.Velocity = Vector.Zero; 168 return; 169 } 170 maila.Velocity = nopeus; 171 } 88 172 89 90 91 92 }93 173 }
Note: See TracChangeset
for help on using the changeset viewer.