- Timestamp:
- 2014-06-30 15:07:27 (9 years ago)
- Location:
- 2014/27/MikkoI/MikonPeli
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/27/MikkoI/MikonPeli/MikonPeli/MikonPeli/MikonPeli.cs
r5167 r5190 9 9 public class BreakablePhysicsObject : PhysicsObject 10 10 { 11 public void Break(int method) { 12 11 private bool broken = false; 12 private MikonPeli game; 13 public void Break(int method, int pieceCountX = 2, int pieceCountY = 2) 14 { 15 if (this.broken) { return; } 16 this.Destroy(); 17 this.broken = true; 18 switch (method) 19 { 20 case 0://uniform break 21 var pieceWidth = this.Width / pieceCountX; 22 var pieceHeight = this.Height / pieceCountY; 23 //loop x and y through 24 //calc left corner 25 var startCorner = Vector.FromLengthAndAngle(this.Width/2-pieceWidth/2,this.AbsoluteAngle+Angle.StraightAngle)+Vector.FromLengthAndAngle(this.Height/2-pieceHeight/2,this.AbsoluteAngle-Angle.RightAngle); //vasen alakulma 26 27 for (int y = 0; y < pieceCountY; y++) 28 { 29 for (int x = 0; x < pieceCountX; x++) 30 { 31 BreakablePhysicsObject childBox = new BreakablePhysicsObject(this.game,pieceWidth, pieceHeight); 32 childBox.Color = RandomGen.NextColor(); 33 childBox.AbsoluteAngle = this.AbsoluteAngle; 34 childBox.AngularVelocity = this.AngularVelocity; 35 36 childBox.Position = this.Position + startCorner 37 + Vector.FromLengthAndAngle(x * pieceWidth, this.AbsoluteAngle) //plus x 38 + Vector.FromLengthAndAngle(y * pieceHeight, this.AbsoluteAngle + Angle.RightAngle); //plus y 39 40 childBox.Velocity = this.Velocity; 41 42 //childBox.Position += offset; 43 44 Game.Add(childBox); 45 } 46 } 47 break; 48 } 13 49 } 14 public BreakablePhysicsObject(double w, double h) : base(w, h) 50 public BreakablePhysicsObject(MikonPeli game,double w, double h) 51 : base(w, h) 15 52 { 16 53 // TODO: Complete member initialization 17 54 game.AddCollisionHandler(game.level, this, delegate { this.Break(0, 2, 2); }); 55 this.game = game; 18 56 } 19 57 } … … 23 61 { 24 62 public Label teksti; 63 public PhysicsObject level; 25 64 26 65 protected override void Draw(Microsoft.Xna.Framework.GameTime gameTime) … … 28 67 if (teksti != null) 29 68 { 30 teksti.Text = (1000 /gameTime.ElapsedGameTime.Milliseconds)+"fps";69 teksti.Text = (1000 / gameTime.ElapsedGameTime.Milliseconds) + "fps"; 31 70 } 32 71 base.Draw(gameTime); 33 72 } 34 void Spawn() { 35 BreakablePhysicsObject boxi = new BreakablePhysicsObject(200.0, 200.0); 73 BreakablePhysicsObject Spawn() 74 { 75 BreakablePhysicsObject boxi = new BreakablePhysicsObject(this,50.0, 50.0); 36 76 Add(boxi); 77 return boxi; 37 78 } 38 public void Reset() { 79 public void Reset() 80 { 39 81 ClearAll(); 40 82 Begin(); … … 47 89 Add(teksti); 48 90 49 Gravity = new Vector(0,-200); 50 Spawn(); 51 Level.CreateBottomBorder(); 91 this.level = Level.CreateBottomBorder(); 92 93 Gravity = new Vector(0, -400); 94 var boxi = Spawn(); 95 boxi.Angle = Angle.FromDegrees(0); 96 boxi.AngularVelocity = 0; 97 52 98 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta Peli"); 53 99 Keyboard.Listen(Key.F4, ButtonState.Down, Reset, "Restart peli"); 100 //boxi.Break(0, 6, 6); 101 Keyboard.Listen(Key.Enter, ButtonState.Pressed, delegate { boxi.Break(0, 9, 9); }, "Riko Boxi"); 54 102 } 55 103 }
Note: See TracChangeset
for help on using the changeset viewer.