- Timestamp:
- 2010-07-27 11:25:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/lijiolva/p0ng/Peli.cs
r1296 r1307 2 2 using Jypeli; 3 3 using Jypeli.Widgets; 4 using Jypeli.Assets;5 4 6 5 public class Peli : PhysicsGame … … 10 9 11 10 PhysicsObject pallo; 12 13 11 PhysicsObject maila1; 14 12 PhysicsObject maila2; 15 13 14 IntMeter pelaajan1Pisteet; 15 IntMeter pelaajan2Pisteet; 16 17 PhysicsObject vasenReuna; 18 PhysicsObject oikeaReuna; 19 16 20 protected override void Begin() 17 21 { 18 //TODO: Alusta peli tässä22 LuoKentta(); 19 23 AsetaOhjaimet(); 20 LuoKentta() ; 21 AloitaPeli() ; 22 24 LisaaLaskurit(); 25 AloitaPeli(); 23 26 } 27 24 28 void LuoKentta() 25 29 { 26 pallo = new PhysicsObject(40.0, 40.0); 27 pallo.Shape = Shapes.Circle ; 28 Add(pallo); 29 pallo.X = 200.0; 30 pallo.Y = 5.9; 31 pallo.Color = Color.DarkViolet ; 32 Level.CreateBorders( 1.0,false); 30 pallo = new PhysicsObject( 40.0, 40.0 ); 31 pallo.Shape = Shapes.Circle; 32 pallo.X = -200.0; 33 pallo.Y = 0.0; 33 34 pallo.Restitution = 1.0; 34 Level.BackgroundColor = Color.DarkRed ; 35 Camera.ZoomToLevel(); 35 pallo.CanRotate = false; 36 Add( pallo ); 37 38 36 39 maila1 = LuoMaila( Level.Left + 20.0, 0.0 ); 37 40 maila2 = LuoMaila( Level.Right - 20.0, 0.0 ); 41 42 vasenReuna = Level.CreateLeftBorder(); 43 vasenReuna.Restitution = 1.0; 44 vasenReuna.IsVisible = false; 38 45 46 oikeaReuna = Level.CreateRightBorder(); 47 oikeaReuna.Restitution = 1.0; 48 oikeaReuna.IsVisible = false; 49 50 PhysicsObject ylaReuna = Level.CreateTopBorder(); 51 vasenReuna.Restitution = 1.0; 52 vasenReuna.IsVisible = false; 53 54 PhysicsObject alaReuna = Level.CreateBottomBorder(); 55 vasenReuna.Restitution = 1.0; 56 vasenReuna.IsVisible = false; 57 58 Level.BackgroundColor = Color.Black; 59 60 Camera.ZoomToLevel(); 61 AddCollisionHandler(pallo, KasittelePallonTormays) ; 39 62 } 63 64 PhysicsObject LuoMaila( double x, double y ) 65 { 66 PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0 ); 67 maila.Shape = Shapes.Rectangle; 68 maila.X = x; 69 maila.Y = y; 70 maila.Restitution = 1.0; 71 Add( maila ); 72 return maila; 73 } 74 40 75 void AloitaPeli() 41 76 { 42 Vector impulssi = new Vector(500.0, 1.0);43 pallo.Hit(impulssi);77 Vector impulssi = new Vector( 500.0, 0.0 ); 78 pallo.Hit( impulssi ); 44 79 } 45 PhysicsObject LuoMaila(double x, double y)46 {47 48 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);49 maila.Shape = Shapes.Rectangle;50 maila.X = x;51 maila.Y = y;52 maila.Restitution = 1.0;53 Add(maila);54 80 55 return maila; 56 } 57 void AsetaOhjaimet() 58 { 59 81 void AsetaOhjaimet() 82 { 60 83 Keyboard.Listen( Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos ); 61 84 Keyboard.Listen( Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero ); … … 70 93 Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet" ); 71 94 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu" ); 95 } 96 72 97 73 } 74 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 98 void AsetaNopeus( PhysicsObject maila, Vector nopeus ) 75 99 { 100 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 101 { 102 maila.Velocity = Vector.Zero; 103 return; 104 } 105 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 106 { 107 maila.Velocity = Vector.Zero; 108 return; 109 } 76 110 maila.Velocity = nopeus; 77 111 } 78 } 112 void LisaaLaskurit() 113 { 114 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 115 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 116 } 117 IntMeter LuoPisteLaskuri(double x, double y) 118 { 119 IntMeter laskuri = new IntMeter(0); 120 laskuri.MaxValue = 10; 121 Label naytto = new Label(); 122 naytto.BindTo(laskuri); 123 naytto.X = x; 124 naytto.Y = y; 125 naytto.TextColor = Color.White; 126 Add(naytto); 127 return laskuri; 128 } 129 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 130 { 131 if (kohde == oikeaReuna) 132 { 133 pelaajan1Pisteet.Value += 1; 134 } 135 else if (kohde == vasenReuna) 136 { 137 pelaajan2Pisteet.Value += 1; 138 } 139 } 140 }
Note: See TracChangeset
for help on using the changeset viewer.