- Timestamp:
- 2015-06-29 14:51:53 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/JaakkoS/Pong/Pong/Pong/Pong.cs
r6506 r6524 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 13 11 14 PhysicsObject pallo; 15 16 PhysicsObject maila1; 17 PhysicsObject maila2; 18 19 IntMeter pelaajan1Pisteet; 20 IntMeter pelaajan2Pisteet; 12 21 13 22 public override void Begin() … … 16 25 AloitaPeli(); 17 26 AsetaOhjaimet(); 27 LisaaLaskurit(); 18 28 19 29 … … 29 39 Add(pallo); 30 40 31 LuoMaila (Level.Left + 20.0, 0.0);32 LuoMaila(Level.Right - 20.0, 0.0);41 maila1 = LuoMaila (Level.Left + 20.0, 0.0); 42 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 33 43 34 44 Level.CreateBorders(1.0, false); … … 46 56 } 47 57 48 voidLuoMaila(double x, double y)58 PhysicsObject LuoMaila(double x, double y) 49 59 { 50 60 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 55 65 maila.Color = Color.LightGreen; 56 66 Add(maila); 67 return maila; 57 68 } 58 69 void AsetaOhjaimet() 59 70 { 60 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaasi ylös"); 61 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); 71 Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja1: Liikuta mailaa ylös", maila1, nopeusYlos); 72 Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 73 Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Pelaaja1: Liikuta mailaa alas", maila1, nopeusAlas); 74 Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 62 75 76 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja2: Liikuta mailaa ylös", maila2, nopeusYlos); 77 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 78 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja2: Liikuta mailaa alas", maila2, nopeusAlas); 79 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 80 81 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 63 82 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 64 83 } 65 84 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 66 85 { 86 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 87 { 88 maila.Velocity = Vector.Zero; 89 return; 90 } 91 if ((nopeus.Y > 0) && (maila.Bottom > Level.Bottom)) 92 { 93 maila.Velocity = Vector.Zero; 94 return; 95 } 96 67 97 maila.Velocity = nopeus; 98 } 99 void LisaaLaskurit() 100 { 101 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 102 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right + 100.0, Screen.Top - 100.0); 103 } 104 IntMeter LisaaPisteLaskurit() 105 { 106 IntMeter laskuri = new IntMeter(0); 107 laskuri.MaxValue = 10; 108 109 110 Label naytto = new Label(); 111 naytto.BindTo(laskuri); 112 naytto.X = x; 113 naytto.Y = y; 114 naytto.TextColor = Color.White; 115 naytto.BorderColor = Level.Background.Color; 116 naytto.Color = Level.Background.Color; 117 Add(naytto); 118 119 return laskuri; 68 120 } 69 121 }
Note: See TracChangeset
for help on using the changeset viewer.