Skip to content

Commit

Permalink
Create and update gamemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanakim0304 committed Oct 23, 2024
1 parent 9bcc04d commit af62fad
Show file tree
Hide file tree
Showing 9 changed files with 5,634 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Assets/Scenes/Scene1.unity
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ TilemapRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 635587383}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
Expand Down Expand Up @@ -3598,6 +3598,37 @@ Tilemap:
e31: 0
e32: 0
e33: 1
--- !u!1 &1028602778
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1028602779}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1028602779
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1028602778}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.64744174, y: 6.375536, z: -0.10777246}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1427431534
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -8751,3 +8782,4 @@ SceneRoots:
m_Roots:
- {fileID: 465062962}
- {fileID: 2046344527}
- {fileID: 1028602779}
8 changes: 8 additions & 0 deletions Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
public Ghost[] ghosts;
public Pacman pacman;
public Transform pellets;

public int score {get; private set;}
public int lives {get; private set;}


private void Start()
{
NewGame();
}

private void NewGame()
{
SetScore(0);
SetLives(3);
NewRound();
}

private void NewRound()
{
foreach (Transform pellet in this.pellets)
{
pellet.gameObject.SetActive(true);
}

ResetState();
}

private void ResetState()
{
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].gameObject.SetActive(true);
}

this.pacman.gameObject.SetActive(true);
}

private void GameOver()
{
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].gameObject.SetActive(false);
}

this.pacman.gameObject.SetActive(false);
}

private void SetScore(int score)
{
this.score = score;
}

private void SetLives(int lives)
{
this.lives = lives;
}

public void GhostEaten(Ghost ghost)
{
SetScore(this.score + ghost.points);
}

public void PacmanEaten()
{
this.pacman.gameObject.SetActive(false);
SetLives(this.lives - 1);

if (this.lives > 0){
Invoke(nameof(ResetState), 3.0f);
} else {
GameOver();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/GameManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/Ghost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
public int points = 200;
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Ghost.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Assets/Scripts/Pacman.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pacman : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Pacman.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af62fad

Please sign in to comment.