馃檲 Darle nombres correctos a nuestras variables puede ser dif铆cil pero, el esfuerzo vale la pena para nosotros y para todo nuestro equipo. 馃 Estas lecturas me ayudaron bastante para programar en JavaScript:
La estructura de un juego para m贸vil
Qu茅 aprender谩s sobre el desarrollo de videojuegos para m贸viles
Presentaci贸n y Game Design de nuestro proyecto
IMPORTANTE: Archivos del curso
Estructura de carpetas y assets en Unity
Sprite Atlas y Generaci贸n de Caramelos
Sprite Atlas: El fondo del escenario
Sprite Atlas: Los dulces
El script de los dulces
El Manager del tablero o Grid Manager
Inicializaci贸n del tablero
Ejercicio: cortar caramelos
Configurar el manager de dulces
A帽adir caramelos de forma aleatoria
Dise帽o de Game Play
Verificar y evitar caramelos repetidos
Selecci贸n de los caramelos
Swapping de Caramelos
Caramelos vecinos
Comprobar 3 en raya
Detectar coincidencias y destruir caramelos
Bajar caramelos en cascada cuando un grupo es eliminado
Generar caramelos aleatorios para completar los espacios vac铆os
Eliminar los grupos de caramelos similares que se generan al completar los espacios vac铆os (combos)
Retos finales
Trabajando la interfaz de nuestro videojuego
Contar los movimientos restantes y la puntuaci贸n
Implementando puntuaci贸n en nuestro juego
Reto: Pantalla de Game Over
Reto: Nuevos niveles de dificultad
Reto: Audio de los caramelos
Reto: Movimiento de los Caramelos con Animaciones
Reto: Men煤 Principal
Cierre del curso
Preparando nuestro juego para exportarlo
Probando nuestro juego en dispositivos m贸viles y Conclusiones
You don't have access to this class
Keep learning! Join and start boosting your career
Inline candy detection is key to achieve matches in games like Candy Crush. The goal is to identify when three or more candies are aligned in rows or columns. This task falls to the manager
, which examines a data matrix looking for matches of three or more candies.
This concept is essential in the classic implementation of Candy Crush, where aligned candies are destroyed. However, it is possible to modify the method to search for other types of matches, such as diagonally or by forming squares of four candies. This will require adjustments to much of the gameplay and code. Below, we explore a basic method for identifying these matches.
First, you need a constant that defines the minimum number of candies for a match. It is recommended to initialize it starting with a capital letter, following C# best practices. Although the standard could be three candies, it is conceptualized as two neighbors plus the current candy, since in the end, the goal is to generate a match of at least three candies.
findMatch
method?We start by creating a method to check for a match in rows or columns. It is built inside the Board Manager
class and its purpose is to check if there is a match of three or more candies at a given address. It uses an empty list of game objects(GameObjects
) that will store the matching candies.
private List<GameObject> FindMatch(Vector2 direction){ List<GameObject> matchingCandies = new List<GameObject>(); // Logic for finding matching candies to be implemented here}
The next step is to program, in the Candy.cs
script, a method that looks for neighbors at the given address, either row or column. This method makes sure that the minimum number of matches is achieved to destroy candy.
private List<GameObject> FindMatch(Vector2 direction){ List<GameObject> matchingCandies = new List<GameObject>(); RaycastHit2D hit = Physics2D.Raycast(this.transform.position, direction);
while (hit.collider != null && hit.collider.GetComponent<SpriteRenderer>().sprite == this.GetComponent<SpriteRenderer>().sprite) { matchingCandies.Add(hit.collider.gameObject); hit = Physics2D.Raycast(hit.collider.transform.position, direction); } return matchingCandies;}
This approach checks for neighbors in the specified direction. If found, it continues until the conditions are met.
To complete the method, it is crucial to evaluate in the opposite direction. This requires duplicating the previous code block and modifying the direction inversely.
// Original codehit = Physics2D.Raycast(hit.collider.transform.position, -direction);
while (hit.collider != null && hit.collider.GetComponent<SpriteRenderer>().sprite == this.GetComponent<SpriteRenderer>().sprite){ matchingCandies.Add(hit.collider.gameObject); hit = Physics2D.Raycast(hit.collider.transform.position, -direction);}
Once the two directions are verified, matching candies are returned. This approach ensures correct neighbor detection in any game situation, whether at the edge or in the center of the board.
This method encourages continuous development and personal improvement, adapting and customizing according to the needs of the game. The logic presented can be the starting point for implementing more advanced features in similar video games. Constant practice and experimentation lead to a deeper mastery of video game programming.
Contributions 8
Questions 1
馃檲 Darle nombres correctos a nuestras variables puede ser dif铆cil pero, el esfuerzo vale la pena para nosotros y para todo nuestro equipo. 馃 Estas lecturas me ayudaron bastante para programar en JavaScript:
Tambien pueden compararlos con el Id.
while (hit.collider != null && hit.collider.GetComponent<Candy>().id == id)
{
matchingCandies.Add(hit.collider.gameObject);
hit = Physics2D.Raycast(hit.collider.transform.position, direction);
}
Super interesante.
EXELENTE
Genial
Todo excelente solo no se cual linea es la que mide en vertical y cual en horizontal,
驴Que paso con el metodo de BoardManager que no termino de escribir?
Want to see more contributions, questions and answers from the community?