Ejemplo n.º 1
0
    public void Fire()
    {
        Player     player = GameManager.player.GetComponent <Player>();
        RaycastHit hit;

        if (Physics.Raycast(transform.position, directionFacing, out hit) &&
            hit.collider.gameObject.GetComponent <Player>() == player &&
            player.colorPainted == colorVisible &&
            Vector3.Distance(transform.position, player.transform.position) < 5.0f)
        {
            Bullet.MakeBullet(transform.position, directionFacing, damage, 1.0f, gameObject);
        }
        if (Physics.Raycast(transform.position, directionFacing, out hit))
        {
            Robot robot = hit.collider.gameObject.GetComponent <Robot>();
            if (robot != null && robot.colorPainted == colorVisible && Vector3.Distance(transform.position, robot.transform.position) < 5.0f)
            {
                Bullet.MakeBullet(transform.position, directionFacing, damage, 1.0f, gameObject);
            }
        }
        if (Physics.Raycast(transform.position, directionFacing, out hit))
        {
            WallBlock block = hit.collider.gameObject.GetComponent <WallBlock>();
            if (block != null && block.currentColor == colorVisible &&
                Vector3.Distance(transform.position, block.transform.position) < 5.0f)
            {
                Bullet.MakeBullet(transform.position, directionFacing, damage, 1.0f, gameObject);
            }
        }
    }
Ejemplo n.º 2
0
        public void CreateWall(Vector2D position)
        {
            if(!ExistsWallAt(position))
                _walls[position] = new WallBlock();

            _walls[position].Add(new Wall());
        }
Ejemplo n.º 3
0
        private void FormCollisionBall_Load(object sender, EventArgs e)
        {
            engine            = new GameEngine(CreateGraphics(), (int)(Width / 1.25), (int)(Height / 1.25));
            engine.Background = Color.Transparent;
            for (int i = 0; i < 10; i++)
            {
                var rand = new Random(GameUtils.GetRandomSeed());
                var ball = new Ball();
                ball.X  = rand.Next(30, engine.Width - 30);
                ball.Y  = rand.Next(30, engine.Height - 30);
                ball.vx = rand.Next(3, 10);
                ball.vy = rand.Next(3, 10);
                engine.AddGameObject(ball);
            }


            engine.Debug = true;
            engine.CollisionDetectionFunc = (from, to) =>
            {
                if (from is WallBlock && to is WallBlock)
                {
                    return(false);
                }

                var a = isIntersect(from.X, from.Width, to.X, to.Width);
                var b = isIntersect(from.Y, from.Height, to.Y, to.Height);
                if (a && b)
                {
                    return(true);
                }
                return(false);
            };
            var block = new WallBlock();

            block.X      = 0;
            block.Y      = 0;
            block.Width  = engine.Width;
            block.Height = 20;
            engine.AddGameObject(block);
            block        = new WallBlock();
            block.X      = 0;
            block.Y      = engine.Height - 20;
            block.Width  = engine.Width;
            block.Height = 20;
            engine.AddGameObject(block);
            block        = new WallBlock();
            block.X      = engine.Width - 20;
            block.Y      = 20;
            block.Width  = 20;
            block.Height = engine.Height - 40;
            engine.AddGameObject(block);
            block        = new WallBlock();
            block.X      = 0;
            block.Y      = 20;
            block.Width  = 20;
            block.Height = engine.Height - 40;
            engine.AddGameObject(block);
            engine.Run();
        }
Ejemplo n.º 4
0
    // fills floor into blocks array
    private void FillFloor()
    {
        int floorWidth = blocks.GetLength(0) - 1;
        int yPos       = 0;

        for (int x = 0; x <= floorWidth; x++)
        {
            blocks[x, yPos] = new WallBlock(BlockType.Floor);
        }
    }
Ejemplo n.º 5
0
    // fills right wall into blocks array
    private void FillRightWall()
    {
        int wallHeight = blocks.GetLength(1) - 1;
        int xPos       = blocks.GetLength(0) - 1;

        for (int y = 1; y <= wallHeight; y++)
        {
            blocks[xPos, y] = new WallBlock(BlockType.RightWall);
        }
    }
Ejemplo n.º 6
0
    // makes cells occupied by tetramino impassable
    public void FreezeTetraminoArea(TetraminoMono tetraminoMono)
    {
        Tetramino tetramino = tetraminoMono.tetramino;

        Vector2Int[] absPoses = tetramino.AbsPoses;
        LoopUtil.LoopAction((i) =>
        {
            this[absPoses[i]] =
                new WallBlock(BlockType.Unspecified, tetraminoMono.GetChildGameObject(i));
        }
                            , absPoses.Length);
        DisplayBlocks.UpdateBlocks();
    }
Ejemplo n.º 7
0
    private void ExecuteAi()
    {
        if (!aiControlled || wall == null || camera == null)
        {
            return;
        }

        if (currentTarget == null || currentTarget.HasScored() || attemptedShots > maxAttemptedShots)
        {
            List <WallBlock> blocks = wall.GetComponentsInChildren <Transform>()
                                      .Select(c => c.GetComponent <WallBlock>())
                                      .Where(c => c != null)
                                      .Where(c => !c.HasScored())
                                      .ToList();
            int blockCount = blocks.Count;

            if (blockCount == 0)
            {
                marker.Move(Vector2.zero);

                return;
            }

            int i = Random.Range(0, blockCount);

            currentTarget  = blocks[i];
            attemptedShots = 0;
            shooting       = false;
        }

        Vector3 targetScreenPos = camera.WorldToScreenPoint(currentTarget.transform.position)
                                  + 3.0f * new Vector3(0.0f, currentTarget.transform.position.y, 0.0f)
                                  + 1.0f * new Vector3(0.0f, Mathf.Pow(currentTarget.transform.position.y, 2.0f), 0.0f);
        Vector3 markerScreenPos = camera.WorldToScreenPoint(marker.transform.position);
        Vector3 distance        = targetScreenPos - markerScreenPos;
        Vector2 distance2d      = new Vector2(distance.x, distance.y);

        if (distance2d.magnitude > marker.speed + 1.0f)
        {
            marker.Move(distance2d);

            shooting = false;
        }
        else
        {
            marker.Move(Vector2.zero);

            shooting = true;
        }
    }
Ejemplo n.º 8
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == cameFrom)
        {
            return;
        }
        Robot robot = other.gameObject.GetComponent <Robot>();

        if (robot != null)
        {
            robot.SetColorPainted(colorPainted);
        }
        else
        {
            WallBlock block = other.gameObject.GetComponent <WallBlock>();
            if (block != null)
            {
                block.SetColorPainted(colorPainted);
            }
        }
        Destroy(gameObject);
    }
Ejemplo n.º 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();
    }
    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));
    }