Changeset 7553 for 2016/26/ViiviV
- Timestamp:
- 2016-06-28 14:32:52 (5 years ago)
- Location:
- 2016/26/ViiviV/Ping pong
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/26/ViiviV/Ping pong/Ping pong/Ping_pong/Ping_pong.cs
r7548 r7553 8 8 9 9 public class Ping_pong : PhysicsGame 10 11 12 10 { 13 11 Vector nopeusYlos = new Vector(0, 200); … … 15 13 PhysicsObject maila1; 16 14 PhysicsObject maila2; 15 IntMeter pelaajan1Pisteet; 16 IntMeter pelaajan2Pisteet; 17 PhysicsObject vasenReuna; 18 PhysicsObject oikeaReuna; 19 17 20 18 21 … … 23 26 LuoKentta(); 24 27 AsetaOhjaimet(); 28 LisaaLaskurit(); 29 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 25 30 26 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 27 28 Vector impulssi = new Vector(500.0 ,100.50); 31 Vector impulssi = new Vector(500.0, 100.50); 29 32 Level.CreateBorders(1.0, false); 30 33 pallo.Hit(impulssi); 31 32 34 33 35 } … … 35 37 void LuoKentta() 36 38 { 37 39 pallo = new PhysicsObject(40.0, 40.0); 38 40 Add(pallo); 39 41 pallo.Shape = Shape.Circle; 40 42 pallo.X = -200.0; 41 Level.CreateBorders(1.0, false); 43 44 vasenReuna = Level.CreateLeftBorder(); 45 vasenReuna.Restitution = 1.0; 46 vasenReuna.IsVisible = false; 47 48 oikeaReuna = Level.CreateRightBorder(); 49 oikeaReuna.Restitution = 1.0; 50 oikeaReuna.IsVisible = false; 51 52 42 53 pallo.Restitution = 1.0; 43 54 Level.Background.Color = Color.Black; 44 Camera. ZoomToLevel(); 45 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 46 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 55 Camera.ZoomToLevel(); 56 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 57 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 58 AddCollisionHandler(pallo, KasittelePallonTormays); 47 59 48 60 } 49 void Aloitapeli()61 void Aloitapeli() 50 62 { 51 63 Vector impulssi = new Vector(500.0, 0.0); … … 66 78 { 67 79 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopetapeli"); 68 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös",maila1, nopeusYlos);80 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 69 81 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 70 82 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); … … 76 88 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 77 89 } 90 78 91 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 79 92 { 93 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 94 { 95 maila.Velocity = Vector.Zero; 96 return; 97 } 98 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 99 { 100 maila.Velocity = Vector.Zero; 101 return; 102 103 104 105 106 107 } 80 108 maila.Velocity = nopeus; 81 if (maila.Top > )82 109 } 110 void LisaaLaskurit() 111 { 112 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 113 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 114 } 115 IntMeter LuoPisteLaskuri(double x, double y) 116 { 117 IntMeter laskuri = new IntMeter(0); 118 laskuri.MaxValue = 10; 119 120 Label naytto = new Label(); 121 naytto.BindTo(laskuri); 122 naytto.X = x; 123 naytto.Y = y; 124 naytto.TextColor = Color.White; 125 naytto.BorderColor = Level.Background.Color; 126 naytto.Color = Level.Background.Color; 127 Add(naytto); 128 return laskuri; 129 130 } 131 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 132 { 133 134 135 if (kohde == oikeaReuna) 136 { 137 pelaajan1Pisteet.Value += 1; 138 } 139 else if (kohde == vasenReuna) 140 { 141 pelaajan2Pisteet.Value += 1; 142 } 143 144 145 } 146 83 147 } 84 148 149
Note: See TracChangeset
for help on using the changeset viewer.