source: 2014/27/AleksanteriV/Protokolla236/Protokolla236/Protokolla236/MikonPhysicsObject.cs @ 5257

Revision 5257, 2.9 KB checked in by mijoilmo, 9 years ago (diff)

Image periytyy :)

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class MikonPhysicsObject : PhysicsObject
10{
11    private bool broken = false;
12    private Protokolla236 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                if (pieceWidth < 3 || pieceHeight < 3) { return; }
24                var useCollisions = true;
25                if (pieceWidth < 10 || pieceHeight < 10) { useCollisions = false; }
26                //loop x and y through
27                //calc left corner
28                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
29
30                for (int y = 0; y < pieceCountY; y++)
31                {
32                    for (int x = 0; x < pieceCountX; x++)
33                    {
34                        MikonPhysicsObject childBox = new MikonPhysicsObject(this.game, pieceWidth, pieceHeight);
35                        if (!useCollisions)
36                        {
37                            childBox.CollisionIgnoreGroup = 2;
38                        }
39                        childBox.Color = this.Color;
40                        childBox.Tag = this.Tag;
41                        childBox.Image = this.Image;
42                        childBox.AbsoluteAngle = this.AbsoluteAngle;
43                        childBox.AngularVelocity = this.AngularVelocity;
44
45                        childBox.Position = this.Position + startCorner
46                            + Vector.FromLengthAndAngle(x * pieceWidth, this.AbsoluteAngle) //plus x                                                               
47                            + Vector.FromLengthAndAngle(y * pieceHeight, this.AbsoluteAngle + Angle.RightAngle); //plus y                                         
48
49                        childBox.Velocity = this.Velocity;
50
51                        //childBox.Position += offset;
52
53                        if (RandomGen.NextDouble(0, 1) < 0.2) {
54                            childBox.Break(method,pieceCountX,pieceCountY);
55                        }
56
57                        Game.Add(childBox);
58                    }
59                }
60                break;
61        }
62    }
63    public MikonPhysicsObject(Protokolla236 game, double w, double h)
64        : base(w, h)
65    {
66        // TODO: Complete member initialization
67        //game.AddCollisionHandler(game.level, this, delegate { this.Break(0, 2, 2); });
68        this.game = game;
69    }
70}
Note: See TracBrowser for help on using the repository browser.