개발일지/TIL
[Unity Devcamp] 0206 개발일지
JangKroed
2023. 3. 21. 20:36
728x90
반응형
기존에 만들던것 참고용으로 삼고 템플릿 구매하여 기획사항 적용
블록 모양 및 생성 규칙 적용
- 블록의 모양에 따라 난이도를 기본과 어려움으로 나누어 같은 블록이 3개 생기지 않고 어려운 난이도의 블록은 2개씩만 나오도록 구현.
블록 생성규칙 코드 - 1
// ShapeInfo.cs
//...
private Dictionary<string, List<int>> ShapeList = new()
{
{ "dot", new List<int>(){ 0 } },
{ "sq4", new List<int>(){ 1 } },
{ "I2", new List<int>(){ 2, 3 } },
{ "I3", new List<int>(){ 4, 5 } },
{ "I4", new List<int>() { 6, 7 } },
{ "L3", new List<int>() { 8, 9, 10, 11 } },
{ "L4", new List<int>() { 12, 13, 14, 15 } },
{ "L4h", new List<int>() { 16, 17, 18, 19 } },
{ "Worm", new List<int>() { 20, 21, 22, 23 } },
{ "T", new List<int>() { 24, 25, 26, 27 } },
{ "Cross4", new List<int>() { 28, 29 } },
{ "U5", new List<int>() { 30, 31, 32, 33 } },
{ "T5", new List<int>() { 34, 35, 36, 37 } },
{ "Z5", new List<int>() { 38, 39, 40, 41 } },
{ "L5", new List<int>() { 42, 43, 44, 45 } },
{ "I5", new List<int>() { 46, 47 } },
};
private List<string> ShapeNames = new()
{
"dot", "sq4", "I2", "I3", "I4", "L3", "L4", "L4h", "Worm", "T", "Cross4", "U5", "T5", "Z5", "L5", "I5"
};
public ShapeSt GetRandomShape()
{
//int index = Random.Range(0, shapes.Length);
var shapeIndex = ShapeList[ShapeNames[Random.Range(0, ShapeNames.Count)]];
int index = shapeIndex[Random.Range(0,shapeIndex.Count)];
/*if (Master.REF.IsDebugMode() && Master.REF.debugShapesIndex[0] >= 0)
{
index = Master.REF.debugShapesIndex[Random.Range(0, Master.REF.debugShapesIndex.Length)];
}*/
return shapes[index];
}
//...
블록 생성규칙 코드 - 2
// ShapeManager.cs
// ...
public void CreateShapes()
{
ClearPanels();
for (int i = 0; i < shapesPanel.Length; i++)
{
var shapeSt = ShapeInfo.REF.GetRandomShape();
while (i > 0 && shapeSt.name == shapesPanel[i - 1].GetChild(0).name || i > 1 && shapeSt.name == shapesPanel[i - 2].GetChild(0).name)
{
shapeSt = ShapeInfo.REF.GetRandomShape();
}
CreateShape(shapeSt, shapesPanel[i]);
shapeCounter++;
}
BoardManager.REF.GameOverCheck();
}
// ...
public void CreateShape(ShapeInfo.ShapeSt shapeSt,Transform shapePanel)
{
GameObject shapeObj = Instantiate(ShapeInfo.REF.shapePrefab, shapePanel);
shapeObj.GetComponent<Shape>().Initialize(shapeSt);
}
// ...
블록 점수계산 로직 적용
- 블록 배치시 블록 칸 수 만큼 점수가 증가하고 줄을 완성했을 경우 {18 * (1 + 완성한 줄 수)} * 콤보 수 만큼 오르도록 구현
- 콤보 조건은 블록은 연속으로 놓아서 줄이나 칸을 완성하거나 한번의 블록 배치로 여러 블록을 파괴할 경우
boardManager.cs - 1
private IEnumerator ClearMatches_Auto(List<Vector2Int> columnMatches, List<Vector2Int> rowMatches, List<Vector2Int> squareMatches, int combo, int clearLines)
{
yield return new WaitForSeconds(0.35F);
Transform textFxTransform = boardPanel;
////print("===============Clear Matches:=======");
if(columnMatches.Count>0)
{
////print("Clear COLUMNS Match | Count:" + columnMatches.Count);
for (int i = 0; i < columnMatches.Count; i++)
{
int x = columnMatches[i].x;
int y = columnMatches[i].y;
matrix[x, y]=matrix[x,y]>0?matrix[x,y]-1:0;
SetCellSprite_Default(boardCells[x, y], x, y, matrix[x, y]);
GfxCreate_BlockCrear(boardCells[x, y].transform);
textFxTransform = boardCells[x, y].transform;
yield return new WaitForSeconds(0.01F);
}
}
if (rowMatches.Count > 0)
{
////print("Clear ROWS Match | Count:" + rowMatches.Count);
for (int i = 0; i < rowMatches.Count; i++)
{
int x = rowMatches[i].x;
int y = rowMatches[i].y;
matrix[x, y] = matrix[x, y] > 0 ? matrix[x, y] - 1 : 0;
SetCellSprite_Default(boardCells[x, y], x, y, matrix[x, y]);
GfxCreate_BlockCrear(boardCells[x, y].transform);
textFxTransform = boardCells[x, y].transform;
yield return new WaitForSeconds(0.01F);
}
}
if (squareMatches.Count > 0)
{
//print("Clear SQUARE Match | Count:" + squareMatches.Count);
for (int i = 0; i < squareMatches.Count; i++)
{
int x = squareMatches[i].x;
int y = squareMatches[i].y;
matrix[x, y] = matrix[x, y] > 0 ? matrix[x, y] - 1 : 0;
SetCellSprite_Default(boardCells[x, y], x, y, matrix[x, y]);
GfxCreate_BlockCrear(boardCells[x, y].transform);
textFxTransform = boardCells[x, y].transform;
yield return new WaitForSeconds(0.01F);
}
}
if (clearLines > 0) AddComboScore(textFxTransform, 18 * (1 + clearLines), combo);
else AddComboScore(textFxTransform, clearLines, combo);
GameOverCheck();
}
boardManager.cs - 2
```
private void AddComboScore(Transform textFxTransform, int value, int combo)
{
if (value >= 36)
{
comboCount++;
score += value * comboCount;
GameHUD.REF.SetScoreUI(score);
TextFxCreate_Score(textFxTransform, value * comboCount, comboCount);
}
else
{
AddScore(textFxTransform, value, combo);
comboCount = 0;
}
}
```
- 추후 블록을 놓을때 사라지는 블록 갯수당 -1점 적용필요
일일 도전목표 (구현 중)
- 게임 시작이 그 날 2번째 이상 플레이부터 목표점수 팝업창이 나온다.
- 목표점수는 매일 달라진다.
- 보드판 왼쪽 상단에 계속 표시된다
- 목표 달성시 체크표시 된다.
- 보상이나 그 외 효과는 없다.
![]() |
아직 팝업창 및 시작 버튼 클릭 후 게임플레이까지만 구현 일일 목표점수 연동 및 2번째 플레이 부터 팝업되는 기능 구현필요 |
728x90
반응형