コード例 #1
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestMarioOnTopOfBlockCollisionHandling()
        {
            Mario      mario = new Mario(new Vector2(100, 110));
            FloorBlock block = new FloorBlock(new Vector2(100, 100));

            Rectangle marioRect = mario.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            Game1.Side collisionType = Game1.Side.Bottom;
            MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType);

            //Assert.AreEqual(111, mario.location.Y);
        }
コード例 #2
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestMarioOnLeftOfBlockCollisionHandling()
        {
            Mario      mario = new Mario(new Vector2(101, 100));
            FloorBlock block = new FloorBlock(new Vector2(120, 100));

            Rectangle marioRect = mario.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            Game1.Side collisionType = Game1.Side.Right;
            MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType);

            //Assert.AreEqual(102, mario.location.X);
        }
コード例 #3
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestMarioOnTopOfBlockCollisionDetector()
        {
            Mario      mario = new Mario(new Vector2(100, 100));
            FloorBlock block = new FloorBlock(new Vector2(100, 110));

            Rectangle marioRect = mario.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();

            Game1.Side collisionType = generalDetector.DetermineCollision(marioRect, blockRect);

            Assert.AreEqual(collisionType, Game1.Side.Bottom);
        }
コード例 #4
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestEnemyOnLeftOfBlockCollisionDetection()
        {
            Goomba     enemy = new Goomba(new Vector2(100, 100));
            FloorBlock block = new FloorBlock(new Vector2(120, 100));

            Rectangle enemyRect = enemy.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();

            Game1.Side collisionType = generalDetector.DetermineCollision(enemyRect, blockRect);

            Assert.AreEqual(collisionType, Game1.Side.Right);
        }
コード例 #5
0
 public void GetFloorIndex(out int i, out int j, FloorBlock floor)
 {
     for (i = 0; i < floorBlocks.xSize; ++i)
     {
         for (j = 0; j < floorBlocks.ySize; j++)
         {
             if (floorBlocks.GetItem(i, j).Equals(floor))
             {
                 return;
             }
         }
     }
     i = -1; j = -1;
 }
コード例 #6
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestEnemyOnRightOfBlockCollisionHandling()
        {
            IEnemy     enemy       = new Goomba(new Vector2(110, 100));
            Goomba     staticEnemy = new Goomba(new Vector2(100, 100));
            FloorBlock block       = new FloorBlock(new Vector2(100, 100));

            Rectangle enemyRect = enemy.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            Game1.Side collisionType = Game1.Side.Left;
            EnemyBlockCollisionHandler.HandleCollision(enemy, block, collisionType);

            IEnemyState enemyState    = enemy.GetState();
            IEnemyState expectedState = new GoombaLeftMovingState(staticEnemy);

            Assert.AreEqual(enemyState.ToString(), expectedState.ToString());
        }
コード例 #7
0
 public FloorBlockEntity(Vector2 loc)
 {
     Sprite          = new FloorBlock(loc);
     EntityCollision = new BlockCollision(this);
 }
コード例 #8
0
        public void BuildBlocks(string input)
        {
            if (Room.Id == 13)
            {
                buildblocks13(input); return;
            }
            switch (input)
            {
            //BLOCKS

            case "TILE":
                IBlock tile = new FloorBlock(Position);
                Room.blocks.Add(tile);
                break;

            case "BLOK":
                IBlock blok = new RegularBlock(Position);
                Room.blocks.Add(blok);
                break;

            case "RFSH":
                IBlock rfsh = new Face1Block(Position);
                Room.blocks.Add(rfsh);
                break;

            case "LFSH":
                IBlock lfsh = new Face2Block(Position);
                Room.blocks.Add(lfsh);
                break;

            case "SPOT":
                IBlock spot = new SpottedBlock(Position);
                Room.blocks.Add(spot);
                break;

            case "BLCK":
                IBlock blck = new BlackBlock(Position);
                Room.blocks.Add(blck);
                break;

            case "BRIK":
                IBlock brik = new BrickBlock(Position);
                Room.blocks.Add(brik);
                break;

            case "DARK":
                IBlock dark = new DarkBlueBlock(Position);
                Room.blocks.Add(dark);
                break;

            case "STAR":
                IBlock star = new StairsBlock(Position);
                Room.blocks.Add(star);
                break;

            case "STIP":
                IBlock stip = new StripeBlock(Position);
                Room.blocks.Add(stip);
                break;

            case "MVBK":
                IBlock mvbk = new MovingVertBlock(Position);
                Room.blocks.Add(mvbk);
                break;

            case "MLBK":
                IBlock mlbk = new MovingLeftBlock(Position);
                Room.blocks.Add(mlbk);
                break;

            //ENEMIES
            case "BBAT":
                IEntity bat = new BlueBatEnemy(Position);
                Room.enemies.Add(enemyID, bat);
                enemyID++;
                break;

            case "SKLN":
                IEntity skel = new SkeletonEnemy(Position);
                Room.enemies.Add(enemyID, skel);
                enemyID++;
                break;

            case "BOSS":
                IAttack up     = new FireAttack(1);
                IAttack center = new FireAttack(0);
                IAttack down   = new FireAttack(2);
                Room.enemies.Add(enemyID, up);
                enemyID++;
                Room.enemies.Add(enemyID, down);
                enemyID++;
                Room.enemies.Add(enemyID, center);
                enemyID++;
                Room.enemies.Add(enemyID, new FinalBossEnemy(Position, up, center, down));
                enemyID++;
                break;

            case "FIRE":
                IEntity fire = new FireEnemy(Position);
                Room.enemies.Add(enemyID, fire);
                enemyID++;
                break;

            case "GELY":
                IEntity gel = new GelEnemy(Position);
                gel.X = gel.Position.X + FOUR * Global.Var.SCALE;
                gel.Y = gel.Position.Y + FOUR * Global.Var.SCALE;
                Room.enemies.Add(enemyID, gel);
                enemyID++;
                break;

            case "GORY":
                IBoomerang goriyaBoomerang = new BoomerangItem();
                IEntity    goriya          = new GoriyaEnemy(goriyaBoomerang, Position);
                Room.enemyProj.Add(goriyaBoomerang);
                Room.enemies.Add(enemyID, goriya);
                enemyID++;
                break;

            case "HAND":
                IEntity hand = new HandEnemy(Position);
                Room.enemies.Add(enemyID, hand);
                enemyID++;
                break;

            case "OLDM":
                IEntity man = new OldManNPC(Position);
                man.X = man.Position.X + EIGHT * Global.Var.SCALE;
                Room.enemies.Add(enemyID, man);
                enemyID++;
                break;

            case "MNFR":
                IEntity fire1 = new FireEnemy(Position);
                IEntity fire2 = new FireEnemy(Position);
                Room.enemies.Add(enemyID, fire1);
                enemyID++;
                Room.enemies.Add(enemyID, fire2);
                enemyID++;

                IEntity manAndFire = new OldMan_FireEnemy(Position, fire1, fire2);
                manAndFire.X = manAndFire.Position.X + EIGHT * Global.Var.SCALE;
                Room.enemies.Add(enemyID, manAndFire);
                enemyID++;
                break;

            case "SPKE":
                IEntity spike = new SpikeEnemy(Position, spikeNum);
                Room.enemies.Add(enemyID, spike);
                enemyID++;
                spikeNum++;
                if (spikeNum > 4)
                {
                    spikeNum = 1;
                }
                break;


            //ITEMS
            // Probably could use a static bomb and boomerang object now that I think of it.
            case "KEYI":
                IItem key = new KeyItem(Position);
                key.X = key.Position.X + FOUR * Global.Var.SCALE;
                Room.items.Add(key);
                break;

            case "BOWI":
                IItem bow = new BowItem(Position);
                Room.items.Add(bow);
                break;

            case "CLCK":
                IItem clock = new ClockItem(Position);
                Room.items.Add(clock);
                break;

            case "CMPS":
                IItem compass = new CompassItem(Position);
                compass.X = compass.Position.X + TWO * Global.Var.SCALE;
                compass.Y = compass.Position.Y + TWO * Global.Var.SCALE;
                Room.items.Add(compass);
                break;

            case "FARY":
                IItem fairy = new FairyItem(Position);
                Room.items.Add(fairy);
                break;

            case "HCON":
                IItem hcont = new HeartContainerItem(Position);
                hcont.X = hcont.Position.X + ONE * Global.Var.SCALE;
                hcont.Y = hcont.Position.Y + ONE * Global.Var.SCALE;
                Room.items.Add(hcont);
                break;

            case "HART":
                IItem heart = new HeartItem(Position);
                Room.items.Add(heart);
                break;

            case "MAPI":
                IItem map = new MapItem(Position);
                map.X = map.Position.X + FOUR * Global.Var.SCALE;
                Room.items.Add(map);
                break;

            case "RUPE":
                IItem rupee = new RupeeItem(Position);
                Room.items.Add(rupee);
                break;

            case "BOMB":
                IItem bomb = new BombStaticItem(Position);
                Room.items.Add(bomb);
                break;

            case "BMRG":
                IItem boom = new BoomerangStaticItem(Position);
                boom.X = boom.Position.X + BMRG_X_OFFSET * Global.Var.SCALE;
                boom.Y = boom.Position.Y + BMRG_Y_OFFSET * Global.Var.SCALE;
                Room.items.Add(boom);
                break;

            case "BRUP":
                IItem brup = new BlueRupeeItem(Position);
                Room.items.Add(brup);
                break;

            case "TRIF":
                IItem triforce = new TriforceItem(Position);
                triforce.X = triforce.Position.X + ELEVEN * Global.Var.SCALE;
                triforce.Y = triforce.Position.Y + ELEVEN * Global.Var.SCALE;
                Room.items.Add(triforce);
                break;
            }
        }
コード例 #9
0
    public override void OnInspectorGUI()
    {
        //不需要base.OnInspectorGUI ();
        EditorGUILayout.BeginVertical();

        bool oldUpperLayer = voxelMap.isUpperLayer;

        voxelMap.isUpperLayer = EditorGUILayout.Toggle("is up layer:", voxelMap.isUpperLayer);
        if (oldUpperLayer != voxelMap.isUpperLayer)
        {
            //ChangeActiveLayer ();
        }

        EditorGUILayout.BeginHorizontal();
        bool oldDispUpeerLayerGizmo = voxelMap.displayUpperGizmo;

        voxelMap.displayUpperGizmo = EditorGUILayout.Toggle("Switch Gizmo Upper / Lower :", voxelMap.displayUpperGizmo);
        if (oldDispUpeerLayerGizmo != voxelMap.displayUpperGizmo)
        {
            //ChangeActiveLayer ();
        }

        EditorGUILayout.EndHorizontal();

        //如果旧的地图尺寸和新的不同,则进行
        Vector2 oldSize = voxelMap.mapSize;

        voxelMap.mapSize = EditorGUILayout.Vector2Field("Voxel Map Size", voxelMap.mapSize);
        if (oldSize != voxelMap.mapSize)
        {
            UpdateCalculations();
        }

        //如果基准方块被改变则重新建立笔刷
        GameObject oldBasicBlock = voxelMap.basicBlock;

        voxelMap.basicBlock = (GameObject)EditorGUILayout.ObjectField("Basic Object:", voxelMap.basicBlock, typeof(GameObject), false);
        if (oldBasicBlock != voxelMap.basicBlock)
        {
            UpdateCalculations();
            voxelMap.blockID = 0;
            CreateBrush();
        }

        //选择需要加入保存的方块类型
        blockType = (BlockType)EditorGUILayout.EnumPopup("Block Type", blockType);
        //输入对于方块合适的名字
        blockName = (string)EditorGUILayout.TextField("New Blcok Name", blockName);
        if (GUILayout.Button("Add New Blcoksd"))
        {
            //必须命名
            if (blockName != "")
            {
                if (blockType != BlockType.None)
                {
                    switch (blockType)
                    {
                    case BlockType.Floor:
                        FloorBlock floorBlock = new FloorBlock(blockName);
                        //为了防止反序列化时没有数据恢复,需要手动赋值一次
                        floorBlock.BlockType = BlockType.Floor;
                        voxelMap.allBlocks.Add(floorBlock);
                        break;

                    case BlockType.Wall:
                        WallBlock wallBlock = new WallBlock(blockName);
                        wallBlock.BlockType = BlockType.Wall;
                        voxelMap.allBlocks.Add(wallBlock);
                        break;

                    case BlockType.Player:
                        PlayerBlock playerBlock = new PlayerBlock(blockName);
                        playerBlock.BlockType = BlockType.Player;
                        voxelMap.allBlocks.Add(playerBlock);
                        break;

                    case BlockType.Enemy:
                        EnemyBlock enemyBlock = new EnemyBlock(blockName);
                        enemyBlock.BlockType = BlockType.Enemy;
                        voxelMap.allBlocks.Add(enemyBlock);
                        break;

                    case BlockType.Door:
                        DoorBlock doorBlock = new DoorBlock(blockName);
                        doorBlock.BlockType = BlockType.Door;
                        voxelMap.allBlocks.Add(doorBlock);
                        break;
                    }

                    blockType = BlockType.None;
                }
            }
        }



        //保存所有的类型进入对应的数组
        //QuickSort (voxelMap.allBlocks, 0, voxelMap.allBlocks.Count);
        //List<BasicBlock> tmp = new List<BasicBlock> ();
        //tmp [1] = new FloorBlock ("hy");
        //tmp [0] = new
        //QuickSorting.QuickSort ();

        //显示现在保存的方块类型
        for (int i = 0; i < voxelMap.allBlocks.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            voxelMap.allBlocks [i].m_gameobject = (GameObject)EditorGUILayout.ObjectField(voxelMap.allBlocks [i].m_name + " " + voxelMap.allBlocks [i].GetType(), voxelMap.allBlocks [i].m_gameobject, typeof(GameObject), false);
            //删除预设方块
            if (GUILayout.Button("Delete"))
            {
                Debug.Log("Delete" + i + voxelMap.allBlocks [i].m_name);
                voxelMap.allBlocks.Remove(voxelMap.allBlocks [i]);
            }
            EditorGUILayout.EndHorizontal();
        }

        //refresh brush mesh to new brush,
        UpdateBrush(voxelMap.GetBlockBrush.m_gameobject.GetComponentInChildren <MeshFilter> (),
                    voxelMap.GetBlockBrush.m_gameobject.GetComponentInChildren <MeshRenderer> ());
        if (GUILayout.Button("Clear Blocks"))
        {
            if (EditorUtility.DisplayDialog("Clear map's blocks?", "Are you sure?", "Clear", "Do not clear"))
            {
                ClearMap();
            }
        }

        EditorGUILayout.EndVertical();
    }
コード例 #10
0
    public void Init(Vector2 pos, FloorBlock floorPatern, WallBlock wallPatern, PlatformBlock platformPatern, SpriteRenderer background)
    {
        position           = pos;
        backgroundRenderer = Instantiate(background);
        backgroundRenderer.transform.localScale = new Vector2(0.9333f, 0.948f);
        backgroundRenderer.transform.parent     = transform;
        backgroundRenderer.gameObject.SetActive(false);

        int platform, wall, floor;

        platform = wall = floor = 0;
        for (int i = 0; i < patern.GetLength(0); ++i)
        {
            for (int j = 0; j < patern.GetLength(1); ++j)
            {
                switch (patern[i, j])
                {
                // Floor
                case 1:
                    ++floor;
                    break;

                // Wall
                case 2:
                    ++wall;
                    break;

                // Platform
                case 3:
                    ++platform;
                    break;

                // Void
                default:
                    break;
                }
            }
        }

        floorBlock    = new FloorBlock[floor];
        wallBlock     = new WallBlock[wall];
        platformBlock = new PlatformBlock[platform];

        Vector2 newPosition = -BLOCK_POS_MAX;

        for (int i = 0; i < patern.GetLength(0); ++i)
        {
            for (int j = 0; j < patern.GetLength(1); ++j)
            {
                switch (patern[i, j])
                {
                // Floor
                case 1:
                    --floor;
                    floorBlock[floor] = Instantiate(floorPatern);
                    floorBlock[floor].transform.parent   = transform;
                    floorBlock[floor].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    floorBlock[floor].Disable();
                    break;

                // Wall
                case 2:
                    --wall;
                    wallBlock[wall] = Instantiate(wallPatern);
                    wallBlock[wall].transform.parent   = transform;
                    wallBlock[wall].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    wallBlock[wall].Disable();
                    break;

                // Platform
                case 3:
                    --platform;
                    platformBlock[platform] = Instantiate(platformPatern);
                    platformBlock[platform].transform.parent   = transform;
                    platformBlock[platform].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    platformBlock[platform].Disable();
                    break;

                // Void
                default:
                    break;
                }
                newPosition.x += spriteSize;
            }
            newPosition.y -= spriteSize;
            newPosition.x  = -BLOCK_POS_MAX.x;
        }

        transform.Translate(new Vector2(position.x * (BLOCK_POS_MAX.x * 2) + position.x * spriteSize, position.y * (BLOCK_POS_MAX.y * 2) + position.y * spriteSize));
    }