コード例 #1
0
        private void Collision()
        {
            //Check if its out of bounds
            if (!CollisionFuncs.PointAABBcolliding(global.point, GameManager.screenBox))
            {
                //Destroy the bullet
                FreeMemory();
                return;
            }


            //Go through all core objects and check for collision with tanks
            foreach (GameObject obj in GameManager.coreObjects)
            {
                if (obj.tag != "Tank")
                {
                    //We only want to collide with tanks
                    continue;
                }

                //Cast to tank and get AABB
                TankClass tank     = obj as TankClass;
                AABB      tankAABB = CollisionFuncs.OBBtoAABB(tank.collider);

                //Check AABB first, then OBB
                if (CollisionFuncs.PointAABBcolliding(global.point, tankAABB))
                {
                    //If they are colliding, check OBB collision
                    if (CollisionFuncs.PointOBBcolliding(global.point, tank.collider))
                    {
                        tank.Hit();

                        //Enter 'smoke mode' to display an explosion for a short time before destroying itself
                        hasHit = true;
                        image  = rl.Raylib.LoadTexture(GameManager.imageDir + @"Smoke\smokeOrange0.png");
                        //Update image based values
                        imgSize   = new rl.Vector2(image.width, image.height);
                        sourceRec = new rl.Rectangle(0f, 0f, imgSize.x, imgSize.y);
                        origin    = imgSize / 2;

                        return;
                    }
                }
            }
        }
コード例 #2
0
ファイル: TankClass.cs プロジェクト: TheTastyGravy/Tank-Game
        private void Collision()
        {
            //Update collider location and rotation
            UpdateColliderLoc();
            //Rotation matrix of the difference in rotation
            MthLib.Matrix3 rotMatrix = new MthLib.Matrix3();
            rotMatrix.SetRotateZ((local.rotation - global.rotation) * (float)(Math.PI / 180f));
            //Rotate the extents, then put them back in the matrix
            MthLib.Vector3 x = new MthLib.Vector3(collider.m1, collider.m4, 0);
            x           = rotMatrix * x;
            collider.m1 = x.x;
            collider.m4 = x.y;
            MthLib.Vector3 y = new MthLib.Vector3(collider.m2, collider.m5, 0);
            y           = rotMatrix * y;
            collider.m2 = y.x;
            collider.m5 = y.y;


            //Get an AABB for rough collision before using OBB
            AABB aabb = CollisionFuncs.OBBtoAABB(collider);

            //Check if going out of bounds. Because the tank needs to stay inside, just AABB needs to be tested
            if (!CollisionFuncs.AABBwithin(aabb, GameManager.screenBox))
            {
                //Tank is out of bounds; reset transform
                local = global;
                return;
            }

            //Go through all core objects and check for collision with other tanks
            foreach (GameObject obj in GameManager.coreObjects)
            {
                //If it isnt a tank, move on
                if (obj.tag != "Tank")
                {
                    continue;
                }

                TankClass tank = obj as TankClass;
                //If the tank is this tank, move on
                if (tank == this)
                {
                    continue;
                }


                //At this point, the tank must be a different tank, so it can be collided with
                //The collider is OBB, so it needs to be made an AABB
                AABB otherAABB = CollisionFuncs.OBBtoAABB(tank.collider);

                if (CollisionFuncs.AABBcolliding(aabb, otherAABB))
                {
                    //If they are colliding, check OBB collision
                    if (CollisionFuncs.OBBcolliding(collider, tank.collider))
                    {
                        //They are colliding, so reset transform
                        local = global;
                        return;
                    }
                }
            }
        }