Changeset 8132 for 2016/30/AapoN/Pong
- Timestamp:
- 2016-07-27 09:58:23 (7 years ago)
- Location:
- 2016/30/AapoN/Pong
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/30/AapoN/Pong/Pong/Pong/Pong.cs
r8094 r8132 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 13 IntMeter Pelaajan1pisteet; 14 IntMeter Pelaajan2pisteet; 15 11 16 PhysicsObject pallo; 17 PhysicsObject maila1; 18 PhysicsObject maila2; 19 20 PhysicsObject vasenreuna; 21 PhysicsObject oikeareuna; 12 22 public override void Begin() 13 23 { 14 24 luokentta(); 25 AsetaOhjaimet(); 15 26 AloitaPeli(); 16 17 18 19 20 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 27 lisaalaskurit(); 21 28 } 22 29 void luokentta() … … 29 36 pallo.Restitution = 1.0; 30 37 Add(pallo); 38 AddCollisionHandler(pallo, KasittelePallonTormays); 31 39 32 LuoMaila(Level.Left + 20.0, 0.0);33 LuoMaila(Level.Right - 20.0, 0.0);40 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 41 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 42 35 Level.CreateBorders(1.0, false); 36 Level.Background.Color = Color.Turquoise; 43 vasenreuna = Level.CreateLeftBorder(); 44 vasenreuna.Restitution = 1.0; 45 oikeareuna = Level.CreateRightBorder(); 46 oikeareuna.Restitution = 1.0; 47 PhysicsObject alareuna = Level.CreateBottomBorder(); 48 alareuna.Restitution = 1.0; 49 PhysicsObject yläreuna = Level.CreateTopBorder(); 50 yläreuna.Restitution = 1.0; 51 Level.Background.Color = Color.Black; 37 52 38 53 Camera.ZoomToLevel(); … … 46 61 pallo.Hit(impulssi); 47 62 } 48 voidLuoMaila(double x, double y)63 PhysicsObject LuoMaila(double x, double y) 49 64 { 50 65 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 54 69 maila.Restitution = 1.0; 55 70 Add(maila); 71 return maila; 72 } 73 void AsetaOhjaimet() 74 { 75 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: liikuttaa mailaa ylos", maila1, nopeusYlos); 76 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 77 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: liikuttaa mailaa alas", maila1, nopeusAlas); 78 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 56 79 80 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: liikuttaa mailaa ylos", maila2, nopeusYlos); 81 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 82 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: liikuttaa mailaa alas", maila2, nopeusAlas); 83 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 84 85 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 86 } 87 88 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 89 { 90 if ((nopeus.Y < 0 && (maila.Bottom < Level.Bottom))) 57 91 { 58 92 maila.Velocity = Vector.Zero; 93 return; 94 } 95 96 if ((nopeus.Y > 0 && (maila.Top > Level.Top))) 97 { 98 maila.Velocity = Vector.Zero; 99 return; 100 } 101 maila.Velocity = nopeus; 102 } 103 void lisaalaskurit() 104 { 105 Pelaajan1pisteet = luoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 106 Pelaajan2pisteet = luoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 107 108 109 } 110 IntMeter luoPisteLaskuri(double x, double y) 111 { 112 IntMeter laskuri = new IntMeter(0); 113 114 laskuri.MaxValue = 10; 115 Label naytto = new Label(); 116 naytto.BindTo(laskuri); 117 naytto.X = x; 118 naytto.Y = y; 119 naytto.TextColor = Color.White; 120 naytto.BorderColor = Level.Background.Color; 121 naytto.Color = Level.Background.Color; 122 Add(naytto); 123 return laskuri; 124 } 125 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 126 { 127 if (kohde == oikeareuna) 128 { 129 Pelaajan1pisteet.Value += 1; 130 131 132 } 133 else if (kohde == vasenreuna) 134 { 135 Pelaajan2pisteet.Value += 1; 59 136 } 60 137 } 61 138 } 139 140 141 142 143 144 145 146 147 62 148 63 149 … … 74 160 75 161 162
Note: See TracChangeset
for help on using the changeset viewer.