Пример #1
0
        /// <summary>
        /// 爆発
        /// </summary>
        public void Explosion()
        {
            //エフェクト用のポジション取得 by長谷川
            effectPosition = new Vector2(position.X - 64, position.Y - 64);

            //アニメーションを開始
            IsAnimation = true;

            //当たり判定変更
            isTrigger = true;
            //当たり判定範囲拡大
            localColRect.Offset(-1, -1);
            localColRect.Width  += 2;
            localColRect.Height += 2;

            //SE
            sound.PlaySE("bomb1");

            //爆発処理
            foreach (var m in map.MapThings)
            {
                if (ColRect.Intersects(m.ColRect))
                {
                    m.EventHandle(this);
                }
            }
        }
Пример #2
0
 public void CheckOhter()
 {
     foreach (var m in map.MapThings)
     {
         if (m is Igniter)
         {
             if (!((Igniter)m).IsToDeath)
             {
                 if (ColRect.Intersects(m.ColRect))
                 {
                     m.EventHandle(this);
                 }
             }
         }
         if (m is Bomb)
         {
             if (!((Bomb)m).IsDead)
             {
                 if (ColRect.Intersects(m.ColRect))
                 {
                     m.EventHandle(this);
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// 四角同士の衝突区域判定
        /// </summary>
        /// <param name="other">判定する対象</param>
        /// <returns></returns>
        public virtual bool CollisionCheck(GameObject other)
        {
            bool flag = false;

            flag = ColRect.Intersects(other.ColRect);
            return(flag);
        }
Пример #4
0
        /// <summary>
        /// 四角同士の衝突区域判定
        /// </summary>
        /// <param name="other">判定する対象</param>
        /// <returns></returns>
        public virtual bool CollisionCheck(GameObject other)
        {
            bool flag = false;//Method.CollisionCheck(position + colOffset, colSize.Width, colSize.Height, other.position + other.colOffset, other.colSize.Width, other.colSize.Height);

            flag = ColRect.Intersects(other.ColRect);
            return(flag);
        }
Пример #5
0
 public override void Notify(float xCurs, float yCurs)
 {
     if (ColRect.Intersect(this.pFont.pFontSprite.pColRect, new ColRect(xCurs, yCurs, 1, 1)))
     {
         // there is a better way
         // do something clever here
         System.Environment.Exit(0);
     }
 }
 override public void Notify(float xCurs, float yCurs)
 {
     if (ColRect.Intersect(this.pFont.pFontSprite.pColRect, new ColRect(xCurs, yCurs, 1, 1)))
     {
         SceneContext.SetState(SceneContext.Scene.HighScore);
         SceneContext.GetState().Initialize();
         SoundMan.PlaySound(Sound.Name.Shoot);
     }
 }
Пример #7
0
 public static bool PointsArrayCollision(Point[] points, ColRect obst,bool fixIt)
 {
     bool col = false;
     for (int i = 0; i != points.Length; i++)
     {
         //========================================================================================Collision from above (-Y)
         if (points[i].y >= obst.y && (points[i].x <= obst.x + obst.w && points[i].x >= obst.x))
         {
             col = true;
             if (fixIt)
             {
                 double pushBack = Math.Abs(points[i].y - obst.y + obst.h);
                 points[i].y -= pushBack;
                 for (int j = 0; j != points.Length; j++)
                 { points[j].y -= pushBack; }
             }
         }
         //========================================================================================Collision from beneath (+Y)
         if (points[i].y<= obst.y + obst.h && (points[i].x <= obst.x + obst.w && points[i].x >= obst.x))
         {
             col = true;
             if (fixIt)
             {
                 double pushBack = Math.Abs(points[i].y - obst.y);
                 points[i].y += pushBack;
                 for (int j = 0; j != points.Length; j++)
                 { points[j].y += pushBack; }
             }
         }
         //========================================================================================Collision from left (-X)
         if (points[i].x <= obst.x + obst.w && (points[i].y <= obst.y + obst.h && points[i].y >= obst.y))
         {
             col = true;
             if (fixIt)
             {
                 double pushBack = Math.Abs(points[i].x - obst.x + obst.w);
                 points[i].y -= pushBack;
                 for (int j = 0; j != points.Length; j++)
                 { points[j].y -= pushBack; }
             }
         }
         //========================================================================================Collision from right (-X)
         if (points[i].y >= obst.x && (points[i].y <= obst.y + obst.h && points[i].y >= obst.y))
         {
             col = true;
             if (fixIt)
             {
                 double pushBack = Math.Abs(points[i].x - obst.x);
                 points[i].y += pushBack;
                 for (int j = 0; j != points.Length; j++)
                 { points[j].y += pushBack; }
             }
         }
     }
     return col;
 }
Пример #8
0
 public void CheckOhterStraw()
 {
     foreach (var m in map.MapThings)
     {
         if (m is Straw)
         {
             if (!((Straw)m).IsToDeath)
             {
                 if (ColRect.Intersects(m.ColRect))
                 {
                     m.EventHandle(this);
                 }
             }
         }
     }
 }
Пример #9
0
        public override void doSubAI()
        {
            refreshColRect();
            getColGrid();

            Point colVectors = new Point();
            short colVectorsCount = 0;

            center.x = x + (w / 2);
            center.y = y + (h / 2);

            colVectors.x = center.x;
            colVectors.y = center.y;

            int xBegin, xEnd, yBegin, yEnd;

            if (x - 16 >= 0)
                xBegin = (int)x - 16;
            else
                xBegin = 0;
            if (x + w + 16 <= RootThingy.sceneX-1)
                xEnd = (int)x + w + 16;
            else
                xEnd = (int)RootThingy.sceneX-1;

            if (y - 16 >= 0)
                yBegin = (int)y - 16;
            else
                yBegin = 0;
            if (y + h + 16 <= RootThingy.sceneY-1)
                yEnd = (int)y + h + 16;
            else
                yEnd = (int)RootThingy.sceneY-1;

            for (int yy = yBegin; yy < yEnd; yy += Map.tileSize)
            {
                for (int xx = xBegin; xx < xEnd; xx += Map.tileSize)
                {
                    Point centerTile = new Point();
                    centerTile.x = (((int)(xx / 16)) * 16) + (Map.tileSize / 2);
                    centerTile.y = (((int)(yy / 16)) * 16) + (Map.tileSize / 2);

                    ColRect crect = new ColRect();
                    crect.x=(int)xx;
                    crect.y=(int)yy;
                    crect.w=16;
                    crect.h=16;

                    MyImage.endDraw2D();
                    GL.Begin(PrimitiveType.LineLoop);
                    GL.Color3(System.Drawing.Color.LimeGreen);
                    GL.Vertex2(crect.x, crect.y);
                    GL.Vertex2(crect.x + crect.w, crect.y);
                    GL.Vertex2(crect.x + crect.w, crect.y + crect.h);
                    GL.Vertex2(crect.x, crect.y + crect.h);
                    GL.End();
                    MyImage.beginDraw2D();

                    //if (Map.map[(int)((yy) / 16), (int)((xx) / 16), 0] == 1 && Collision.col_circleRect(x + (w / 2), y + (w / 2), w / 2, crect))
                    //    {
                    //        double xOff = (crect.x) - (center.x); //
                    //        double yOff = (crect.y) - (center.y); //Distance between Center of circle and center of colliding tile
                    //        colVectors.x += xOff - ((Map.tileSize / 2) + (w / 2));    //
                    //        colVectors.y += yOff - ((Map.tileSize / 2) + (w / 2));    //The actual Distance minus the minimum "not-colliding" distance
                    //        colVectorsCount++;
                    //        MyImage.endDraw2D();
                    //        GL.Begin(PrimitiveType.Lines);
                    //        GL.Color3(System.Drawing.Color.Magenta);
                    //        GL.Vertex2(center.x + xOff, center.y + yOff);
                    //        GL.Vertex2(center.x, center.y); //Kreismitte
                    //        GL.End();
                    //        MyImage.beginDraw2D();
                    //    }

                    if (Map.map[(int)((yy) / 16), (int)((xx) / 16), 0] == 1 &&
                        (
                            (Collision.col_circlePoint(center.x,center.y,(w/2),crect.x,crect.y)) ||
                            (Collision.col_circlePoint(center.x,center.y,(w/2),crect.x + crect.w,crect.y)) ||
                            (Collision.col_circlePoint(center.x,center.y,(w/2),crect.x + crect.w,crect.y + crect.h)) ||
                            (Collision.col_circlePoint(center.x,center.y,(w/2),crect.x,crect.y + crect.h))
                        ))
                    {
                        MyImage.endDraw2D();
                        GL.Begin(PrimitiveType.Lines);
                        GL.Color3(System.Drawing.Color.Magenta);
                        GL.Vertex2(centerTile.x + 8, centerTile.y);
                        GL.Vertex2(centerTile.x, centerTile.y); //Kreismitte
                        GL.End();
                        MyImage.beginDraw2D();
                    }

                }
            }

            colVectors.x = colVectors.x / colVectorsCount*-1;  //Average all collisions
            colVectors.y = colVectors.y / colVectorsCount*-1;  //

            MyImage.endDraw2D();
            GL.Begin(PrimitiveType.Lines);
            GL.Color3(System.Drawing.Color.Aqua);
            GL.Vertex2(colVectors.x + center.x, colVectors.y + center.y);
            GL.Vertex2(center.x, center.y);
            GL.End();
            MyImage.beginDraw2D();

            //if (getColXY((int)x - 1, (int)y + (h / 2)) == 1) //Left wall ?
            //{
            //    dir = false;
            //    xVel = 0;
            //}
            //if (getColXY((int)x + w + 1, (int)y + (h / 2)) == 1)  //Right wall ?
            //{
            //    dir = true;
            //    xVel = 0;
            //}

            //if (getColXY((int)x + (w / 2), (int)y + h + 1) == 1)    //floorCol
            //{
            //    while (colBottom == 1)
            //    {
            //        y--;
            //        refreshColRect();
            //        getColGrid();
            //    }
            //    yVel = 0;
            //    onGround = true;
            //}
            //else
            //{
            //    yVel += Map.gravity;
            //    onGround = false;
            //}

            var keyboard = Keyboard.GetState();
            if (keyboard[Key.J])
            {
                if(xVel>-1.0)
                xVel -= 0.01;
            }
            if (keyboard[Key.L])
            {
                if(xVel<1.0)
                xVel += 0.01;
            }
            if (keyboard[Key.I])
            {
                if (yVel > -1.0)
                    yVel -= 0.01;
            }
            if (keyboard[Key.K])
            {
                if (yVel < 1.0)
                    yVel += 0.01;
            }

            if(!keyboard[Key.J] && !keyboard[Key.L])
            {
                if (xVel < 0)
                { xVel += 0.004; }
                if (xVel > 0)
                { xVel -= 0.004; }
                if (xVel > -0.004 && xVel < 0.004)
                    xVel = 0;
            }

            if (!keyboard[Key.I] && !keyboard[Key.K])
            {
                if (yVel < 0)
                { yVel += 0.004; }
                if (yVel > 0)
                { yVel -= 0.004; }
                if (yVel > -0.004 && yVel < 0.004)
                    yVel = 0;
            }

            angle += (xVel * 180 / ((w / 2) * Math.PI)) *-1;
            while (angle > 360)
                angle -= 360;
            while (angle < 0)
                angle += 360;

            x += xVel;
            y += yVel;
            //if (colVectorsCount > 0)
            //{
            //    x += -colVectors.x;
            //    y += -colVectors.y;
            //}

            if (RootThingy.debugInfo)
            {
                this.texture = Texture.circle32_debug;
                //MyImage.drawText("colVectors.x: " + colVectors.x, (int)x + w + 2, (int)y, System.Drawing.Color.Wheat, Texture.ASCII);
                //MyImage.drawText("colVectors.y: " + colVectors.y, (int)x + w + 2, (int)y + 12, System.Drawing.Color.Wheat, Texture.ASCII);
                MyImage.drawText("colVectorsCount: " + colVectorsCount, (int)x + w + 2, (int)y + 24, System.Drawing.Color.Wheat, Texture.ASCII);
            }
            else
                this.texture = Texture.smw2_rollingRock;
        }
Пример #10
0
 ///////////////////////////////////////////Check if two BaseObj's collide with each other
 public bool getCol2Obj(ColRect obj1, ColRect obj2)
 {
     if ((obj1.x + obj1.w >= obj2.x && obj1.x <= obj2.x + obj2.w) && (obj1.y + obj1.h >= obj2.y && obj1.y <= obj2.y + obj2.h))
         return true;
     else
         return false;
 }