Changeset 8854
- Timestamp:
- 2017-07-03 15:02:03 (5 years ago)
- Location:
- 2017/27/PyryS
- Files:
-
- 96 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/27/PyryS/Pong/Pong/Pong/Pong.cs
r8819 r8854 12 12 PhysicsObject LPaddle; 13 13 PhysicsObject RPaddle; 14 PhysicsObject RightBorder; 15 PhysicsObject LeftBorder; 16 PhysicsObject BottomBorder; 17 PhysicsObject TopBorder; 14 18 Vector SpeedUp = new Vector(0, 400); 15 19 Vector SpeedDown = new Vector(0, -400); 20 IntMeter P1Score; 21 IntMeter P2Score; 16 22 public override void Begin() 17 23 { … … 27 33 28 34 // Call score function 29 Add Score();35 AddCounters(); 30 36 31 37 } … … 46 52 Add(Ball); 47 53 54 // Set up collision handling for Ball 55 AddCollisionHandler(Ball, BallCollisionHandler); 56 48 57 // Create level borders 49 Level.CreateBorders(1.0, true); 58 LeftBorder = Level.CreateLeftBorder(); 59 LeftBorder.Restitution = 1.0; 60 LeftBorder.IsVisible = true; 61 62 RightBorder = Level.CreateRightBorder(); 63 RightBorder.Restitution = 1.0; 64 RightBorder.IsVisible = true; 65 66 BottomBorder = Level.CreateBottomBorder(); 67 BottomBorder.Restitution = 1.0; 68 BottomBorder.IsVisible = true; 69 70 TopBorder = Level.CreateTopBorder(); 71 TopBorder.Restitution = 1.0; 72 TopBorder.IsVisible = true; 50 73 51 74 // Set Background color to black … … 53 76 54 77 // Zoom camera to just show the level 55 Camera.ZoomTo Level();78 Camera.ZoomToAllObjects(); 56 79 57 80 // Create paddles … … 114 137 { 115 138 Paddle.Velocity = Vector.Zero; 116 return;117 139 } 118 if ((Speed.Y > 0) && Paddle.Bottom >Level.Bottom)140 if ((Speed.Y > 0) && Paddle.Bottom < Level.Bottom) 119 141 { 120 142 Paddle.Velocity = Vector.Zero; 121 return;122 143 } 123 144 Paddle.Velocity = Speed; 124 145 } 125 146 // Function for score counters 126 IntMeter AddScore()147 IntMeter ScoreDisplay(double x, double y) 127 148 { 128 149 // Define score counter 129 150 IntMeter Counter = new IntMeter(0); 130 151 Counter.MaxValue = 15; 152 153 // Define score counter text 154 Label ScoreDisplay = new Label(); 155 ScoreDisplay.BindTo(Counter); 156 ScoreDisplay.X = x; 157 ScoreDisplay.Y = y; 158 ScoreDisplay.TextColor = Color.White; 159 ScoreDisplay.BorderColor = Level.Background.Color; 160 ScoreDisplay.Color = Level.Background.Color; 161 Add(ScoreDisplay); 162 131 163 return Counter; 132 164 } 165 void AddCounters() 166 { 167 P1Score = ScoreDisplay(Screen.Left + 480.0, Screen.Top - 200.0); 168 P2Score = ScoreDisplay(Screen.Right - 480.0, Screen.Top - 200.0); 169 } 170 // Ball collision handling 171 void BallCollisionHandler(PhysicsObject Ball, PhysicsObject Subject) 172 { 173 if (Subject == RightBorder) 174 { 175 P1Score.Value += 1; 176 } 177 else if (Subject == LeftBorder) 178 { 179 P2Score.Value += 1; 180 } 181 } 133 182 }
Note: See TracChangeset
for help on using the changeset viewer.