- Timestamp:
- 2010-06-15 11:25:39 (13 years ago)
- Location:
- 2010/24/vihoskon
- Files:
-
- 11 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/24/vihoskon/pong/Peli.cs
r812 r834 2 2 using Jypeli; 3 3 using Jypeli.ScreenObjects; 4 using Jypeli.Assets;5 4 6 5 public class Peli : PhysicsGame 7 6 { 8 7 PhysicsObject pallo; 8 PhysicsObject maila1; 9 PhysicsObject maila2; 9 10 10 11 protected override void Begin() 11 12 { 12 13 LuoKentta(); 13 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu"); 14 Vector impulssi = new Vector(500.0, 0.0); 15 pallo.Hit( impulssi); 16 } 17 18 19 void AloitaPeli() 20 { 21 Vector impulssi = new Vector(500.0, 0.0); 22 pallo.Hit(impulssi); 14 AsetaOhjaimet(); 15 AloitaPeli(); 23 16 } 24 17 25 18 void LuoKentta() 26 19 { 27 pallo = new PhysicsObject(4 0.0, 40.0);20 pallo = new PhysicsObject(4.0, 4.0); 28 21 pallo.Shape = Shapes.Circle; 29 22 pallo.X = -200.0; … … 31 24 pallo.Restitution = 1.0; 32 25 Add(pallo); 26 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 27 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 33 28 34 29 Level.CreateBorders(1.0, false); 35 30 Level.BackgroundColor = Color.Black; 36 31 37 LuoMaila(Level.Left + 20.0, 0.0);38 LuoMaila(Level.Right - 20.0, 0.0);32 Camera.ZoomToLevel(); 33 } 39 34 35 PhysicsObject LuoMaila(double x, double y) 36 { 37 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 38 maila.Shape = Shapes.Rectangle; 39 maila.X = x; 40 maila.Y = y; 41 maila.Restitution = 1.0; 42 Add(maila); 43 return maila; 40 44 } 41 void LuoMaila( double x, double y ) 42 { 43 PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 44 maila.Shape = Shapes.Rectangle; 45 maila.X = x; 46 maila.Y = y; 47 maila.Restitution = 1.0; 48 Add( maila );} 49 45 46 void AloitaPeli() 47 { 48 Vector impulssi = new Vector(1000.0, 0.0); 49 pallo.Hit(impulssi); 50 } 51 52 void AsetaOhjaimet() 53 { 54 Keyboard.Listen(Key.A, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös", maila1); 55 Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null, maila1); 56 Keyboard.Listen(Key.Z, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 1: Liikuta mailaa alas", maila1); 57 Keyboard.Listen(Key.Z, ButtonState.Released, PysaytaMaila, null, maila1); 58 59 Keyboard.Listen(Key.Up, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 2: Liikuta mailaa ylös", maila2); 60 Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaMaila, null, maila2); 61 Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 2: Liikuta mailaa alas", maila2); 62 Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaMaila, null, maila2); 63 64 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 65 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 66 } 67 68 void LiikutaMailaaYlos(PhysicsObject maila) 69 { 70 Vector nopeus = new Vector(0, 200); 71 maila.Velocity = nopeus; 72 } 73 74 void LiikutaMailaaAlas(PhysicsObject maila) 75 { 76 Vector nopeus = new Vector(0, -200); 77 maila.Velocity = nopeus; 78 } 79 80 void PysaytaMaila(PhysicsObject maila) 81 { 82 maila.Velocity = Vector.Zero; 83 } 50 84 } 51 52 53 54 55 56 57
Note: See TracChangeset
for help on using the changeset viewer.