Skip to content
Snippets Groups Projects
Commit ec57f5cc authored by Putinabillaa's avatar Putinabillaa
Browse files

feat: get spawned pets

parent 7d63ecdc
No related merge requests found
...@@ -51,5 +51,5 @@ ...@@ -51,5 +51,5 @@
"temp/": true, "temp/": true,
"Temp/": true "Temp/": true
}, },
"dotnet.defaultSolution": "GamePBD.sln" "dotnet.defaultSolution": "if3210-2024-unity-ngk.sln"
} }
\ No newline at end of file
This diff is collapsed.
fileFormatVersion: 2
guid: 1ac6e0efc01154936905e5bd1dda76e8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
using UnityEngine; using UnityEngine;
using System; using System;
using System.Collections.Generic;
[Serializable] [Serializable]
public class GameState { public class GameState {
...@@ -7,12 +8,14 @@ public class GameState { ...@@ -7,12 +8,14 @@ public class GameState {
public float playerHealth; public float playerHealth;
public int lastQuestIndex; public int lastQuestIndex;
public int difficulty; public int difficulty;
public List<int> spawnedPets;
public GameState(string playerName, float playerHealth, int lastQuestIndex, int difficulty) { public GameState(string playerName, float playerHealth, int lastQuestIndex, int difficulty, List<int> spawnedPets) {
this.playerName = playerName; this.playerName = playerName;
this.playerHealth = playerHealth; this.playerHealth = playerHealth;
this.lastQuestIndex = lastQuestIndex; this.lastQuestIndex = lastQuestIndex;
this.difficulty = difficulty; this.difficulty = difficulty;
this.spawnedPets = new List<int>(spawnedPets);
} }
// Copy constructor // Copy constructor
...@@ -21,6 +24,8 @@ public class GameState { ...@@ -21,6 +24,8 @@ public class GameState {
this.playerHealth = gameState.playerHealth; this.playerHealth = gameState.playerHealth;
this.lastQuestIndex = gameState.lastQuestIndex; this.lastQuestIndex = gameState.lastQuestIndex;
this.difficulty = gameState.difficulty; this.difficulty = gameState.difficulty;
this.spawnedPets = gameState.spawnedPets;
this.spawnedPets = new List<int>(gameState.spawnedPets);
} }
// Copy operator // Copy operator
...@@ -29,38 +34,16 @@ public class GameState { ...@@ -29,38 +34,16 @@ public class GameState {
this.playerHealth = gameState.playerHealth; this.playerHealth = gameState.playerHealth;
this.lastQuestIndex = gameState.lastQuestIndex; this.lastQuestIndex = gameState.lastQuestIndex;
this.difficulty = gameState.difficulty; this.difficulty = gameState.difficulty;
} this.spawnedPets = gameState.spawnedPets;
// Getter and Setter
public string GetPlayerName() {
return playerName;
}
public void SetPlayerName(string playerName) {
this.playerName = playerName;
}
public float GetPlayerHealth() {
return playerHealth;
}
public void SetPlayerHealth(float playerHealth) {
this.playerHealth = playerHealth;
}
public int GetLastQuestIndex() {
return lastQuestIndex;
}
public void SetLastQuestIndex(int lastQuestIndex) {
this.lastQuestIndex = lastQuestIndex;
}
public int GetDifficulty() {
return difficulty;
}
public void SetDifficulty(int difficulty) {
this.difficulty = difficulty;
} }
public void Print(){ public void Print(){
// Debug.Log("Player Name: " + playerName); Debug.Log("Player Name: " + playerName);
// Debug.Log("Player Health: " + playerHealth); Debug.Log("Player Health: " + playerHealth);
// Debug.Log("Last Quest Index: " + lastQuestIndex); Debug.Log("Last Quest Index: " + lastQuestIndex);
// Debug.Log("Difficulty: " + difficulty); Debug.Log("Difficulty: " + difficulty);
foreach (int pet in spawnedPets) {
Debug.Log("Pet: " + pet);
}
} }
} }
using UnityEngine; using UnityEngine;
using System.Collections.Generic;
public class MainSceneController : MonoBehaviour public class MainSceneController : MonoBehaviour
{ {
...@@ -6,6 +7,7 @@ public class MainSceneController : MonoBehaviour ...@@ -6,6 +7,7 @@ public class MainSceneController : MonoBehaviour
public int lastQCompleted; public int lastQCompleted;
public GameObject player; public GameObject player;
public GameObject shop; public GameObject shop;
public GameObject shopTabel;
public GameObject managers; public GameObject managers;
public GameObject saveGameManager; public GameObject saveGameManager;
public GameObject gamePlayUI; public GameObject gamePlayUI;
...@@ -26,7 +28,7 @@ public class MainSceneController : MonoBehaviour ...@@ -26,7 +28,7 @@ public class MainSceneController : MonoBehaviour
playerName = PlayerPrefs.HasKey("PlayerName") ? PlayerPrefs.GetString("PlayerName") : "Player"; playerName = PlayerPrefs.HasKey("PlayerName") ? PlayerPrefs.GetString("PlayerName") : "Player";
difficulty = PlayerPrefs.HasKey("Difficulty") ? PlayerPrefs.GetInt("Difficulty") : 0; difficulty = PlayerPrefs.HasKey("Difficulty") ? PlayerPrefs.GetInt("Difficulty") : 0;
gameState = new GameState(playerName, player.GetComponent<PlayerHealth>().maxHealth, lastQCompleted, difficulty); gameState = new GameState(playerName, player.GetComponent<PlayerHealth>().maxHealth, lastQCompleted, difficulty, shopTabel.GetComponent<Shop>().spawnedPets);
player.GetComponent<PlayerHealth>().difficulty = difficulty; player.GetComponent<PlayerHealth>().difficulty = difficulty;
...@@ -72,6 +74,10 @@ public class MainSceneController : MonoBehaviour ...@@ -72,6 +74,10 @@ public class MainSceneController : MonoBehaviour
Debug.Log("Game State PlayerHealth: " + saveData.gameState.playerHealth); Debug.Log("Game State PlayerHealth: " + saveData.gameState.playerHealth);
Debug.Log("Game State LastQuestIndex: " + saveData.gameState.lastQuestIndex); Debug.Log("Game State LastQuestIndex: " + saveData.gameState.lastQuestIndex);
Debug.Log("Game State Difficulty: " + saveData.gameState.difficulty); Debug.Log("Game State Difficulty: " + saveData.gameState.difficulty);
foreach (int pet in saveData.gameState.spawnedPets)
{
Debug.Log("Pet: " + pet);
}
if (saveData.gameState != null) if (saveData.gameState != null)
{ {
...@@ -81,11 +87,11 @@ public class MainSceneController : MonoBehaviour ...@@ -81,11 +87,11 @@ public class MainSceneController : MonoBehaviour
player.GetComponent<PlayerHealth>().SetHealth(gameState.playerHealth); player.GetComponent<PlayerHealth>().SetHealth(gameState.playerHealth);
managers.GetComponent<QuestManager>().SetQuestIndex(gameState.lastQuestIndex); managers.GetComponent<QuestManager>().SetQuestIndex(gameState.lastQuestIndex);
player.GetComponent<PlayerHealth>().difficulty = difficulty; player.GetComponent<PlayerHealth>().difficulty = difficulty;
shopTabel.GetComponent<Shop>().SpawnAllPets(gameState.spawnedPets);
} }
else else
{ {
Debug.Log("Game State is null."); Debug.Log("Game State is null.");
// Handle the case where the GameState object is null
} }
} }
} }
...@@ -108,10 +114,11 @@ public class MainSceneController : MonoBehaviour ...@@ -108,10 +114,11 @@ public class MainSceneController : MonoBehaviour
// Debug.Log("Saving Game State"); // Debug.Log("Saving Game State");
lastQCompleted = current; lastQCompleted = current;
gameState.SetPlayerHealth(player.GetComponent<PlayerHealth>().CurrentHealth); gameState.playerHealth = player.GetComponent<PlayerHealth>().CurrentHealth;
gameState.SetLastQuestIndex(lastQCompleted); gameState.lastQuestIndex = lastQCompleted;
gameState.SetPlayerName(playerName); gameState.playerName = playerName;
gameState.SetDifficulty(difficulty); gameState.difficulty = difficulty;
gameState.spawnedPets = shopTabel.GetComponent<Shop>().spawnedPets;
gameState.Print(); gameState.Print();
} }
......
...@@ -2,6 +2,7 @@ using UnityEngine; ...@@ -2,6 +2,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System; using System;
using TMPro; using TMPro;
using System.Collections.Generic;
[Serializable] [Serializable]
public class SaveData { public class SaveData {
...@@ -129,6 +130,10 @@ public class SaveGameManager : MonoBehaviour ...@@ -129,6 +130,10 @@ public class SaveGameManager : MonoBehaviour
Debug.Log("Game State PlayerHealth: " + currentGameData.playerHealth); Debug.Log("Game State PlayerHealth: " + currentGameData.playerHealth);
Debug.Log("Game State LastQuestIndex: " + currentGameData.lastQuestIndex); Debug.Log("Game State LastQuestIndex: " + currentGameData.lastQuestIndex);
Debug.Log("Game State Difficulty: " + currentGameData.difficulty); Debug.Log("Game State Difficulty: " + currentGameData.difficulty);
foreach (int pet in currentGameData.spawnedPets)
{
Debug.Log("Game State Pet: " + pet);
}
SaveData saveData = new SaveData(selectedSlot, fileName, DateTime.Now.ToString(), currentGameData); SaveData saveData = new SaveData(selectedSlot, fileName, DateTime.Now.ToString(), currentGameData);
string json = JsonUtility.ToJson(saveData); string json = JsonUtility.ToJson(saveData);
Debug.Log("JSON saved: " + json); Debug.Log("JSON saved: " + json);
......
...@@ -4,6 +4,7 @@ using UnityEngine.UI; ...@@ -4,6 +4,7 @@ using UnityEngine.UI;
using TMPro; using TMPro;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using System.Collections.Generic;
public class Shop : MonoBehaviour public class Shop : MonoBehaviour
{ {
...@@ -15,6 +16,8 @@ public class Shop : MonoBehaviour ...@@ -15,6 +16,8 @@ public class Shop : MonoBehaviour
private bool isPaused = false; private bool isPaused = false;
public PetSpawner petSpawner; public PetSpawner petSpawner;
public List<int> spawnedPets = new List<int>();
void Start() { void Start() {
popUp.SetActive(false); popUp.SetActive(false);
...@@ -57,9 +60,21 @@ public class Shop : MonoBehaviour ...@@ -57,9 +60,21 @@ public class Shop : MonoBehaviour
public void BuyJavier() { public void BuyJavier() {
petSpawner.SpawnJavier(); petSpawner.SpawnJavier();
spawnedPets.Add(0);
} }
public void BuyBagas() { public void BuyBagas() {
petSpawner.SpawnBagas(); petSpawner.SpawnBagas();
spawnedPets.Add(1);
}
public void SpawnAllPets(List<int> spawnedPets) {
foreach (int pet in spawnedPets) {
if (pet == 0) {
petSpawner.SpawnJavier();
} else if (pet == 1) {
petSpawner.SpawnBagas();
}
}
} }
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ TextureImporter: ...@@ -7,7 +7,7 @@ TextureImporter:
mipmaps: mipmaps:
mipMapMode: 0 mipMapMode: 0
enableMipMap: 1 enableMipMap: 1
sRGBTexture: 1 sRGBTexture: 0
linearTexture: 0 linearTexture: 0
fadeOut: 0 fadeOut: 0
borderMipMap: 0 borderMipMap: 0
...@@ -54,7 +54,7 @@ TextureImporter: ...@@ -54,7 +54,7 @@ TextureImporter:
alphaUsage: 1 alphaUsage: 1
alphaIsTransparency: 0 alphaIsTransparency: 0
spriteTessellationDetail: -1 spriteTessellationDetail: -1
textureType: 0 textureType: 1
textureShape: 1 textureShape: 1
singleChannelComponent: 0 singleChannelComponent: 0
flipbookRows: 1 flipbookRows: 1
...@@ -106,6 +106,32 @@ TextureImporter: ...@@ -106,6 +106,32 @@ TextureImporter:
ignorePlatformSupport: 0 ignorePlatformSupport: 0
androidETC2FallbackOverride: 0 androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0 forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet: spriteSheet:
serializedVersion: 2 serializedVersion: 2
sprites: [] sprites: []
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment