Inheritance: MonoBehaviour
示例#1
0
    protected override void oncantmove <T>(T component)
    {
        wall hitwall = component as wall;

        hitwall.damagewall(walldamage);
        animator.ResetTrigger("playerchop");
    }
示例#2
0
    private void SetupWallDirections(int x, int y)
    {
        for (int i = 0; i < 4; i++)
        {
            wall wall = new wall();
            switch (i)
            {
            case UP_INDEX:
                wall.direction = Vector2.up;
                break;

            case RIGHT_INDEX:
                wall.direction = Vector2.right;
                break;

            case DOWN_INDEX:
                wall.direction = Vector2.down;
                break;

            default:
                wall.direction = Vector2.left;
                break;
            }
            if (level[x, y].room.type == Room.RoomTypes.border)
            {
                wall.wallType = wallTypes.closed;
            }
            else
            {
                wall.wallType = wallTypes.empty;
            }
            level[x, y].walls[i] = wall;
        }
    }
示例#3
0
    //----------------------------------------------------------------------------------------------------------------------
    /// @brief Add a wall to our scene
    /// @param _normal the direction we wish for our wall to point in
    /// @param _center the postion we wish for our wall to be
    /// @param _draw a bool for if we want to draw
    /// @param _drawSizeX how big we want to draw our wall in X scale
    /// @param _drawSizeY how big we want to draw our wall in Y scale
    /// @param _drawSizeZ how big we want to draw our wall in Z scale
    public void addWall(Vector3 _normal, Vector3 _center, bool _draw, float _drawSizeX, float _drawSizeY, float _drawSizeZ)
    {
        //render part
        if (m_prefab == null)
        {
            m_prefab = Resources.Load("models/wall") as GameObject;
        }

        GameObject m_go = GameObject.Instantiate(m_prefab, _center, Quaternion.LookRotation(_normal)) as GameObject;

        m_go.name = "Wall" + m_gos.Count;
        m_go.transform.localScale = new Vector3(_drawSizeX, _drawSizeY, _drawSizeZ);
        m_gos.Add(m_go);
        ////////////////////////////////////////////////////////////
        /// collision logical part
        ///
        wall tempWall = new wall();
        tempWall.draw = _draw;
        if (_draw)
        {
            tempWall.drawSizeX = _drawSizeX;
            tempWall.drawSizeY = _drawSizeY;
            tempWall.drawSizeZ = _drawSizeZ;
        }

        tempWall.center = _center;
        tempWall.plane = new Vector4(_normal.x,_normal.y,_normal.z,_center.x*_normal.x + _center.y*_normal.y + _center.z*_normal.z);
        m_walls.Add(tempWall);
    }
    void OnCollisionEnter2D(Collision2D Other)
    {
        Instantiate(Explostion, transform.position, Quaternion.identity);
        if (Other.gameObject.CompareTag("Enemy") && IsThisHero)
        {
            EnemyHealth eh = Other.gameObject.GetComponent <EnemyHealth> ();
            eh.takeDamage(DamageCreated);
        }

        else if (Other.gameObject.CompareTag("Player") && !IsThisHero)
        {
            PlayerHealth ph = Other.gameObject.GetComponent <PlayerHealth> ();
            ph.takeDamage(DamageCreated);
        }

        else if (Other.gameObject.CompareTag("GreenWall") && IsThisHero)
        {
            wall w = Other.gameObject.GetComponent <wall> ();
            w.DestroyWall();
        }
        else if (Other.gameObject.CompareTag("EnemySlug") && IsThisHero)
        {
            EnemySlug eh = Other.gameObject.GetComponent <EnemySlug> ();
            eh.takeDamage(DamageCreated);
        }

        Destroy(gameObject);
    }
示例#5
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if ("Wall".Equals(collision.gameObject.tag))
     {
         m_Wall = collision.gameObject.GetComponent <wall>();
     }
 }
示例#6
0
    void OnServerInitialized()
    {
        SpawnPlayer();
        GameObject get = GameObject.Find("Wall1");
        wall       w   = (wall)get.GetComponent(typeof(wall));

        w.makeBlocks();
    }
示例#7
0
    protected override void OnCanMove <T> (T component)
    {
        wall hitwall = component as wall;

        hitwall.DamageWall(mWallDamage);

        mAnimator.SetTrigger("player_hit");
    }
	// Use this for initialization
	void Start () {
        myWall = gameObject.GetComponent<wall>();

        //if (Input.GetKeyDown(KeyCode.Q))
        //{
        //    Instantiate(WallPrefab);
        //}

    }
示例#9
0
    bool B_DoubleWall(int n)
    {
        wave_name = "shard_double_wall";

        bool there_is_manual = false;

        CreateNormalFloor("doubleWall_veryHard", n);

        float rand_x = Random.Range(-center_mid_area, center_mid_area);
        //spike, located at middle
        int rand = Random.Range(1, 100);

        if (rand < 40)
        {
            game_controller.s.create_spike(rand_x, actual_y, n);
        }
        else if (rand < 65)
        {
            game_controller.s.create_hidden_spike(rand_x, actual_y, n);
        }
        else
        {
            game_controller.s.create_hidden_spike(rand_x, actual_y, n, true);
            there_is_manual = true;
        }

        //second spike, manually triggered located at the opposite corner of the wall
        float rand_x2 = Random.Range(corner_right - 1.3f, corner_right);

        // WALL TWEEN LOGIC
        wall w1 = game_controller.s.create_wall_corner(n, there_is_manual);

        wall w2 = game_controller.s.create_wall_corner(n, false);

        w1.my_twin_wall = w2;
        w2.my_twin_wall = w1;

        w1.wall_trigger           = true;
        w2.wall_triggered_by_wall = true;
        w2.GetComponent <BoxCollider2D>().enabled = false;

        last_spike_right = false;
        last_spike_left  = false;
        last_wall        = true;
        last_hole        = false;
        return(true);
    }
示例#10
0
    void OnCollisionEnter(Collision collision)
    {
        var r = Random.Range(0f, 1f);
        var g = Random.Range(0f, 1f);
        var b = Random.Range(0f, 1f);

        GetComponent <Renderer>().material.color = new Color(r, g, b);
        Debug.Log("hit");

        wall w = collision.gameObject.GetComponent(typeof(wall)) as wall;

        if (w != null)
        {
            w.bullet_hit(1);
        }
        // Destroy(this.gameObject);
    }
示例#11
0
 void Start()
 {
     main = this;
 }
示例#12
0
 public distroyWall(wall wall, int row, int col)
 {
     _wall    = wall;
     this.row = row;
     this.col = col;
 }
    public void Save()
    {
        // 1. Get the SaveName;
        string scenarioName = ScenarioName.text;

        // 2. Get all the existing scenes from gamemanager.
        List <GameObject> AllScenes = null;

        if (gamemanager.name == "DesignSceneGameManager")
        {
            AllScenes = gamemanager.GetComponent <DesignSceneGameManager>().AllScenes;
        }

        // 3. Create a folder named with savename.
        WorkingDirectory = Application.persistentDataPath + "/" + scenarioName;
        // If there already exists a scenario with scenarioName, replace it with the new one. Therefore,
        // users should make sure not to use the same scenario name
        if (Directory.Exists(WorkingDirectory))
        {
            Directory.Delete(WorkingDirectory, true);
        }
        Directory.CreateDirectory(WorkingDirectory);

        // 4. For each scene, do the followings
        foreach (GameObject Scene in AllScenes)
        {
            // 4.1 create a sub-folder with the scenarioName name
            WorkingDirectory = Application.persistentDataPath + "/" + scenarioName + "/" + Scene.name;
            Directory.CreateDirectory(WorkingDirectory);

            // 4.2 create a list to store all the names of the objects
            List <string> AllObjectNames = new List <string>();

            // 4.3 Fill in the class SceneDetails according to the design of the scene
            SceneDetails sceneDetails = new SceneDetails();
            sceneDetails.Walls       = new List <wall>();
            sceneDetails.Floors      = new List <floor>();
            sceneDetails.Ceilings    = new List <ceiling>();
            sceneDetails.Obstacles   = new List <obstacle>();
            sceneDetails.Doors       = new List <door>();
            sceneDetails.Fires       = new List <fire>();
            sceneDetails.Pedestrians = new List <pedestrian>();
            sceneDetails.Players     = new List <player>();
            // 4.3.1 Fill in the simulation info
            sceneDetails.SimTime = Scene.GetComponent <SceneInfo>().SimulationTime;
            sceneDetails.Width   = Scene.GetComponent <SceneInfo>().Width;
            sceneDetails.Length  = Scene.GetComponent <SceneInfo>().Length;
            sceneDetails.Height  = Scene.GetComponent <SceneInfo>().Height;
            sceneDetails.PlayerX = Scene.GetComponent <SceneInfo>().PlayerX;
            sceneDetails.PlayerY = Scene.GetComponent <SceneInfo>().PlayerY;
            // 4.3.2 fill in the info of different objects into sceneDetails
            foreach (Transform ChildObjectTransform in Scene.transform)
            {
                // Wall and its doors
                if (ChildObjectTransform.tag == "Wall")
                {
                    wall WallInfo = new wall();
                    Wall wallinfo = ChildObjectTransform.gameObject.GetComponent <Wall>();
                    AllObjectNames.Add(wallinfo.Name);
                    WallInfo.NameIndex = AllObjectNames.Count - 1;
                    WallInfo.xpos      = wallinfo.x_pos;
                    WallInfo.ypos      = wallinfo.y_pos;
                    WallInfo.zrot      = wallinfo.z_rot;
                    WallInfo.Width     = wallinfo.Width;
                    WallInfo.Height    = wallinfo.Height;
                    WallInfo.Opacity   = wallinfo.Opacity;
                    sceneDetails.Walls.Add(WallInfo);

                    // doors that are attached to it
                    foreach (Transform doorTransform in ChildObjectTransform)
                    {
                        if (doorTransform.tag == "Door")
                        {
                            door DoorInfo = new door();
                            Door doorinfo = doorTransform.gameObject.GetComponent <Door>();
                            AllObjectNames.Add(doorinfo.Name);
                            DoorInfo.NameIndex        = AllObjectNames.Count - 1;
                            DoorInfo.RelativePosition = doorinfo.RelativePosition;
                            DoorInfo.Width            = doorinfo.Width;
                            DoorInfo.Height           = doorinfo.Height;
                            if (doorinfo.Open)
                            {
                                DoorInfo.Open = 1;
                            }
                            else
                            {
                                DoorInfo.Open = 0;
                            }
                            DoorInfo.WallNameIndex = WallInfo.NameIndex;
                            AllObjectNames.Add(doorinfo.NextScene.name);
                            DoorInfo.SceneNameIndex = AllObjectNames.Count - 1;
                            sceneDetails.Doors.Add(DoorInfo);
                        }
                    }
                }
                // Floor
                else if (ChildObjectTransform.tag == "Floor")
                {
                    floor FloorInfo = new floor();
                    Floor floorinfo = ChildObjectTransform.gameObject.GetComponent <Floor>();
                    AllObjectNames.Add(floorinfo.Name);
                    FloorInfo.NameIndex = AllObjectNames.Count - 1;
                    FloorInfo.xpos      = floorinfo.x_pos;
                    FloorInfo.ypos      = floorinfo.y_pos;
                    FloorInfo.Width     = floorinfo.Width;
                    FloorInfo.Length    = floorinfo.Length;
                    sceneDetails.Floors.Add(FloorInfo);
                }
                // Ceiling
                else if (ChildObjectTransform.tag == "Ceiling")
                {
                    ceiling CeilingInfo = new ceiling();
                    Ceiling ceilinginfo = ChildObjectTransform.gameObject.GetComponent <Ceiling>();
                    AllObjectNames.Add(ceilinginfo.Name);
                    CeilingInfo.NameIndex = AllObjectNames.Count - 1;
                    CeilingInfo.xpos      = ceilinginfo.x_pos;
                    CeilingInfo.ypos      = ceilinginfo.y_pos;
                    CeilingInfo.zpos      = ceilinginfo.z_pos;
                    CeilingInfo.Width     = ceilinginfo.Width;
                    CeilingInfo.Length    = ceilinginfo.Length;
                    CeilingInfo.Opacity   = ceilinginfo.Opacity;
                    sceneDetails.Ceilings.Add(CeilingInfo);
                }
                // Obstacle
                else if (ChildObjectTransform.tag == "Obstacle")
                {
                    obstacle ObstacleInfo = new obstacle();
                    Obstacle obstacleinfo = ChildObjectTransform.gameObject.GetComponent <Obstacle>();
                    AllObjectNames.Add(obstacleinfo.Name);
                    ObstacleInfo.NameIndex = AllObjectNames.Count - 1;
                    ObstacleInfo.xpos      = obstacleinfo.x_pos;
                    ObstacleInfo.ypos      = obstacleinfo.y_pos;
                    ObstacleInfo.Width     = obstacleinfo.Width;
                    ObstacleInfo.Length    = obstacleinfo.Length;
                    ObstacleInfo.Height    = obstacleinfo.Height;
                    ObstacleInfo.Opacity   = obstacleinfo.Opacity;
                    sceneDetails.Obstacles.Add(ObstacleInfo);
                }
                // Fire
                else if (ChildObjectTransform.tag == "Fire")
                {
                    fire FireInfo = new fire();
                    Fire fireinfo = ChildObjectTransform.gameObject.GetComponent <Fire>();
                    AllObjectNames.Add(fireinfo.Name);
                    FireInfo.NameIndex  = AllObjectNames.Count - 1;
                    FireInfo.xpos       = fireinfo.x_pos;
                    FireInfo.ypos       = fireinfo.y_pos;
                    FireInfo.zpos       = fireinfo.z_pos;
                    FireInfo.Width      = fireinfo.Width;
                    FireInfo.Length     = fireinfo.Length;
                    FireInfo.HRRPUA     = fireinfo.HRRPUA;
                    FireInfo.CO_YIELD   = fireinfo.CO_YIELD;
                    FireInfo.SOOT_YIELD = fireinfo.SOOT_YIELD;
                    FireInfo.Fuel       = Array.IndexOf(fireinfo.Fuels,
                                                        fireinfo.FUEL);
                    sceneDetails.Fires.Add(FireInfo);
                }
                // Pedestrian
                else if (ChildObjectTransform.tag == "Pedestrian")
                {
                    pedestrian PedestrianInfo = new pedestrian();
                    Pedestrian pedestrianinfo = ChildObjectTransform.gameObject.GetComponent <Pedestrian>();
                    AllObjectNames.Add(pedestrianinfo.Name);
                    PedestrianInfo.NameIndex = AllObjectNames.Count - 1;
                    PedestrianInfo.xpos      = pedestrianinfo.x_pos;
                    PedestrianInfo.ypos      = pedestrianinfo.y_pos;
                    PedestrianInfo.Speed     = pedestrianinfo.Speed;
                    PedestrianInfo.Health    = pedestrianinfo.Health;
                    AllObjectNames.Add(pedestrianinfo.Exit.name);
                    PedestrianInfo.ExitNameIndex = AllObjectNames.Count - 1;
                    sceneDetails.Pedestrians.Add(PedestrianInfo);
                }
                else if (ChildObjectTransform.tag == "Player")
                {
                    player PlayerInfo = new player();
                    Player playerinfo = ChildObjectTransform.gameObject.GetComponent <Player>();
                    AllObjectNames.Add(playerinfo.Name);
                    PlayerInfo.NameIndex = AllObjectNames.Count - 1;
                    PlayerInfo.xpos      = playerinfo.x_pos;
                    PlayerInfo.ypos      = playerinfo.y_pos;
                    PlayerInfo.Speed     = playerinfo.Speed;
                    PlayerInfo.Health    = playerinfo.Health;
                    sceneDetails.Players.Add(PlayerInfo);
                }
            }

            // 4.4 Save AllObjectNames into a text file
            StreamWriter NamesTxtFile = new StreamWriter(WorkingDirectory + "/AllNames.txt");
            foreach (string name in AllObjectNames)
            {
                NamesTxtFile.WriteLine(name);
            }
            NamesTxtFile.Close();

            // 4.5 Save sceneDetails into a binary file, SceneDetails.dat
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.OpenOrCreate);
            bf.Serialize(file, sceneDetails);
            file.Close();
        }
    }
示例#14
0
 void makemaze()
 {
     for (int x = 0; x < 31; x++)
     {
         for (int y = 0; y < 31; y++)
         {
             if (y % 2 == 1)
             {
                 map[x, y] = false;
                 if (x % 2 == 0)
                 {
                     walls.Add(new wall(x, y - 1, x, y + 1, x, y));
                 }
             }
             else
             {
                 if (x % 2 == 0)
                 {
                     map[x, y] = true;
                 }
                 else
                 {
                     map[x, y] = false;
                     walls.Add(new wall(x - 1, y, x + 1, y, x, y));
                 }
             }
             fa[x, y] = new Vector2Int(x, y);
         }
     }
     System.Random rnd = new System.Random();
     for (int i = 0; i < walls.Count; i++)
     {
         int  a = rnd.Next(walls.Count - 1), b = rnd.Next(a + 1, walls.Count);
         wall c = walls[a]; walls[a] = walls[b]; walls[b] = c;
     }
     for (int i = 0; i < walls.Count; i++)
     {
         Vector2Int a = find(walls[i].x1, walls[i].y1);
         Vector2Int b = find(walls[i].x2, walls[i].y2);
         if (!a.Equals(b))
         {
             map[walls[i].x, walls[i].y] = true;
             fa[a.x, a.y] = b;
         }
         else
         {
             continue;
         }
         if (find(0, 0).Equals(find(30, 30)))
         {
             break;
         }
     }
     for (int x = 0; x < 31; x++)
     {
         for (int y = 0; y < 31; y++)
         {
             if (!map[x, y])
             {
                 GameObject go = Instantiate(zhu);
                 go.transform.position = new Vector3(x, 0.5f, y);
             }
         }
     }
     while (true)
     {
         int a = rnd.Next(30);
         int b = rnd.Next(30);
         if (find(0, 0).Equals(find(0, 0)))
         {
             GameObject go = Instantiate(Empty);
             go.transform.position = new Vector3(a, 0, b);
             break;
         }
     }
 }