- Timestamp:
- 2012-06-15 12:14:30 (11 years ago)
- Location:
- 2012/24/JuhoH
- Files:
-
- 60 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/24/JuhoH
-
Property
svn:ignore
set to
Ball vs. Predator
Ball vs. Predators
-
Property
svn:ignore
set to
-
2012/24/JuhoH/pong/pong/pong/pong.cs
r2919 r3111 9 9 public class pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200);12 Vector nopeusAlas = new Vector(0, - 200);11 Vector nopeusYlos = new Vector(0, 400); 12 Vector nopeusAlas = new Vector(0, -400); 13 13 14 14 PhysicsObject pallo; 15 15 PhysicsObject maila1; 16 16 PhysicsObject maila2; 17 PhysicsObject vasenReuna; 18 PhysicsObject oikeaReuna; 19 IntMeter pelaajan1Pisteet; 20 IntMeter pelaajan2Pisteet; 21 17 22 public override void Begin() 18 23 { … … 20 25 LuoKentta(); 21 26 AsetaOhjaimet(); 27 LisaaLaskurit(); 22 28 AloitaPeli(); 23 29 // TODO: Kirjoita ohjelmakoodisi tähän … … 37 43 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 38 44 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 45 46 39 47 pallo.Restitution = 1.0; 40 Level.CreateBorders(1.0, true); 48 49 vasenReuna = Level.CreateLeftBorder(); 50 vasenReuna.Restitution = 1.0; 51 vasenReuna.IsVisible = false; 52 oikeaReuna = Level.CreateRightBorder(); 53 oikeaReuna.Restitution = 1.0; 54 oikeaReuna.IsVisible = false; 55 PhysicsObject alaReuna = Level.CreateBottomBorder(); 56 alaReuna.Restitution = 1.0; 57 alaReuna.IsVisible = false; 58 PhysicsObject ylaReuna = Level.CreateTopBorder(); 59 ylaReuna.Restitution = 1.0; 60 ylaReuna.IsVisible = false; 41 61 Level.BackgroundColor = Color.Orange; 42 62 Camera.ZoomToLevel(); 43 63 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 44 maila.Shape = Shape.Rectangle; 45 maila.X = Level.Left + 20.0; 46 maila.Y = 0.0; 47 maila.Restitution = 1.0; 48 Add(maila); 49 64 AddCollisionHandler(pallo, KasittelePallonTormays); 50 65 51 66 } … … 53 68 void AloitaPeli() 54 69 { 55 Vector impulssi = new Vector( 500.0, 0.0);70 Vector impulssi = new Vector(700.0, 0.0); 56 71 pallo.Hit(impulssi); 57 72 } … … 85 100 86 101 87 102 88 103 89 104 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); … … 91 106 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 92 107 { 108 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 109 { 110 maila.Velocity = Vector.Zero; 111 return; 112 } 113 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 114 { 115 maila.Velocity = Vector.Zero; 116 return; 117 } 118 93 119 maila.Velocity = nopeus; 94 120 } 121 void LisaaLaskurit() 122 { 123 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 124 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 125 } 95 126 127 128 129 IntMeter LuoPisteLaskuri(double x, double y) 130 { 131 IntMeter laskuri = new IntMeter(0); 132 laskuri.MaxValue = 10; 133 Label naytto = new Label(); 134 naytto.BindTo(laskuri); 135 naytto.X = x; 136 naytto.Y = y; 137 naytto.TextColor = Color.White; 138 naytto.BorderColor = Level.BackgroundColor; 139 naytto.Color = Level.BackgroundColor; 140 Add(naytto); 141 142 return laskuri; 143 } 144 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 145 { 146 { 147 if (kohde == oikeaReuna) 148 { 149 pelaajan1Pisteet.Value += 1; 150 } 151 else if (kohde == vasenReuna) 152 { 153 pelaajan2Pisteet.Value += 1; 154 } 155 } 156 157 } 96 158 } 159 160
Note: See TracChangeset
for help on using the changeset viewer.