示例#1
0
文件: Level.cs 项目: xstos/alithiatec
        public Level(Game parent, string[][] data)
        {
            Game  = parent;
            World = new World(this);
            buildHpColors();
            this.data = data;
            float pwid, ph; int nrows, ncols;

            Width        = 1.0F;
            Height       = 0.625F;
            nrows        = data.Length;
            ncols        = data[0].Length;
            BrickWidth   = Width / (float)ncols;           //100%
            BrickHeight  = Height / (float)nrows;          //100%
            pwid         = Width * 0.1F; ph = Height * 0.15F;
            Paddle       = Mesh2D.Paddle(new P3(-pwid / 2F, -ph / 2.0F, 0), pwid, ph, new P3(Width / 2.0F, Height - ph / 2F, 0), 0.98f);
            Paddle.Color = Color.Blue;
            CreatePaddle(Paddle);
            World.AddMesh("paddles", Paddle);
            PaddleStop = BrickWidth + pwid / 2F;
            World.Meshes.Add("vectors", new List <Mesh2D>());
            P3 ballStart = new P3(Width / 2F, Height - BrickHeight, 0);
            V3 vel       = new V3(new P3((float)r.NextDouble() * Width, Height / 2F, 0), ballStart);       //set random init direction

            vel.Magnitude = 1.0F;
            Ball          = Mesh2D.Ball(Width / 200.0F, ballStart, vel);
            CreateBall(Ball);
            World.AddMesh("balls", Ball);
            string type;
            Mesh2D m;

            for (int i = 0; i < data.Length; i++)
            {
                for (int j = 0; j < data[i].Length; j++)
                {
                    m    = Mesh2D.Rectangle(P3.Zero, BrickWidth, BrickHeight, P3.New(BrickWidth * j, BrickHeight * i));
                    type = data[i][j];
                    if (type == "W")
                    {
                        CreateWall(m);
                        World.AddMesh("walls", m);
                        continue;
                    }
                    int hp = int.Parse(type);
                    if (hp == 0)
                    {
                        continue;
                    }
                    CreateBrick(m, hp);
                    BricksLeft++;
                    World.AddMesh("bricks", m);
                }
            }
        }
示例#2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Edge e  = new Edge(P3.New(0, 0), P3.New(0, -1));
            Edge e2 = new Edge(P3.New(0, -1), P3.New(0, 0));
            V3   v  = new V3(1, 1, 0);
            V3   v2 = new V3(0.5F, 0, 0);
            V3   v3 = new V3(0, 1, 0);

            v3.RotateBy2D(-0.78f);
            v3.RotateBy2D(0.78f * 2);
            float d = v.ProjectionDistance(v2);
            Dictionary <Edge, int> dic = new Dictionary <Edge, int>();
            //dic.Add(e, 0);
            //dic.Add(e2, 0);
            V3 n  = e.GetNormal2DRightHanded();
            V3 n2 = e2.GetNormal2DRightHanded();
            P3 p;

            Application.Run(new Form1());
        }
示例#3
0
        //1w to 0.625h

        /// <returns>true if a collision occured</returns>
        public void ResolveCollisions2(float deltaTimeInSec, bool moveNext)
        {
            List <Mesh2D> obstacles = new List <Mesh2D>();
            List <Mesh2D> collideable;

            obstacles.AddRange(Meshes["bricks"]);
            obstacles.AddRange(Meshes["walls"]);
            obstacles.AddRange(Meshes["paddles"]);
            Mesh2D next; Mesh2D projectile;

            for (int i = 0; i < Meshes["balls"].Count; i++)
            {
                projectile = Meshes["balls"][i];
                next       = projectile.Clone();
                next.MoveNext(deltaTimeInSec);                 //AddVec(next.Trajectory(), Color.Blue);
                collideable = GetCollideable(next, obstacles); //find hittable meshes
                if (collideable.Count > 0)
                {
                    List <Mesh2D> collided = GetCollidedMeshes(next, collideable);
                    if (collided.Count > 0)
                    {
                        float d;
                        Edge  closest = GetCollisionEdge(next, projectile, collided, out d);
                        if (closest != null)
                        {
                            projectile.DeflectAgainst(closest.GetNormal2DRightHanded().UnitVector);
                            if (closest.Parent.Attributes.Get <string>("name") == "brick")
                            {
                                int hp = closest.Parent.Attributes.Get <int>("hitpoints");
                                Level.Game.Score += 100 * hp;
                                hp--;
                                if (hp == 0)
                                {
                                    closest.Parent.Position = P3.New(2, 2);
                                }
                                closest.Parent.Attributes["hitpoints"] = hp;
                                Level.Game.Sound.PlaySFX("brickhit");
                                Level.BricksLeft--;
                                if (Level.BricksLeft == 0)
                                {
                                    Level.Game.NextLevel();
                                }
                            }
                            else if (closest.Parent.Attributes.Get <string>("name") == "wall" || closest.Parent.Attributes.Get <string>("name") == "paddle")
                            {
                                Level.Game.Sound.PlaySFX("wallhit");
                            }
                        }
                        else
                        {
                            if (moveNext)
                            {
                                projectile.MoveNext(deltaTimeInSec);
                            }
                        }
                    }
                    else                         //collided.count==0
                    {
                        if (moveNext)
                        {
                            projectile.MoveNext(deltaTimeInSec);
                        }
                    }
                }
                else                     //if collideable.count==0
                {
                    if (moveNext)
                    {
                        projectile.MoveNext(deltaTimeInSec);
                    }
                }
            }
        }