1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | class MikonParticle : GameObject |
---|
10 | { |
---|
11 | private Protokolla236 parent; |
---|
12 | private Vector velocity; |
---|
13 | public Vector Velocity { get { return velocity; } set { velocity = value; } } |
---|
14 | private double mass; |
---|
15 | public double Mass { get { return mass; } set { mass = value; } } |
---|
16 | public override void Update(Time time) |
---|
17 | { |
---|
18 | this.Position += this.velocity / this.mass / 40; |
---|
19 | if (this.parent.Level.Left > this.Position.X || this.parent.Level.Right < this.Position.X) { |
---|
20 | this.Destroy(); |
---|
21 | } |
---|
22 | if (this.parent.Level.Bottom > this.Position.Y || this.parent.Level.Top < this.Position.Y) { |
---|
23 | this.Destroy(); |
---|
24 | } |
---|
25 | base.Update(time); |
---|
26 | } |
---|
27 | public MikonParticle(Protokolla236 parent,double w, double h) |
---|
28 | : base(w, h) |
---|
29 | { |
---|
30 | this.parent = parent; |
---|
31 | this.IsUpdated = true; |
---|
32 | } |
---|
33 | } |
---|
34 | public class MikonPhysicsObject : PhysicsObject |
---|
35 | { |
---|
36 | private bool broken = false; |
---|
37 | private Protokolla236 game; |
---|
38 | public void Break(int method, int pieceCountX = 2, int pieceCountY = 2) |
---|
39 | { |
---|
40 | if (this.broken) { return; } |
---|
41 | this.Destroy(); |
---|
42 | this.broken = true; |
---|
43 | switch (method) |
---|
44 | { |
---|
45 | case 0://uniform break |
---|
46 | var pieceWidth = this.Width / pieceCountX; |
---|
47 | var pieceHeight = this.Height / pieceCountY; |
---|
48 | if (pieceWidth < 1 || pieceHeight < 1) { return; } |
---|
49 | var cheap = false; |
---|
50 | if (pieceWidth < 10 || pieceHeight < 10) { cheap = true; } |
---|
51 | //loop x and y through |
---|
52 | //calc left corner |
---|
53 | 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 |
---|
54 | |
---|
55 | for (int y = 0; y < pieceCountY; y++) |
---|
56 | { |
---|
57 | for (int x = 0; x < pieceCountX; x++) |
---|
58 | { |
---|
59 | int w = this.Image.Width / pieceCountX, h = this.Image.Height / pieceCountY; |
---|
60 | var imageArea = this.Image.Area( |
---|
61 | w * x, |
---|
62 | h * (pieceCountY - y - 1), |
---|
63 | w * (x + 1), |
---|
64 | h * ((pieceCountY - y - 1) + 1) |
---|
65 | ); |
---|
66 | if (!cheap) |
---|
67 | { |
---|
68 | MikonPhysicsObject childBox = new MikonPhysicsObject(this.game, pieceWidth, pieceHeight); |
---|
69 | childBox.Tag = this.Tag; |
---|
70 | childBox.IgnoresGravity = this.IgnoresGravity; |
---|
71 | childBox.Image = imageArea; |
---|
72 | |
---|
73 | childBox.AbsoluteAngle = this.AbsoluteAngle; |
---|
74 | childBox.AngularVelocity = this.AngularVelocity; |
---|
75 | |
---|
76 | childBox.Position = this.Position + startCorner |
---|
77 | + Vector.FromLengthAndAngle(x * pieceWidth, this.AbsoluteAngle) //plus x |
---|
78 | + Vector.FromLengthAndAngle(y * pieceHeight, this.AbsoluteAngle + Angle.RightAngle); //plus y |
---|
79 | |
---|
80 | childBox.Velocity = this.Velocity; |
---|
81 | |
---|
82 | //childBox.Position += offset; |
---|
83 | |
---|
84 | //if (RandomGen.NextDouble(0, 1) < 0.2) |
---|
85 | //{ |
---|
86 | // childBox.Break(method, pieceCountX, pieceCountY); |
---|
87 | //} |
---|
88 | |
---|
89 | Game.Add(childBox); |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | MikonParticle childBox = new MikonParticle(this.game,pieceWidth, pieceHeight); |
---|
94 | childBox.Tag = this.Tag; |
---|
95 | //childBox.IgnoresGravity = this.IgnoresGravity; |
---|
96 | childBox.Image = imageArea; |
---|
97 | childBox.Mass = this.Mass; |
---|
98 | |
---|
99 | childBox.AbsoluteAngle = this.AbsoluteAngle; |
---|
100 | //childBox.AngularVelocity = this.AngularVelocity; |
---|
101 | |
---|
102 | childBox.Position = this.Position + startCorner |
---|
103 | + Vector.FromLengthAndAngle(x * pieceWidth, this.AbsoluteAngle) //plus x |
---|
104 | + Vector.FromLengthAndAngle(y * pieceHeight, this.AbsoluteAngle + Angle.RightAngle); //plus y |
---|
105 | |
---|
106 | childBox.Velocity = this.Velocity; |
---|
107 | |
---|
108 | //if (RandomGen.NextDouble(0, 1) < 0.2) |
---|
109 | //{ |
---|
110 | // childBox.Break(method, pieceCountX, pieceCountY); |
---|
111 | //} |
---|
112 | |
---|
113 | Game.Add(childBox); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | break; |
---|
118 | } |
---|
119 | } |
---|
120 | public MikonPhysicsObject(Protokolla236 game, double w, double h) |
---|
121 | : base(w, h) |
---|
122 | { |
---|
123 | // TODO: Complete member initialization |
---|
124 | //game.AddCollisionHandler(game.level, this, delegate { this.Break(0, 2, 2); }); |
---|
125 | this.game = game; |
---|
126 | } |
---|
127 | } |
---|