Changeset 1604 for 2010/31/jomaveij/Pong/Peli.cs
- Timestamp:
- 2010-08-04 14:59:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/31/jomaveij/Pong/Peli.cs
r1573 r1604 8 8 PhysicsObject pallero; 9 9 Vector yhaylosyrittaa = new Vector(0, 200); 10 Vector maanalainen = new Vector(); 10 Vector maanalainen = new Vector(0, -200); 11 PhysicsObject vasen; 12 PhysicsObject oikia; 13 PhysicsObject pelaaja1; 14 PhysicsObject pelaaja2; 15 IntMeter Ykkospisteet; 16 IntMeter Kakkospisteet; 11 17 12 18 protected override void Begin() … … 14 20 Kentta(); 15 21 Ohjustukikohta(); 22 Pluslaskut(); 16 23 Alota(); 17 PingPong(Level.Left + 20, 0.0); 18 PingPong(Level.Right - 20, 0.0); 24 19 25 } 20 26 … … 26 32 Add(pallero); 27 33 pallero.Restitution = 1.0; 28 Level.CreateBorders(1.0, true); 34 AddCollisionHandler(pallero, Tyrmäys); 35 vasen = Level.CreateLeftBorder(); 36 oikia = Level.CreateRightBorder(); 37 PhysicsObject katto = Level.CreateTopBorder(); 38 PhysicsObject lattia = Level.CreateBottomBorder(); 29 39 Level.BackgroundColor = Color.ForestGreen; 30 Camera.ZoomToLevel(); 40 Camera.ZoomToLevel(); 41 pelaaja1 = PingPong(Level.Left + 20, 0.0); 42 pelaaja2 = PingPong(Level.Right - 20, 0.0); 31 43 } 32 44 33 45 void Alota() 34 46 { 35 Vector newton = new Vector( 1000.0, 500.0);47 Vector newton = new Vector(-1000.0, 500.0); 36 48 pallero.Hit(newton); 37 49 } 38 voidPingPong(double x, double y)50 PhysicsObject PingPong(double x, double y) 39 51 { 40 52 PhysicsObject pong = PhysicsObject.CreateStaticObject(20.0, 50.0); … … 42 54 pong.Restitution = 1.0; 43 55 Add(pong); 56 return pong; 57 } 58 59 void Tyrmäys(PhysicsObject pallero, PhysicsObject uhri) 60 { 61 if (uhri == oikia) 62 { 63 Ykkospisteet.Value += 1; 64 } 65 if (uhri == vasen) 66 { 67 Kakkospisteet.Value += 1; 68 } 44 69 } 45 70 46 71 void Ohjustukikohta() 47 72 { 48 Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös"); 49 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null); 50 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu!!!"); 73 Keyboard.Listen(Key.A, ButtonState.Down, Vauhdikkuus, "Pelaaja 1: Liikuta mailaa ylös", pelaaja1, yhaylosyrittaa); 74 Keyboard.Listen(Key.A, ButtonState.Released, Vauhdikkuus, null, pelaaja1, Vector.Zero); 75 Keyboard.Listen(Key.Z, ButtonState.Down, Vauhdikkuus, "Pelaaja 1: Liikuta mailaa alas", pelaaja1, maanalainen); 76 Keyboard.Listen(Key.Z, ButtonState.Released, Vauhdikkuus, null, pelaaja1, Vector.Zero); 77 Keyboard.Listen(Key.Up, ButtonState.Down, Vauhdikkuus, "Pelaaja 2: Liikuta mailaa ylös", pelaaja2, yhaylosyrittaa); 78 Keyboard.Listen(Key.Up, ButtonState.Released, Vauhdikkuus, null, pelaaja2, Vector.Zero); 79 Keyboard.Listen(Key.Down, ButtonState.Down, Vauhdikkuus, "Pelaaja 2: Liikuta mailaa alas", pelaaja2, maanalainen); 80 Keyboard.Listen(Key.Down, ButtonState.Released, Vauhdikkuus, null, pelaaja2, Vector.Zero); 81 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohje"); 82 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 83 84 } 85 86 void Pluslaskut() 87 { 88 Ykkospisteet = Laskin(Screen.Left + 100.0, Screen.Top - 100.0); 89 Kakkospisteet = Laskin(Screen.Right - 100.0, Screen.Top - 100.0); 90 } 91 92 IntMeter Laskin(double x, double y) 93 { 94 IntMeter laskin = new IntMeter(0); 95 laskin.MaxValue = 5; 96 97 Label tausta = new Label(); 98 tausta.BindTo(laskin); 99 tausta.X = x; 100 tausta.Y = y; 101 Add(tausta); 102 return laskin; 51 103 } 52 104 53 105 void Vauhdikkuus(PhysicsObject pong, Vector vauhti) 54 106 { 107 if ((vauhti.Y < 0) && (pong.Bottom < Level.Bottom)) 108 { 109 pong.Velocity = Vector.Zero; 110 return; 111 } 112 if ((vauhti.Y > 0) && (pong.Top > Level.Top)) 113 { 114 pong.Velocity = Vector.Zero; 115 return; 116 } 55 117 pong.Velocity = vauhti; 56 118 }
Note: See TracChangeset
for help on using the changeset viewer.