Ir al contenido principal

Juegos indie y publishers

Una vez un equipo indie ha terminado un juego o está en la fase de desarrollo y tiene claro los datos clave del juego como el modelo de negocio, plataformas, ventana de lanzamiento y un roadmap bien definido es momento de pensar como querréis lanzar su juego . Evidentemente la auto publicación es una opción, pero obliga al equipo a derivar recursos (tiempo, conocimientos y dinero) en entender como se debe lanzar un juego para que este funcione o al menos recuperemos lo invertido. Como desarrollador de juegos indie, conocer el funcionamiento de los publishers es crucial para decidir si trabajar con uno puede ayudarte a lanzar y comercializar tu juego de manera más efectiva. El punto clave para ello es evaluar lo que necesitamos de él (porting, marqueting, localización, etc.), analizar que recoup tendremos (dinero que habrá que devolver al publisher) y con que condiciones. El recoup (o recoupment) es el proceso por el cual un publisher recupera el dinero invertido en un juego antes d...

Attila. Mecánica de juego

Una vez terminado el editor de niveles, podemos crear algunos y gravarlos en la carpeta resources para que al instalar el juego en un dispositivo móvil podamos seguir accediendo a los archivos individualmente.


El siguiente paso, más allá de crear las escenas intermedias (menú principal, menú de etapas) que más adelante implementaremos nos permiten llegar a la escena del juego. En esta escena queremos mostrar el tablero en formato isométrico para poder jugar con el nivel previamente diseñado.


En concreto yo utilizo Isometric Builder para para implementar las escenas isométricas ya que me permite, más adelante, tratar cada casilla como un objetos independiente y en este caso añadir clases para cada casilla independiente.


El primer paso es diseñar el tablero máximo para distribuir los elementos de juego (tablero HUD, controles) en el espacio. En este caso yo he utilizado un gráfico isométrico genérico para implementar las casillas vacías.


A partir de aquí la implementación del juego consiste en la interrelación de las clases compuestas por el GameManager, el Player, y las casillas del tablero.



El GameManager se encarga de cargar el tablero a partir del archivo en la carpeta resources y generar el tablero en pantalla. Así mismo debemos calcular los movimientos disponibles después de mover el jugador así como procesar los eventos que se generen al mover el caballo. También es su función estar permanentemente a la escucha para saber cuándo el jugador ha pulsado alguna casilla de destino.


GameManager.cs
 using System.Collections;  
 using System.Collections.Generic;  
 using UnityEngine;  
 using UnityEngine.SceneManagement;  
 using UnityEngine.UI;  
 public class GameManager : MonoBehaviour  
 {  
   public Text troops;  
   public Text weapons;  
   public Text water;  
   public Text food;  
   public Text gold;  
   public Text stageName;  
   public Sprite tundra;  
   public Sprite desert;  
   public Sprite woods;  
   public Sprite town;  
   public Sprite city;  
   public Sprite army;  
   public Sprite crops;  
   public Sprite lake;  
   public Sprite river;  
   public Sprite mine;  
   public Sprite objective;  
   public Sprite mountains;  
   public Sprite empty;  
   public Sprite horse;  
   private int troopsO;  
   private int weaponsO;  
   private int waterO;  
   private int foodO;  
   private int goldO;  
   private int scoreO;  
   // Start is called before the first frame update  
   void Start()  
   {  
     SaveOriginals();  
     GlobalInfo.isPlaying = false;  
     GlobalInfo.stagesCount++;  
     SetEnviroment();  
     StartPlay();  
   }  
   public void SetEnviroment()  
   {  
     troops.text = GlobalInfo.troops.ToString("#,#");  
     weapons.text = GlobalInfo.weapons.ToString("#,#");  
     water.text = GlobalInfo.water.ToString("#,#");  
     food.text = GlobalInfo.food.ToString("#,#");  
     gold.text = GlobalInfo.gold.ToString("#,#");  
     Levels.LoadLevel(GlobalInfo.actualStage);  
     GlobalInfo.objectivesNum = 0;  
     GlobalInfo.finalNum = 0;  
     stageName.text = GlobalInfo.stageName;  
     PaintStage();  
     PaintInfo();  
   }  
   public void SaveOriginals()  
   {  
     //Save original values  
     troopsO = GlobalInfo.troops;  
     weaponsO = GlobalInfo.weapons;  
     waterO = GlobalInfo.water;  
     foodO = GlobalInfo.food;  
     goldO = GlobalInfo.gold;  
     scoreO = GlobalInfo.score;  
   }  
   public void RestoreOriginals()  
   {  
     //Restore original values  
     GlobalInfo.troops = troopsO;  
     GlobalInfo.weapons = weaponsO;  
     GlobalInfo.water = waterO;  
     GlobalInfo.food = foodO;  
     GlobalInfo.gold = goldO;  
     GlobalInfo.score = scoreO;  
   }   
   private void StartPlay()  
   {  
     GlobalInfo.isPlaying = true;  
   }  
   private void PaintStage()  
   {  
     int xx = 0;  
     int yy = 0;  
     for (int i = 1; i <= 64; i++)  
     {  
       GameObject cell = GameObject.Find("Cell" + i.ToString());  
       GameObject regular = GetChildWithName(cell, "Regualr_Collider_Union");  
       GameObject spriteCell = GetChildWithName(regular, "Iso2DObject_Union");  
       // GameCell Class info  
       cell.GetComponent<GameCell>().num = i;  
       cell.GetComponent<GameCell>().x = xx;  
       cell.GetComponent<GameCell>().y = yy;  
       xx++;  
       if (xx == 8)  
       {  
         xx = 0;  
         yy++;  
       }  
       //Sprite  
       if (GlobalInfo.gridStage[i - 1].type > 0)  
       {  
         spriteCell.GetComponent<SpriteRenderer>().sprite = TypeSprite(GlobalInfo.gridStage[i - 1].type);  
         if (GlobalInfo.gridStage[i - 1].isObjective)  
         {            
           GameObject ObjFlag = GeneralUtils.FindObject(cell, "Flag");  
           ObjFlag.SetActive(true);  
           cell.GetComponent<GameCell>().objective = true;  
           GlobalInfo.objectivesNum++;            
         }  
         if (GlobalInfo.gridStage[i - 1].isFinal)  
         {           
           GameObject FinFlag = GeneralUtils.FindObject(cell, "FlagF");  
           FinFlag.SetActive(true);  
           cell.GetComponent<GameCell>().final = true;  
           GlobalInfo.finalNum++;  
         }  
       } else  
       {  
         Destroy(cell);  
       }  
       //Player info  
       if (GlobalInfo.gridStage[i - 1].isStart == true)  
       {  
         GlobalInfo.playerPos = i;  
       }        
     }  
     //Set player  
     GameObject player = GameObject.Find("Player");  
     player.transform.position = GameObject.Find("Cell" + GlobalInfo.playerPos.ToString()).GetComponent<Transform>().position;  
     //Set player cell  
     GameObject cellStart = GameObject.Find("Cell" + GlobalInfo.playerPos.ToString());  
     GameObject regularStart = GetChildWithName(cellStart, "Regualr_Collider_Union");  
     GameObject spriteCellStart = GetChildWithName(regularStart, "Iso2DObject_Union");  
     spriteCellStart.GetComponent<SpriteRenderer>().sprite = horse;  
     Invoke("CalculateMovementsAvaliable", 0.5f);  
   }  
   private void CalculateMovementsAvaliable()  
   {  
     //Calculate movements avaliable  
     GameObject[] cells = GameObject.FindGameObjectsWithTag("GameCell");  
     foreach (GameObject cell in cells)  
     {  
       cell.GetComponent<GameCell>().CalculateMovements();  
     }  
     GameObject cellStart = GameObject.Find("Cell" + GlobalInfo.playerPos.ToString());  
     cellStart.GetComponent<GameCell>().SetMoveables();  
     cellStart.GetComponent<GameCell>().ShowMoveables();  
   }  
   private GameObject GetChildWithName(GameObject obj, string name)  
   {  
     Transform trans = obj.transform;  
     Transform childTrans = trans.Find(name);  
     if (childTrans != null)  
     {  
       return childTrans.gameObject;  
     }  
     else  
     {  
       return null;  
     }  
   }  
   public void PaintInfo()  
   {  
     GameObject.Find("Player").GetComponent<MovePlayer>().ShowInfo();  
   }  
   public Sprite TypeSprite(int num)  
   {  
     if (num == 1) { return tundra; }  
     if (num == 2) { return desert; }  
     if (num == 3) { return woods; }  
     if (num == 4) { return town; }  
     if (num == 5) { return city; }  
     if (num == 6) { return army; }  
     if (num == 7) { return crops; }  
     if (num == 8) { return lake; }  
     if (num == 9) { return river; }  
     if (num == 10) { return mine; }  
     if (num == 11) { return objective; }  
     if (num == 12) { return mountains; }  
     return empty;  
   }  
   public void ToStageMenu()  
   {  
     SceneManager.LoadScene("StageSelector");  
   }  
   public void RestartLevel()  
   {  
     RestoreOriginals();  
     SceneManager.LoadScene("Attila");  
   }  
   public void MoveHorse(string origen, string final)  
   {  
     GameObject.Find("Player").GetComponent<MovePlayer>().Move(final);  
   }  
   private bool DestionationAvaliable(GameObject dest)  
   {      
     return dest.GetComponent<GameCell>().moveable;  
   }  
   // Update is called once per frame  
   void Update()  
   {  
     if (Input.GetMouseButtonDown(0))  
     {  
       Ray screenRay = Camera.main.ScreenPointToRay(Input.mousePosition);  
       RaycastHit hit;  
       if (Physics.Raycast(screenRay, out hit))  
       {  
         if (hit.collider != null)  
         {  
           if (hit.collider.gameObject.name == "Regualr_Collider_Union"   
             && GlobalInfo.isPlaying == true   
             && GlobalInfo.isPlayerMoving == false)  
           {  
             if (DestionationAvaliable(GameObject.Find(hit.collider.gameObject.transform.parent.name)))  
             {  
               MoveHorse("Cell" + GlobalInfo.playerPos.ToString(), hit.collider.gameObject.transform.parent.name);  
             }              
           }            
         }          
       }  
     }  
   }  
 }  

Hay que tener en cuenta que el caballo tarda un tiempo en moverse por lo cual debemos gestionar ese tiempo de movimiento y actuar al llegar a la casilla destino y no dejar que se produzca ningún evento mientras el caballo está en movimiento. La clase MovePlayer se encarga de este trabajo, mover el caballo utilizando el NavMesh que hemos creado encima del tablero. También será la encargada de gestionar los eventos al mover el jugador e interaccionar con una casilla.

MovePlayer.cs
 using System.Collections;  
 using UnityEngine;  
 using UnityEngine.AI;  
 using UnityEngine.UI;  
 public class MovePlayer : MonoBehaviour  
 {  
   public Text objectivesText;  
   public Text finalText;  
   private NavMeshAgent agent;  
   private string destination;  
   public void Start()  
   {  
     destination = "";  
     GlobalInfo.isOldCellDestroyed = true;  
   }  
   public void Move(string mCell)  
   {  
     GameObject dest = GameObject.Find(mCell);  
     if (dest != null)  
     {  
       //Don't move at the same position  
       if ("Cell" + GlobalInfo.playerPos.ToString() != mCell)  
       {  
         NavMeshAgent agent = GetComponent<NavMeshAgent>();  
         agent.destination = dest.transform.position;  
         GlobalInfo.isPlayerMoving = true;  
         GlobalInfo.isOldCellDestroyed = false;  
         destination = mCell;  
         dest.GetComponent<GameCell>().SetMoveables();  
         GameObject origin = GameObject.Find("Cell" + GlobalInfo.playerPos.ToString());  
         origin.GetComponent<GameCell>().HideMoveables();  
         StartCoroutine(DestroyCell(origin));  
       }        
     }      
   }  
   IEnumerator DestroyCell(GameObject cellToDestroy)  
   {  
     yield return new WaitForSeconds(1f);      
     Destroy(cellToDestroy);  
     yield return new WaitForSeconds(0.5f);  
     CalculateNewMovements();  
     GlobalInfo.isOldCellDestroyed = true;  
   }  
   private void CalculateNewMovements()  
   {  
     GameObject[] cells = GameObject.FindGameObjectsWithTag("GameCell");  
     foreach (GameObject cell in cells)  
     {  
       cell.GetComponent<GameCell>().CalculateMovements();  
     }  
   }  
   private bool PathComplete()  
   {  
     NavMeshAgent mNavMeshAgent = GetComponent<NavMeshAgent>();  
     if (!mNavMeshAgent.pathPending)  
     {  
       if (mNavMeshAgent.remainingDistance <= mNavMeshAgent.stoppingDistance)  
       {  
         if (!mNavMeshAgent.hasPath || mNavMeshAgent.velocity.sqrMagnitude == 0f)  
         {  
           return true;  
         }  
         return false;  
       }  
       return false;  
     }  
     return false;  
   }  
   public void ProcessEvents()  
   {  
     //Update values  
     if (GameObject.Find(destination).GetComponent<GameCell>().objective == true)  
     {  
       GlobalInfo.objectivesNum--;  
     }  
     if (GameObject.Find(destination).GetComponent<GameCell>().final == true)  
     {  
       GlobalInfo.finalNum--;  
     }  
     if (GlobalInfo.objectivesNum == 0)  
     {  
       if (GlobalInfo.finalNum == 0)  
       {  
         //Good job!  
       }  
     }  
     if (GlobalInfo.movementsNum == 0)  
     {  
       //Game over;  
     }  
     ShowInfo();  
     GlobalInfo.isPlayerMoving = false;  
   }  
   public void ShowInfo()  
   {  
     objectivesText.text = GlobalInfo.objectivesNum.ToString();      
   }  
   private void Update()  
   {  
     if (GlobalInfo.isPlayerMoving == true)  
     {  
       if (PathComplete() && GlobalInfo.isOldCellDestroyed)  
       {          
         GameObject.Find(destination).GetComponent<GameCell>().ShowMoveables();  
         GlobalInfo.playerPos = GameObject.Find(destination).GetComponent<GameCell>().num;  
         //Set destionation cell  
         GameObject cellStart = GameObject.Find("Cell" + GlobalInfo.playerPos.ToString());  
         GameObject regularStart = GetChildWithName(cellStart, "Regualr_Collider_Union");  
         GameObject spriteCellStart = GetChildWithName(regularStart, "Iso2DObject_Union");  
         spriteCellStart.GetComponent<SpriteRenderer>().sprite = GameObject.Find("GameManager").GetComponent<GameManager>().horse;  
         ProcessEvents();          
       }        
     }  
   }  
   private GameObject GetChildWithName(GameObject obj, string name)  
   {  
     Transform trans = obj.transform;  
     Transform childTrans = trans.Find(name);  
     if (childTrans != null)  
     {  
       return childTrans.gameObject;  
     }  
     else  
     {  
       return null;  
     }  
   }  
 }  

Y finalmente tenemos la clase GameCell que se encarga de calcular las posibilidades de movimiento teniendo en cuenta el movimiento del caballo y las casillas que nos quedan disponibles después de cada tirada, mostrar u ocultar las posibilidades en pantalla.


GameCell.cs
 using System.Collections;  
 using System.Collections.Generic;  
 using UnityEngine;  
 using System;  
 public class GameCell : MonoBehaviour  
 {  
   public int x;  
   public int y;  
   public int num;  
   public bool moveable;  
   public bool final;  
   public bool objective;  
   public int[] moves = new int[8] ;  
   // Start is called before the first frame update  
   void Start()  
   {  
     ResetMovements();      
   }  
   private void ResetMovements()  
   {  
     moves[0] = 0;  
     moves[1] = 0;  
     moves[2] = 0;  
     moves[3] = 0;  
     moves[4] = 0;  
     moves[5] = 0;  
     moves[6] = 0;  
     moves[7] = 0;  
   }  
   public void CalculateMovements()  
   {  
     ResetMovements();  
     if ((x + 1 < 8) && (y - 2 >= 0))  
     {  
       moves[0] = FindGameCell(x+1,y-2);  
     }  
     if ((x + 2 < 8) && (y + 1 < 8))  
     {  
       moves[1] = FindGameCell(x + 2, y + 1);  
     }  
     if ((x + 2 < 8) && (y - 1 >= 0))  
     {  
       moves[2] = FindGameCell(x + 2, y - 1);  
     }  
     if ((x + 1 < 8) && (y + 2 < 8))  
     {  
       moves[3] = FindGameCell(x + 1, y + 2);  
     }  
     if ((x - 1 >= 0) && (y + 2 < 8))  
     {  
       moves[4] = FindGameCell(x - 1, y + 2);  
     }  
     if ((x - 2 >= 0) && (y + 1 < 8))  
     {  
       moves[5] = FindGameCell(x - 2, y + 1);  
     }  
     if ((x - 2 >= 0) && (y - 1 >= 0))  
     {  
       moves[6] = FindGameCell(x - 2, y - 1);  
     }  
     if ((x - 1 >= 0) && (y - 2 >= 0))  
     {  
       moves[7] = FindGameCell(x - 1, y - 2);  
     }  
   }    
   private int FindGameCell(int xx, int yy)  
   {  
     GameObject[] cells = GameObject.FindGameObjectsWithTag("GameCell");  
     foreach (GameObject cell in cells)  
     {  
       if (cell.GetComponent<GameCell>().x == xx && cell.GetComponent<GameCell>().y == yy)  
       {  
         return cell.GetComponent<GameCell>().num;  
       }  
     }  
     return 0;  
   }  
   public void SetMoveables()  
   {  
     GameObject[] cells = GameObject.FindGameObjectsWithTag("GameCell");  
     foreach (GameObject cell in cells)  
     {  
       cell.GetComponent<GameCell>().moveable = false;  
       int pos = Array.IndexOf(moves, cell.GetComponent<GameCell>().num);  
       if (pos > -1)  
       {  
         cell.GetComponent<GameCell>().moveable = true;          
       }  
     }  
   }  
   public void ShowMoveables()  
   {  
     GlobalInfo.movementsNum = 0;  
     for (int i = 0; i < 8; i++)  
     {  
       if (moves[i]>0)  
       {  
         GameObject cell = GameObject.Find("Cell" + moves[i].ToString());  
         GameObject selector = GeneralUtils.FindObject(cell, "Selector");  
         selector.SetActive(true);  
         GlobalInfo.movementsNum++;  
       }  
     }  
   }  
   public int GetMoveables()  
   {  
     int num = 0;  
     for (int i = 0; i < 8; i++)  
     {  
       if (moves[i] > 0)  
       {  
         num++;  
       }  
     }  
     return num;  
   }  
   public void HideMoveables()  
   {  
     for (int i = 0; i < 8; i++)  
     {  
       if (moves[i] > 0)  
       {  
         GameObject cell = GameObject.Find("Cell" + moves[i].ToString());  
         GameObject selector = GeneralUtils.FindObject(cell, "Selector");  
         selector.SetActive(false);  
       }  
     }  
   }  
 }  

Comentarios

Entradas populares de este blog

Juegos indie y publishers

Una vez un equipo indie ha terminado un juego o está en la fase de desarrollo y tiene claro los datos clave del juego como el modelo de negocio, plataformas, ventana de lanzamiento y un roadmap bien definido es momento de pensar como querréis lanzar su juego . Evidentemente la auto publicación es una opción, pero obliga al equipo a derivar recursos (tiempo, conocimientos y dinero) en entender como se debe lanzar un juego para que este funcione o al menos recuperemos lo invertido. Como desarrollador de juegos indie, conocer el funcionamiento de los publishers es crucial para decidir si trabajar con uno puede ayudarte a lanzar y comercializar tu juego de manera más efectiva. El punto clave para ello es evaluar lo que necesitamos de él (porting, marqueting, localización, etc.), analizar que recoup tendremos (dinero que habrá que devolver al publisher) y con que condiciones. El recoup (o recoupment) es el proceso por el cual un publisher recupera el dinero invertido en un juego antes d...

Controladores de personaje para Unity 3D

Como no me gusta inventar la rueda agradezco aquellos desarrolladores que comparten parte de su esfuerzo con la comunidad. En esta ocasión os traigo dos controladores de personaje para vuestros proyectos Unity 3D que he encontrado muy interesantes y que os pueden ayudar en vuestros proyectos. En primer lugar tenemos a Dynamic Parkour System de Eric Canela . Es un plugin gratuito para Unity que permite a cualquier persona importar cualquier modelo y tener un controlador ya funcionando con capacidades de parkour como en los juegos de Assassin's Creed.  Lo he probado en Unity y después de poner las dependencias (para que el Sistema de Parkour Dinámico funcione, requiere la importación de los paquetes de Cinemachine y del Sistema de Entrada ubicados en el Administrador de Paquetes de Unity.) ha funcionado perfectamente en un proyecto propio.  Si os interesa o si estaís diseñando un juego con mecánicas como esta os recomiendo que le echéis un vistazo. Al final del artículo os...

El diseño de la interfaz de usuario

El estudio del diseño de interfaz de usuario en videojuegos es un tema que se ha estudiado en profundidad pero que muchos desarrolladores que empiezan no prestan mucha atención centrando su energía en las mecánicas del juego y especialmente el arte ya que muchas veces el éxito o el fracaso de un juego dependen de ello. Pero más lejos de la realidad la capacidad lúdica de un juego muchas veces también viene determinada por el diseño de la interfaz que hace de dialogo entre el jugador y el juego. Uno de los mejores análisis de las interfaces de usuario en videojuegos lo encontramos en los estudios realizados por Anthony Stonehouse y Marcus Andrews . El diseño de la interfaz de usuario en los juegos difiere de otro diseño de interfaz de usuario porque implica un elemento adicional: la ficción. La ficción involucra un avatar del usuario real, o jugador. El jugador se convierte en un elemento invisible, pero clave de la historia, como un narrador en una novela o película. Esta ficc...