コード例 #1
0
 public TerrainCell(TypeTerrain typeTerrain)
 {
     type       = typeTerrain;
     route      = false;
     villeIndex = -1;
     ruineIndex = -1;
 }
コード例 #2
0
        public void IsOnGround(TypeTerrain typeTerrain, Terrain terrain)
        {
            switch (typeTerrain)
            {
            case TypeTerrain.ground:
                if (this._location.Y == terrain.Location.Y)
                {
                    _onGround = true;
                }
                else
                {
                    _onGround = false;
                }
                break;

            case TypeTerrain.roof:
                _onGround = false;
                break;

            case TypeTerrain.wall:
                _onGround = false;
                break;

            case TypeTerrain.plateform:
                _onGround = false;
                break;
            }
        }
コード例 #3
0
    public static IntRect ConvertirIndiceTileset(TypeTerrain tt)
    {
        IntRect rect;

        //on cast la signification du terrain pour l'utiliser comme un int
        int indice = (int)tt;

        //les sprites du tileset font tous 128px de hauteur et largeur
        rect.Width = rect.Height = 128;

        //On initialise Top et Left avant de s'en servir pour trouver la bonne image dans le tileset
        rect.Top = rect.Left = 0;

        /*
         * Le tileset est formé de ligne de 3 sprites.
         * A chaque fois qu'on dépasse la valeur "3", on change de ligne, on incrémente donc rect.Top.
         * On oublie pas de soustraire a l'indice les 3 valeurs et on reverifie jusqu'a ce qu'on soit sur la bonne ligne.
         * Le reste des soustraction permet de savoir le bon indice sur rect.Width
         */
        while (indice >= 3)
        {
            indice   -= 3;
            rect.Top += 128;
        }

        //On applique le reste de la somme sur rect.Left.
        rect.Left = indice * 128;

        return(rect);
    }
コード例 #4
0
    public static GameObject generateObject(string objectName, string spriteName, TypeTerrain tTerrain = null, componentMapObject parent = null, Dictionary<string, List<NotifyBehaviorMapObject>> notifyBehaviors = null, Notifier notify = null)
    {
        GameObject playerObject = new GameObject(objectName);

        attachNewComponent(playerObject, spriteName, tTerrain, parent, notifyBehaviors, notify);

        return playerObject;
    }
コード例 #5
0
    public static GameObject generateObject(string objectName, string spriteName = null, TypeTerrain tTerrain = null, componentMapObject parent = null, Dictionary<string, List<NotifyBehaviorMapObject>> notifyBehaviors = null, Notifier notify = null)
    {
        GameObject tileObject = new GameObject(objectName);

        componentMapObject cTile = tileObject.AddComponent<componentTile>();
        initializeComponent(cTile, spriteName, tTerrain, parent, notifyBehaviors, notify);

        return tileObject;
    }
コード例 #6
0
ファイル: Acre.cs プロジェクト: jeepee12/Simville
 /// <summary>
 /// constructeur de la classe Acre
 /// </summary>
 public Acre()
 {
     this.terrain = TypeTerrain.Champ;
     this.sante = 0;
     this.criminalite = 0;
     this.loisirs = 0;
     this.satisfaction = 0;
     this.nbHabitant = 0;
 }
コード例 #7
0
    /// <summary>
    /// Creates a new unit's GameObject and attaches appropriate components.
    /// </summary>
    /// <param name="unitName">The Unit's name (Not the game object's name). If this is null it will get it from the stat template</param>
    /// <param name="stats">The stat template</param>
    /// <param name="owner">This will need to change, it is unused at the current moment.</param>
    /// <param name="objectName">The GameObject's name</param>
    /// <param name="spriteName">The sprite's name</param>
    /// <param name="tTerrain">The typeTerrain of the unit (Typically this should be unpassable... because it's a unit)</param>
    /// <param name="mapObjectParent">The map object's parent object</param>
    /// <returns>The newly created GameObject with attached components</returns>
    public static GameObject createUnit(string unitName, IUnitStatTemplate stats, int owner, string objectName, string spriteName, TypeTerrain tTerrain = null, componentMapObject mapObjectParent = null)
    {
        //TODO: Change owner to a pointer to a player or controller data structure. not enitrely sure how I want to handle that yet.
        GameObject objUnit = new GameObject(objectName);

        componentUnitMapObject.attachNewComponent(objUnit, spriteName, tTerrain, mapObjectParent);
        componentUnit.attachNewComponent(objUnit, unitName, stats, owner);

        return objUnit;
    }
コード例 #8
0
    public Terrain(TypeTerrain type)
    {
        m_type               = type;
        m_couleur            = Couleur.AUCUNE;
        m_maison             = new Sprite(RessourceGraphique.Instance.TilesetMaison);
        m_maison.TextureRect = new IntRect((int)m_couleur * 64, 0, 64, 64);

        this.Texture     = RessourceGraphique.Instance.TilesetTerrain;
        this.TextureRect = RessourceGraphique.ConvertirIndiceTileset(type);
    }
コード例 #9
0
    /**
     *	fonction IsNear:
     *	determine si un terrain de type t
     *	se trouve à côté d'une coordonnée _case
     */
    public static bool IsNear(Plateau d, Tuple <Coordonnee, Terrain> _case, TypeTerrain t)
    {
        List <Coordonnee> voisins = d.Adjacent(_case.Item1);

        foreach (Coordonnee voisin in voisins)
        {
            if (d[voisin].Type == t)
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #10
0
ファイル: Joueur.cs プロジェクト: mlengagne/kingdombuilder
    protected Joueur(Couleur couleur)
    {
        if (rnd1 == null)
        {
            rnd1 = new Random();
        }

        m_listeBonus     = new List <TypeTerrain>();
        m_maisonsPlacees = new List <Coordonnee>();
        m_carteTerrain   = Piocher();
        m_couleur        = couleur;
        m_score          = 0;
        m_nbMaisons      = 20;
    }
コード例 #11
0
ファイル: Joueur.cs プロジェクト: mlengagne/kingdombuilder
 public void RecupererBonus(Plateau plateau)
 {
     foreach (KeyValuePair <Coordonnee, Terrain> terrain in plateau)
     {
         if (terrain.Value.Couleur == m_couleur)
         {
             TypeTerrain bonus = plateau.RecupererBonus(plateau.Adjacent(terrain.Key));
             if (bonus != TypeTerrain.AUCUN && !m_listeBonus.Contains(bonus))
             {
                 m_listeBonus.Add(bonus);
             }
         }
     }
 }
コード例 #12
0
 private static void initializeComponent(componentMapObject cTile, string spriteName, TypeTerrain tTerrain = null, componentMapObject parent = null, Dictionary<string, List<NotifyBehaviorMapObject>> notifyBehaviors = null, Notifier notify = null)
 {
     cTile.setParent(parent);
     cTile.setSprite(spriteName);
     cTile.setTypeTerrain(tTerrain);
     cTile.setRenderSortingLayer(RENDER_SORTING_LAYER);
     cTile.init();
     if(notifyBehaviors != null)
     {
         foreach(string key in notifyBehaviors.Keys)
         {
             foreach(NotifyBehaviorMapObject behavior in notifyBehaviors[key])
             {
                 cTile.addNotifyBehavior(key, new NotifyBehaviorMapObject(behavior));
             }
         }
     }
     cTile.setNotifier(notify);
 }
コード例 #13
0
ファイル: BoiteInfo.cs プロジェクト: mlengagne/kingdombuilder
    public void ModifierTextes(Couleur couleur, TypeTerrain type, Int16 nbMaisons)
    {
        m_infoJoueur.DisplayedString = "Joueur " + couleur.ToString();
        m_infoJoueur.Color           = RecupererCouleur(couleur);

        m_infoTerrain.DisplayedString = "Terrain " + type.ToString();
        m_infoTerrain.Color           = RecupererCouleur(couleur);

        m_infoMaison.DisplayedString = "Maison x" + nbMaisons.ToString();
        m_infoMaison.Color           = RecupererCouleur(couleur);

        if (couleur == Couleur.NOIR)
        {
            m_boite.FillColor = new Color(0, 0, 0, 0);
        }
        else
        {
            m_boite.FillColor = new Color(0, 0, 0, 200);
        }
    }
コード例 #14
0
    public static GameObject attachNewComponent(GameObject attachingTo, string spriteName, TypeTerrain tTerrain = null, componentMapObject parent = null, Dictionary<string, List<NotifyBehaviorMapObject>> notifyBehaviors = null, Notifier notify = null)
    {
        componentMapObject cMapObject = attachingTo.AddComponent<componentUnitMapObject>();
        cMapObject.setParent(parent);
        cMapObject.setSprite(spriteName);
        cMapObject.setTypeTerrain(tTerrain);
        cMapObject.setRenderSortingLayer("gamePieces");
        cMapObject.init();
        if (notifyBehaviors != null)
        {
            foreach (string key in notifyBehaviors.Keys)
            {
                foreach (NotifyBehaviorMapObject behavior in notifyBehaviors[key])
                {
                    cMapObject.addNotifyBehavior(key, new NotifyBehaviorMapObject(behavior));
                }
            }
        }
        cMapObject.setNotifier(notify);

        return attachingTo;
    }
コード例 #15
0
ファイル: Terrain.cs プロジェクト: soleil2010/Game2D
        /// <summary>
        /// Construct the object Terrain
        /// Ein terrain Ein Type
        /// </summary>
        /// <param name="ground"></param>
        /// <param name="roof"></param>
        /// <param name="wall"></param>
        /// <param name="platform"></param>
        public Terrain(TypeTerrain typeTerrain)
        {
            switch (typeTerrain)
            {
            case TypeTerrain.ground:
                this._ground = true;
                break;

            case TypeTerrain.roof:
                this._roof = true;
                break;

            case TypeTerrain.wall:
                this._wall = true;
                break;

            case TypeTerrain.plateform:
                this._plateform = true;
                break;
            }

            this._location = new Location();
        }
コード例 #16
0
    public static GameObject generateObject(string objectName, string spriteName, TypeTerrain tTerrain = null, componentMapObject parent = null, Dictionary<string, List<NotifyBehaviorMapObject>> notifyBehaviors = null, Notifier notify = null)
    {
        GameObject tileObject = new GameObject(objectName);

        componentMapObject cMapObject = tileObject.AddComponent<componentTestObject>();
        cMapObject.setParent(parent);
        cMapObject.setSprite(spriteName);
        cMapObject.setTypeTerrain(tTerrain);
        cMapObject.setRenderSortingLayer("gameAbovePieces");
        cMapObject.init();
        if (notifyBehaviors != null)
        {
            foreach (string key in notifyBehaviors.Keys)
            {
                foreach (NotifyBehaviorMapObject behavior in notifyBehaviors[key])
                {
                    cMapObject.addNotifyBehavior(key, new NotifyBehaviorMapObject(behavior));
                }
            }
        }
        cMapObject.setNotifier(notify);

        return tileObject;
    }
コード例 #17
0
    //Returns a success code (0) or an error code (>= 1)
    private int LoadLevel()
    {
        if(_map != null) //Add any uninitialization here, or maybe even repurposing.
        {
            GameObject tempMap = _map.gameObject;   //Utilizing a temp to make sure the memory clears properly. If it ever becomes an issue make this better.
            _map = null;
            _objMap = null;
            GameObject.Destroy(tempMap);
        }

        _objMap = new GameObject("Game Map");
        _map = _objMap.AddComponent<componentGameMap>();

        if(_notifier != null) //Make a new notifier for each game.
        {
            _notifier = null;
        }

        _notifier = new Notifier();

        //Load these from the file once it's created
        TextAsset txtAsset = (TextAsset)Resources.Load("Maps/testMap");

            //Eventually add a validator to the XML to determine whether or not to pass or fail before starting.
        XDocument xmlMap = XDocument.Parse(txtAsset.text);

        Debug.Log("Map Name : " + (string)xmlMap.Root.Attribute("name"));

        XElement xmlPalette = xmlMap.Root.Element("Palette");

        Dictionary<string, TypeTerrain> terrains = new Dictionary<string, TypeTerrain>();
        IEnumerable<XElement> xmlTerrainList = xmlPalette.Elements("Terrain");
        foreach (XElement xmlTerrain in xmlTerrainList)
        {
            string terrainName = (string)xmlTerrain.Attribute("name");
            TypeTerrain terrain = new TypeTerrain(terrainName);

            IEnumerable<XElement> xmlTerrainRequirementList = xmlTerrain.Elements("Requirement");
            //Terrain Pass Requirements
            foreach (XElement xmlTerrainRequirement in xmlTerrainRequirementList)
            {
                TerrainPassRequirement terrainPassRequirement = new TerrainPassRequirement();
                //Terrain Individual Pass Requirement
                IEnumerable<XElement> xmlTerrainPassRequirements = xmlTerrainRequirement.Elements("Type");
                foreach (XElement xmlTerrainPassRequirement in xmlTerrainPassRequirements)
                {
                    terrainPassRequirement.addRequirement((string)xmlTerrainPassRequirement.Attribute("name"), (bool)xmlTerrainPassRequirement.Attribute("required"));
                }
                terrain.addPassRequirement(terrainPassRequirement);
            }
            terrains.Add(terrainName, terrain);
        }

        Dictionary<string, componentTile> tiles = new Dictionary<string, componentTile>();  //ShortName is the key
        tiles.Add("0", componentTile.generateObject("EmptyTileTemplate").GetComponent<componentTile>());
        IEnumerable<XElement> xmlTileList = xmlPalette.Elements("Tile");
        foreach (XElement xmlTile in xmlTileList)
        {
            //Attributes
            string tileName = (string)xmlTile.Attribute("name");
            string tileShortName = (string)xmlTile.Attribute("shortName");
            string tileTerrainTypeName = (string)xmlTile.Attribute("terrain");
            TypeTerrain tileTerrainType = (tileTerrainTypeName == null)?(null):(terrains[tileTerrainTypeName]);
            string tileParentShortName = (string)xmlTile.Attribute("parent");
            componentMapObject tileParent = (tileParentShortName == null)?(null):((componentTile)tiles[tileParentShortName]);

            //Elements
            string tileSpriteName = (string)xmlTile.Element("Sprite");

            //TODO: Load Tile Behavior

            componentTile cTile = componentTile.generateObject(tileName, tileSpriteName, tileTerrainType, tileParent).GetComponent<componentTile>();

            //Load Collider
            XElement xmlCollider = xmlTile.Element("Collider");
            if (xmlCollider != null)
            {
                string colliderType = (string)xmlCollider.Attribute("type");
                switch(colliderType)
                {
                    case "box":
                        XElement xmlColliderWidth = xmlCollider.Element("Width");
                        bool scaleRelativeWidth = ((string)(xmlColliderWidth.Attribute("scale"))).ToUpper().Equals("RELATIVE");
                        float colliderWidthBase = (float)xmlColliderWidth;
                        float colliderWidth = colliderWidthBase;
                        if(scaleRelativeWidth == true)
                        {
                            colliderWidth = cTile.getSpriteRenderer().bounds.size.x * colliderWidthBase;
                        }

                        XElement xmlColliderHeight = xmlCollider.Element("Height");
                        bool scaleRelativeHeight = ((string)(xmlColliderHeight.Attribute("scale"))).ToUpper().Equals("RELATIVE");
                        float colliderHeightBase = (float)xmlColliderHeight;
                        float colliderHeight = colliderHeightBase;
                        if(scaleRelativeHeight == true)
                        {
                            colliderHeight = cTile.getSpriteRenderer().bounds.size.y * colliderHeightBase;
                        }

                        bool isTrigger = (bool)xmlCollider.Attribute("isTrigger");

                        BoxCollider2D boxCollider = cTile.gameObject.AddComponent<BoxCollider2D>();
                        boxCollider.isTrigger = isTrigger;
                        boxCollider.size = new Vector2(colliderWidth, colliderHeight);
                        break;
                    case "circle":
                        break;
                    default:
                        Debug.Log("Unknown Collider Type : " + colliderType);
                        break;
                }
                /*
                    <Collider type="box" isTrigger="false">
                        <width scale="relative">1</width>
                        <height scale="relative">1</height>
                    </Collider>
                 */
            }
            cTile.gameObject.SetActive(false);

            tiles.Add(tileShortName, cTile);

            if (tileShortName == "C")   //TEMPORARY
            {
                cTile.addNotifyBehavior("CTesting", new NotifyBehaviorMapObject());
            }
        }

        //Map Layout
        XElement xmlLayout = xmlMap.Root.Element("Layout");
        List<XElement> xmlRowList = xmlLayout.Elements("Row").ToList<XElement>();

        //Dynamically grab the width from the length of the first row, and the height from the number of rows.
            //Dynamically grabbing them helps reduce human error that will happen during map XML creation, but adds a little bit of time to loading.
        int w = 0;
        if(xmlRowList.Count > 0)
        {
            w = ((string)(xmlRowList[0])).Split(',').Length;
        }
        int mapHeight = xmlRowList.Count;
        int mapWidth = w;

        _map.init(mapWidth, mapHeight);

        int cY = 0;
        foreach(XElement xmlRow in xmlRowList)
        {
            string rawRowData = (string)xmlRow;
            IEnumerable<string> splitRowData = rawRowData.Split(',');
            int cX = 0;
            foreach(string cellData in splitRowData)
            {
                string cellDataTrimmed = cellData.Trim();
                componentTile tileTemplate = tiles["0"];
                if (tiles.ContainsKey(cellDataTrimmed))
                {
                    tileTemplate = tiles[cellDataTrimmed];
                }
                else
                {
                    Debug.Log("Error could not find tile of short name : " + cellDataTrimmed + " - Replacing with a default tile \"0\"");
                }

                GameObject newTileObject = _map.addTile(cX, cY, tileTemplate, _notifier);

                cX++;
            }
            cY++;
        }

        //Load Map Objects (This must occur after the initialization of the tiles.)
        Dictionary<string, componentMapObject.dBuildObject> mapObjectRegistry = createMapObjectRegistry();
        IEnumerable<XElement> xmlObjects = xmlMap.Root.Element("MapObjects").Elements("Object");
        foreach (XElement xmlObject in xmlObjects)
        {
            string objType = ((string)xmlObject.Attribute("type")).ToUpper(); //auto to upper for case insensitivity
            if (mapObjectRegistry.ContainsKey(objType))
            {
                GameObject mapObject = mapObjectRegistry[objType](xmlObject);
                int objX = (xmlObject.Element("x") != null) ? ((int)xmlObject.Element("x")) : (0);
                int objY = (xmlObject.Element("y") != null) ? ((int)xmlObject.Element("y")) : (0);
                _map.addMapObject(objX, objY, mapObject);
            }
            else
            {
                Debug.Log("Unknown Map Object Type : " + objType);
            }
        }

        //Clean Up
        /* Not sure if I want to do this. Memory overhead seems minimal, and maybe I'll use them in the future.
        foreach (string tileKey in tiles.Keys)
        {
            DestroyObject(tiles[tileKey].gameObject);
        }
        */

        //Temporary player creating stuff
        List<componentMapObject> startLocations = _map.getMapObjectsByType(componentStartLocation.OBJECT_TYPE);
        int idx = Random.Range(0, startLocations.Count);
        GameObject playerUnitObject = componentUnit.createUnit("Player One Mega Tank Golem!", new SimpleUnitStatTemplate("Useless Name!", 10, 10), 1, "Player 1", "testTile_White_Black");
        componentMapObject playerUnitMapObject = playerUnitObject.GetComponent<componentMapObject>();
        playerUnitMapObject.addNotifyBehavior("Testing", new NotifyBehaviorMapObject());
        playerUnitMapObject.setNotifier(_notifier);
        componentUnit tempUnitComponent = playerUnitObject.GetComponent<componentUnit>();
        _map.addMapObject(_map.getObjectLocation(startLocations[idx]), playerUnitObject);

        notify("Testing", new Notification());
        notify("CTesting", new Notification());

        return 0;
    }
コード例 #18
0
    /**
     * A dedicated function to create the game object and tile component from it's parts.
     * Note: There isn't a way to externally create components.
     * @param x refers to the grid location
     * @param y refers to the grid location
     * @param spriteName refers to the sprite name
     * @param tTerrain refers to the type of terrain
     * @param parent refers to who the parent of the tile is
     */
    public GameObject addTile(int x, int y, string spriteName, TypeTerrain tTerrain, componentMapObject parent = null)
    {
        GameObject tileObject = componentTile.generateObject(TILE_OBJECT_NAME + " (" + x + "," + y + ")", spriteName, tTerrain, parent);

        addMapObject(x, y, tileObject);

        return tileObject;
    }
コード例 #19
0
 public Terrain(TypeTerrain type)
 {
     Type = type;
 }
コード例 #20
0
 public Sprite GetSpriteTerrain(TypeTerrain terrain)
 {
     return(m_conteneurTerrains[(int)terrain]);
 }
コード例 #21
0
 public void setTypeTerrain(TypeTerrain value)
 {
     _typeTerrain = value;
 }