R1
This commit is contained in:
parent
37252a4edc
commit
19ab6f65e3
258 changed files with 406592 additions and 0 deletions
25
Assets/Scripts/Boussole.cs
Normal file
25
Assets/Scripts/Boussole.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Boussole : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject fire;
|
||||
public GameObject player;
|
||||
public GameObject encadrement;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 rot = Quaternion.FromToRotation(new Vector3(1, 0, 0), new Vector3(fire.transform.position.x - player.transform.position.x, fire.transform.position.y - player.transform.position.y, 0)).eulerAngles;
|
||||
rot.z -= 45;
|
||||
this.transform.rotation = Quaternion.Euler(rot);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Boussole.cs.meta
Normal file
11
Assets/Scripts/Boussole.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91377f2976743f3b2a52c42cdc062144
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/Scripts/CameraScript.cs
Normal file
17
Assets/Scripts/CameraScript.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CameraScript : MonoBehaviour
|
||||
{
|
||||
|
||||
public Material material;
|
||||
public FearLevel fear;
|
||||
|
||||
void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
material.SetFloat("_Fear", fear.GetFearLevel());
|
||||
// Copy the source Render Texture to the destination,
|
||||
// applying the material along the way.
|
||||
Graphics.Blit(source, destination, material);
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/CameraScript.cs.meta
Normal file
11
Assets/Scripts/CameraScript.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ab34ad7fcbc3f459fafd69546c95a4aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Scripts/CombustibleItem.cs
Normal file
40
Assets/Scripts/CombustibleItem.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class CombustibleItem
|
||||
{
|
||||
private float quantityOfEnergy;
|
||||
private Sprite sprite;
|
||||
private GameObject gameObject;
|
||||
|
||||
public CombustibleItem(float quantityOfEnergy, Sprite sprite)
|
||||
{
|
||||
this.quantityOfEnergy = quantityOfEnergy;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetQuantityOfEnergy(float quantityOfEnergy)
|
||||
{
|
||||
this.quantityOfEnergy = quantityOfEnergy;
|
||||
}
|
||||
|
||||
public float GetQuantityOfEnergy()
|
||||
{
|
||||
return this.quantityOfEnergy;
|
||||
}
|
||||
|
||||
public Sprite GetSprite()
|
||||
{
|
||||
return this.sprite;
|
||||
}
|
||||
|
||||
public void SetGameObject (GameObject gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
}
|
||||
|
||||
public GameObject GetGameObject ()
|
||||
{
|
||||
return this.gameObject;
|
||||
}
|
||||
}
|
11
Assets/Scripts/CombustibleItem.cs.meta
Normal file
11
Assets/Scripts/CombustibleItem.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07c157dcca9d944889fe20fc8cb7e94d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
5
Assets/Scripts/Direction.cs
Normal file
5
Assets/Scripts/Direction.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
using System;
|
||||
public enum Direction
|
||||
{
|
||||
UP = 0, DOWN = 1, LEFT = 3, RIGHT = 4, UP_LEFT = 5, UP_RIGHT = 6, DOWN_LEFT = 7, DOWN_RIGHT = 8
|
||||
}
|
11
Assets/Scripts/Direction.cs.meta
Normal file
11
Assets/Scripts/Direction.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e486829bde59b6926a2d32ea6ae2b969
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
53
Assets/Scripts/FearLevel.cs
Normal file
53
Assets/Scripts/FearLevel.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FearLevel : MonoBehaviour
|
||||
{
|
||||
private readonly int UP_SPEED = 2, DOWN_SPEED = 10;
|
||||
public GameObject fire, player;
|
||||
private float fearLevel = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Vector2.Distance(player.transform.position, fire.transform.position) < (fire.GetComponent<FireScript>().GetFireIntensity() / 5) || player.GetComponent<PlayerTorch>().TorchIsActive())
|
||||
{
|
||||
if (fearLevel <= 0) return;
|
||||
DecrementLevel(Time.deltaTime * DOWN_SPEED);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fearLevel >= 100)
|
||||
{
|
||||
Global.Dead();
|
||||
return;
|
||||
}
|
||||
IncrementLevel(Time.deltaTime * UP_SPEED);
|
||||
}
|
||||
Debug.Log(fearLevel + " " + fire.GetComponent<FireScript>().GetFireIntensity());
|
||||
}
|
||||
|
||||
public float GetFearLevel()
|
||||
{
|
||||
return fearLevel;
|
||||
}
|
||||
|
||||
public void DecrementLevel(float amount)
|
||||
{
|
||||
this.fearLevel -= amount;
|
||||
if (this.fearLevel < 0) this.fearLevel = 0;
|
||||
}
|
||||
|
||||
public void IncrementLevel(float amount)
|
||||
{
|
||||
this.fearLevel += amount;
|
||||
if (this.fearLevel > 100) this.fearLevel = 100;
|
||||
}
|
||||
}
|
11
Assets/Scripts/FearLevel.cs.meta
Normal file
11
Assets/Scripts/FearLevel.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2905f0663b6d6837ea139a66e358da05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/FearUI.cs
Normal file
20
Assets/Scripts/FearUI.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FearUI : MonoBehaviour
|
||||
{
|
||||
|
||||
public FearLevel fear;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
this.gameObject.transform.localScale = new Vector3(1 - fear.GetFearLevel() / 100.0f, this.gameObject.transform.localScale.y, this.gameObject.transform.localScale.z);
|
||||
}
|
||||
}
|
11
Assets/Scripts/FearUI.cs.meta
Normal file
11
Assets/Scripts/FearUI.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a279954becea8b25585e101da454e7ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/FireBack.cs
Normal file
21
Assets/Scripts/FireBack.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FireBack : MonoBehaviour
|
||||
{
|
||||
public Rain rain;
|
||||
public GameObject item;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (rain.IsRaining()) item.SetActive(true);
|
||||
else item.SetActive(false);
|
||||
}
|
||||
}
|
11
Assets/Scripts/FireBack.cs.meta
Normal file
11
Assets/Scripts/FireBack.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b0825ca1462f681989b4181ff4730073
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
147
Assets/Scripts/FireScript.cs
Normal file
147
Assets/Scripts/FireScript.cs
Normal file
|
@ -0,0 +1,147 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class FireScript : MonoBehaviour
|
||||
{
|
||||
public GameObject fire1, fire2, fire3, pointLight, fireGUI;
|
||||
public PlayerScript player;
|
||||
public readonly float NUMBER_OF_ENERGY_LOST_PER_SECOND = 1;
|
||||
public readonly float MAX_FIRE_INTENSITY = 100;
|
||||
public GameObject prefabsFireElement;
|
||||
public Rain rain;
|
||||
|
||||
public Sprite startUpSpriteCombustibleElement;
|
||||
public float startupCombustionEnergyElement = 100;
|
||||
|
||||
private PlayerScript playerTriggered;
|
||||
private Vector2 startScaleFire1, startScaleFire2, startScaleFire3, startFireGUI;
|
||||
private float startLightRange;
|
||||
private int startOrderFire1, startOrderFire2, startOrderFire3;
|
||||
private Light pLight;
|
||||
private List<CombustibleItem> combustibleItems = new List<CombustibleItem>();
|
||||
private bool playerHasFeared = false;
|
||||
private float ratioEnergyLostBooster = 1;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
startScaleFire1 = new Vector2(fire1.gameObject.transform.localScale.x, fire1.gameObject.transform.localScale.y);
|
||||
startScaleFire2 = new Vector2(fire2.gameObject.transform.localScale.x, fire2.gameObject.transform.localScale.y);
|
||||
startScaleFire3 = new Vector2(fire3.gameObject.transform.localScale.x, fire3.gameObject.transform.localScale.y);
|
||||
startFireGUI = new Vector2(fireGUI.gameObject.transform.localScale.x, fireGUI.gameObject.transform.localScale.y);
|
||||
pLight = pointLight.GetComponent<Light>();
|
||||
startOrderFire1 = fire1.GetComponent<Renderer>().sortingOrder;
|
||||
startOrderFire2 = fire2.GetComponent<Renderer>().sortingOrder;
|
||||
startOrderFire3 = fire3.GetComponent<Renderer>().sortingOrder;
|
||||
startLightRange = pLight.range;
|
||||
if (startUpSpriteCombustibleElement is Sprite) AddIntensity(new CombustibleItem[] { new CombustibleItem(startupCombustionEnergyElement, startUpSpriteCombustibleElement) });
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
ratioEnergyLostBooster = (rain.IsRaining()) ? 2 : 1;
|
||||
if (GetFireIntensity() > 0)
|
||||
{
|
||||
DecrementIntensity(Time.deltaTime * NUMBER_OF_ENERGY_LOST_PER_SECOND * ratioEnergyLostBooster);
|
||||
playerHasFeared = false;
|
||||
}
|
||||
else if (!playerHasFeared)
|
||||
{
|
||||
player.GetComponent<FearLevel>().IncrementLevel(50);
|
||||
foreach (CombustibleItem combustibleItem in combustibleItems)
|
||||
{
|
||||
Destroy(combustibleItem.GetGameObject());
|
||||
}
|
||||
combustibleItems.Clear();
|
||||
playerHasFeared = true;
|
||||
}
|
||||
float ratioFireIntensity = GetFireIntensity() / MAX_FIRE_INTENSITY;
|
||||
fire1.gameObject.transform.localScale = new Vector3(startScaleFire1.x * ratioFireIntensity, startScaleFire1.y * ratioFireIntensity, 0);
|
||||
fire2.gameObject.transform.localScale = new Vector3(startScaleFire2.x * ratioFireIntensity, startScaleFire2.y * ratioFireIntensity, 0);
|
||||
fire3.gameObject.transform.localScale = new Vector3(startScaleFire3.x * ratioFireIntensity, startScaleFire3.y * ratioFireIntensity, 0);
|
||||
fireGUI.gameObject.transform.localScale = new Vector3(startFireGUI.x * ratioFireIntensity, startFireGUI.y * ratioFireIntensity, 0);
|
||||
float newRange = startLightRange * ratioFireIntensity;
|
||||
pLight.range = newRange + (Mathf.Cos(Time.timeSinceLevelLoad * 8) * newRange * 0.01f);
|
||||
if (player.transform.position.y > transform.position.y * 2 + player.transform.localScale.y)
|
||||
{
|
||||
fire1.GetComponent<Renderer>().sortingOrder = startOrderFire1 + 100;
|
||||
fire2.GetComponent<Renderer>().sortingOrder = startOrderFire2 + 100;
|
||||
fire3.GetComponent<Renderer>().sortingOrder = startOrderFire3 + 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
fire1.GetComponent<Renderer>().sortingOrder = startOrderFire1;
|
||||
fire2.GetComponent<Renderer>().sortingOrder = startOrderFire2;
|
||||
fire3.GetComponent<Renderer>().sortingOrder = startOrderFire3;
|
||||
}
|
||||
|
||||
if (playerTriggered is PlayerScript)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) || Manette.IsUse())
|
||||
{
|
||||
AddIntensity(playerTriggered.BurnObjects(MAX_FIRE_INTENSITY - GetFireIntensity()));
|
||||
playerTriggered = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddIntensity (CombustibleItem[] combustibleItems)
|
||||
{
|
||||
for (int i = 0; i < combustibleItems.Length; i++)
|
||||
{
|
||||
GameObject go = Instantiate(prefabsFireElement, this.transform.position, Quaternion.Euler(0, 0, Random.Range(0, 360)));
|
||||
go.GetComponent<SpriteRenderer>().sprite = combustibleItems[i].GetSprite();
|
||||
combustibleItems[i].SetGameObject(go);
|
||||
this.combustibleItems.Add(combustibleItems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void DecrementIntensity (float intensity)
|
||||
{
|
||||
if (this.combustibleItems.Count == 0) return;
|
||||
if (GetFireIntensity() < intensity) intensity = GetFireIntensity();
|
||||
float intensityLeft = this.combustibleItems[0].GetQuantityOfEnergy() - intensity;
|
||||
if (intensityLeft <= 0)
|
||||
{
|
||||
Destroy(this.combustibleItems[0].GetGameObject());
|
||||
this.combustibleItems.RemoveAt(0);
|
||||
if (this.combustibleItems.Count > 0)
|
||||
{
|
||||
this.combustibleItems[0].SetQuantityOfEnergy(this.combustibleItems[0].GetQuantityOfEnergy() + intensityLeft);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.combustibleItems[0].SetQuantityOfEnergy(intensityLeft);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetFireIntensity ()
|
||||
{
|
||||
float t = 0;
|
||||
foreach (CombustibleItem c in this.combustibleItems)
|
||||
{
|
||||
t += c.GetQuantityOfEnergy();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = c.gameObject.GetComponent<PlayerScript>();
|
||||
playerTriggered.SetInteractMessage(true, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = null;
|
||||
c.gameObject.GetComponent<PlayerScript>().SetInteractMessage(false, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/FireScript.cs.meta
Normal file
11
Assets/Scripts/FireScript.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f71a09b81bfac21c080289a73431ec6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
Assets/Scripts/GameOverMenu.cs
Normal file
30
Assets/Scripts/GameOverMenu.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameOverMenu : MonoBehaviour
|
||||
{
|
||||
public Button replayButton;
|
||||
public Button exitButton;
|
||||
public Text scoreText;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
replayButton.onClick.AddListener(onReplayButtonClick);
|
||||
exitButton.onClick.AddListener(onExitButtonClick);
|
||||
scoreText.text = PlayerPrefs.GetInt("previous_score", 0).ToString();
|
||||
}
|
||||
|
||||
void onReplayButtonClick()
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
|
||||
void onExitButtonClick()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameOverMenu.cs.meta
Normal file
11
Assets/Scripts/GameOverMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c43f7437e2bb041e28c5d4261c28b8e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Assets/Scripts/Global.cs
Normal file
23
Assets/Scripts/Global.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Global
|
||||
{
|
||||
public static PlayerScript player;
|
||||
|
||||
public static void Dead ()
|
||||
{
|
||||
if (PlayerPrefs.HasKey("best_score"))
|
||||
{
|
||||
if (player.GetScore() > PlayerPrefs.GetInt("best_score")) PlayerPrefs.SetInt("best_score", player.GetScore());
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerPrefs.SetInt("best_score", player.GetScore());
|
||||
}
|
||||
|
||||
PlayerPrefs.SetInt("previous_score", player.GetScore());
|
||||
|
||||
SceneManager.LoadScene(2);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Global.cs.meta
Normal file
11
Assets/Scripts/Global.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f3cecc073330689792476e9cb842f6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Scripts/MainMenu.cs
Normal file
40
Assets/Scripts/MainMenu.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public Button playButton;
|
||||
public Button exitButton;
|
||||
public Button helpButton;
|
||||
public GameObject helpCanvas;
|
||||
public Text bestScoreText;
|
||||
|
||||
private bool helpCanvasVisible = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
playButton.onClick.AddListener(OnPlayButtonClick);
|
||||
exitButton.onClick.AddListener(OnExitButtonClick);
|
||||
helpButton.onClick.AddListener(OnHelpButtonClick);
|
||||
bestScoreText.text = PlayerPrefs.GetInt("best_score", 0).ToString();
|
||||
}
|
||||
|
||||
void OnPlayButtonClick()
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
|
||||
void OnExitButtonClick()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
void OnHelpButtonClick()
|
||||
{
|
||||
helpCanvasVisible = !helpCanvasVisible;
|
||||
helpCanvas.SetActive(helpCanvasVisible);
|
||||
}
|
||||
}
|
11
Assets/Scripts/MainMenu.cs.meta
Normal file
11
Assets/Scripts/MainMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1851456cc76e90648dc0f3ab2a3b6f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Assets/Scripts/Manette.cs
Normal file
76
Assets/Scripts/Manette.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Manette
|
||||
{
|
||||
public static bool IsUp ()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
float value = Input.GetAxis("Vertical");
|
||||
if (value > 0.01) return true;
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsDown()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
float value = Input.GetAxis("Vertical");
|
||||
if (value < -0.01) return true;
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsRight()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
float value = Input.GetAxis("Horizontal");
|
||||
if (value > 0.01) return true;
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsLeft()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
float value = Input.GetAxis("Horizontal");
|
||||
if (value < -0.01) return true;
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsUse()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
return Input.GetButtonDown("Fire1");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsTorch()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
return Input.GetButtonDown("Fire2");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsPlaceBlock()
|
||||
{
|
||||
if (Input.GetJoystickNames().Length > 0)
|
||||
{
|
||||
return Input.GetButtonDown("Space");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Manette.cs.meta
Normal file
11
Assets/Scripts/Manette.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c3b42952f5191dcf85fbe0c7ff3e010
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
153
Assets/Scripts/Ogres.cs
Normal file
153
Assets/Scripts/Ogres.cs
Normal file
|
@ -0,0 +1,153 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Ogres : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public GameObject fire;
|
||||
private float SPEED = 1;
|
||||
|
||||
private Direction currentDirection = Direction.DOWN;
|
||||
private Animator animator;
|
||||
private PlayerScript playerScript;
|
||||
private Vector2 currentDestination;
|
||||
private bool isAggro = false;
|
||||
private bool fireSpotted = false;
|
||||
private readonly int DISTANCE_TO_SPOT = 15;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
playerScript = player.GetComponent<PlayerScript>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
CheckAggro();
|
||||
Vector2 direction = GetDirectionFromDestination(GetDestination());
|
||||
if (direction.y > 0.1f && direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkLeft", 0);
|
||||
currentDirection = Direction.UP_LEFT;
|
||||
}
|
||||
else if (direction.y > 0.1f && direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkRight", 0);
|
||||
currentDirection = Direction.UP_RIGHT;
|
||||
}
|
||||
else if (direction.y < -0.1f && direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkLeft", 0);
|
||||
currentDirection = Direction.DOWN_LEFT;
|
||||
}
|
||||
else if (direction.y < -0.1f && direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkRight", 0);
|
||||
currentDirection = Direction.DOWN_RIGHT;
|
||||
}
|
||||
else if (direction.y > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkUp", 0);
|
||||
currentDirection = Direction.UP;
|
||||
}
|
||||
else if (direction.y < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y - SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkDown", 0);
|
||||
currentDirection = Direction.DOWN;
|
||||
}
|
||||
else if (direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkLeft", 0);
|
||||
currentDirection = Direction.LEFT;
|
||||
}
|
||||
else if (direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("OgresWalkRight", 0);
|
||||
currentDirection = Direction.RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentDirection == Direction.DOWN)
|
||||
{
|
||||
animator.Play("OgresStopDown", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.UP)
|
||||
{
|
||||
animator.Play("OgresStopUp", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.LEFT || currentDirection == Direction.UP_LEFT || currentDirection == Direction.DOWN_LEFT)
|
||||
{
|
||||
animator.Play("OgresStopLeft", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.RIGHT || currentDirection == Direction.UP_RIGHT || currentDirection == Direction.DOWN_RIGHT)
|
||||
{
|
||||
animator.Play("OgresStopRight", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.Play("OgresStopDown", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckAggro()
|
||||
{
|
||||
if (Vector2.Distance(this.transform.position, player.transform.position) < DISTANCE_TO_SPOT)
|
||||
{
|
||||
isAggro = true;
|
||||
}
|
||||
|
||||
if (Vector2.Distance(this.transform.position, fire.transform.position) < DISTANCE_TO_SPOT)
|
||||
{
|
||||
fireSpotted = true;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 GetDestination()
|
||||
{
|
||||
if (!fireSpotted)
|
||||
{
|
||||
if (!isAggro)
|
||||
{
|
||||
if (Vector2.Distance(this.transform.position, currentDestination) < 4)
|
||||
{
|
||||
currentDestination = new Vector2(Random.Range(-20, 20), Random.Range(-20, 20));
|
||||
}
|
||||
return currentDestination;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector2.Distance(this.transform.position, player.transform.position) > DISTANCE_TO_SPOT * 5)
|
||||
{
|
||||
isAggro = false;
|
||||
}
|
||||
return player.transform.position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector2.Distance(this.transform.position, fire.transform.position) < 4)
|
||||
{
|
||||
fire.GetComponent<FireScript>().DecrementIntensity(100);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
return fire.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 GetDirectionFromDestination(Vector2 destination)
|
||||
{
|
||||
return new Vector2(destination.x - transform.position.x, destination.y - transform.position.y);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Ogres.cs.meta
Normal file
11
Assets/Scripts/Ogres.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c8d4f1aa21c57c169badfef829951645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
125
Assets/Scripts/Ours.cs
Normal file
125
Assets/Scripts/Ours.cs
Normal file
|
@ -0,0 +1,125 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Ours : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public GameObject tent;
|
||||
public float SPEED = 1;
|
||||
|
||||
private Direction currentDirection = Direction.DOWN;
|
||||
private Animator animator;
|
||||
private PlayerScript playerScript;
|
||||
private Vector2 currentDestination;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
playerScript = player.GetComponent<PlayerScript>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector2 direction = GetDirectionFromDestination(GetDestination());
|
||||
|
||||
if (direction.y > 0.1f && direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkLeft", 0);
|
||||
currentDirection = Direction.UP_LEFT;
|
||||
}
|
||||
else if (direction.y > 0.1f && direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkRight", 0);
|
||||
currentDirection = Direction.UP_RIGHT;
|
||||
}
|
||||
else if (direction.y < -0.1f && direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkLeft", 0);
|
||||
currentDirection = Direction.DOWN_LEFT;
|
||||
}
|
||||
else if (direction.y < -0.1f && direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkRight", 0);
|
||||
currentDirection = Direction.DOWN_RIGHT;
|
||||
}
|
||||
else if (direction.y > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkUp", 0);
|
||||
currentDirection = Direction.UP;
|
||||
}
|
||||
else if (direction.y < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y - SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkDown", 0);
|
||||
currentDirection = Direction.DOWN;
|
||||
}
|
||||
else if (direction.x < -0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkLeft", 0);
|
||||
currentDirection = Direction.LEFT;
|
||||
}
|
||||
else if (direction.x > 0.1f)
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("OursWalkRight", 0);
|
||||
currentDirection = Direction.RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentDirection == Direction.DOWN)
|
||||
{
|
||||
animator.Play("OursStopDown", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.UP)
|
||||
{
|
||||
animator.Play("OursStopUp", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.LEFT || currentDirection == Direction.UP_LEFT || currentDirection == Direction.DOWN_LEFT)
|
||||
{
|
||||
animator.Play("OursStopLeft", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.RIGHT || currentDirection == Direction.UP_RIGHT || currentDirection == Direction.DOWN_RIGHT)
|
||||
{
|
||||
animator.Play("OursStopRight", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.Play("OursStopDown", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 GetDestination()
|
||||
{
|
||||
if (playerScript.GetNumberOfWood() > 0 && !tent.GetComponent<Tent>().playerIsSafe())
|
||||
{
|
||||
if (Vector2.Distance(this.transform.position, player.transform.position) < 4)
|
||||
{
|
||||
playerScript.BurnObjects(1000);
|
||||
this.GetComponent<AudioSource>().Play();
|
||||
player.GetComponent<FearLevel>().IncrementLevel(10);
|
||||
playerScript.EmitHurtParticle();
|
||||
}
|
||||
return player.transform.position;
|
||||
}
|
||||
if (Vector2.Distance(this.transform.position, currentDestination) < 4)
|
||||
{
|
||||
currentDestination = new Vector2(Random.Range(-20, 20), Random.Range(-20, 20));
|
||||
}
|
||||
return currentDestination;
|
||||
}
|
||||
|
||||
Vector2 GetDirectionFromDestination (Vector2 destination)
|
||||
{
|
||||
return new Vector2(destination.x - transform.position.x, destination.y - transform.position.y);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Ours.cs.meta
Normal file
11
Assets/Scripts/Ours.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 508c99386e48a6450a61eca169bee5fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/PickableObject.cs
Normal file
45
Assets/Scripts/PickableObject.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PickableObject : MonoBehaviour
|
||||
{
|
||||
private PlayerScript playerTriggered;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (playerTriggered is PlayerScript)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) || Manette.IsUse())
|
||||
{
|
||||
if (playerTriggered.PickupObject(new CombustibleItem(Random.Range(0,10), GetComponent<SpriteRenderer>().sprite))) Destroy(this.gameObject);
|
||||
playerTriggered = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = c.gameObject.GetComponent<PlayerScript>();
|
||||
playerTriggered.SetInteractMessage(true, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = null;
|
||||
c.gameObject.GetComponent<PlayerScript>().SetInteractMessage(false, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/PickableObject.cs.meta
Normal file
11
Assets/Scripts/PickableObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 39e42cb302f87a470851c82d938c8d5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
186
Assets/Scripts/PlayerScript.cs
Normal file
186
Assets/Scripts/PlayerScript.cs
Normal file
|
@ -0,0 +1,186 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerScript : MonoBehaviour
|
||||
{
|
||||
public int SPEED = 10;
|
||||
public GameObject interactMessage;
|
||||
public Text text;
|
||||
public ParticleSystem hurt;
|
||||
|
||||
public GameObject wall;
|
||||
|
||||
private Direction currentDirection = Direction.DOWN;
|
||||
private Animator animator;
|
||||
private List<CombustibleItem> selectedCombustibleItem = new List<CombustibleItem>();
|
||||
public int score = 0;
|
||||
public float previousTime = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Global.player = this;
|
||||
animator = GetComponent<Animator>();
|
||||
previousTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Time.realtimeSinceStartup - previousTime > 1.0f)
|
||||
{
|
||||
score++;
|
||||
previousTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
text.text = "Bois : " + selectedCombustibleItem.Count;
|
||||
if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.Z) || Manette.IsUp()) && (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A) || Manette.IsLeft()))
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkLeft", 0);
|
||||
currentDirection = Direction.UP_LEFT;
|
||||
}
|
||||
else if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.Z) || Manette.IsUp()) && (Input.GetKey(KeyCode.D) || Manette.IsRight()))
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkRight", 0);
|
||||
currentDirection = Direction.UP_RIGHT;
|
||||
}
|
||||
else if ((Input.GetKey(KeyCode.S) || Manette.IsDown()) && (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A) || Manette.IsLeft()))
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkLeft", 0);
|
||||
currentDirection = Direction.DOWN_LEFT;
|
||||
}
|
||||
else if ((Input.GetKey(KeyCode.S) || Manette.IsDown()) && (Input.GetKey(KeyCode.D) || Manette.IsRight()))
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.y - SPEED * Time.deltaTime * 0.70710678118655f, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkRight", 0);
|
||||
currentDirection = Direction.DOWN_RIGHT;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.Z) || Manette.IsUp())
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkUp", 0);
|
||||
currentDirection = Direction.UP;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.S) || Manette.IsDown())
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y - SPEED * Time.deltaTime, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkDown", 0);
|
||||
currentDirection = Direction.DOWN;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A) || Manette.IsLeft())
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x - SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkLeft", 0);
|
||||
currentDirection = Direction.LEFT;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.D) || Manette.IsRight())
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + SPEED * Time.deltaTime, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
|
||||
animator.Play("PlayerWalkRight", 0);
|
||||
currentDirection = Direction.RIGHT;
|
||||
}
|
||||
else if ((Input.GetKey(KeyCode.Space) || Manette.IsPlaceBlock()) && this.selectedCombustibleItem.Count >= 30)
|
||||
{
|
||||
this.BurnObjects(300);
|
||||
Vector3 objectPlacement = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y, 0);
|
||||
|
||||
switch (currentDirection)
|
||||
{
|
||||
case Direction.LEFT:
|
||||
objectPlacement.x--;
|
||||
break;
|
||||
case Direction.RIGHT:
|
||||
objectPlacement.x++;
|
||||
break;
|
||||
case Direction.UP:
|
||||
objectPlacement.y++;
|
||||
break;
|
||||
case Direction.DOWN:
|
||||
objectPlacement.y--;
|
||||
break;
|
||||
}
|
||||
|
||||
Instantiate(wall, objectPlacement, Quaternion.identity);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentDirection == Direction.DOWN)
|
||||
{
|
||||
animator.Play("PlayerStopDown", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.UP)
|
||||
{
|
||||
animator.Play("PlayerStopUp", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.LEFT || currentDirection == Direction.UP_LEFT || currentDirection == Direction.DOWN_LEFT)
|
||||
{
|
||||
animator.Play("PlayerStopLeft", 0);
|
||||
}
|
||||
else if (currentDirection == Direction.RIGHT || currentDirection == Direction.UP_RIGHT || currentDirection == Direction.DOWN_RIGHT)
|
||||
{
|
||||
animator.Play("PlayerStopRight", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.Play("PlayerStopDown", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PickupObject (CombustibleItem combustibleItem)
|
||||
{
|
||||
score += (int)combustibleItem.GetQuantityOfEnergy();
|
||||
GetComponent<AudioSource>().Play();
|
||||
if (this.selectedCombustibleItem.Count < 30)
|
||||
{
|
||||
this.selectedCombustibleItem.Add(combustibleItem);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetNumberOfWood ()
|
||||
{
|
||||
return selectedCombustibleItem.Count;
|
||||
}
|
||||
|
||||
public CombustibleItem[] BurnObjects(float leftIntensity)
|
||||
{
|
||||
List<CombustibleItem> combustibles = new List<CombustibleItem>();
|
||||
foreach (CombustibleItem combustibleItem in selectedCombustibleItem)
|
||||
{
|
||||
if (leftIntensity < combustibleItem.GetQuantityOfEnergy()) break;
|
||||
leftIntensity -= combustibleItem.GetQuantityOfEnergy();
|
||||
combustibles.Add(combustibleItem);
|
||||
}
|
||||
foreach (CombustibleItem c in combustibles)
|
||||
{
|
||||
selectedCombustibleItem.Remove(c);
|
||||
}
|
||||
return combustibles.ToArray();
|
||||
}
|
||||
|
||||
public void SetInteractMessage(bool visible, string tag)
|
||||
{
|
||||
if (interactMessage is GameObject) interactMessage.SetActive(visible);
|
||||
if (tag is string) interactMessage.GetComponent<Text>().text = "Press E to interact with " + tag;
|
||||
}
|
||||
|
||||
public void EmitHurtParticle()
|
||||
{
|
||||
score -= 100;
|
||||
hurt.Play();
|
||||
}
|
||||
|
||||
public int GetScore ()
|
||||
{
|
||||
return this.score;
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerScript.cs.meta
Normal file
11
Assets/Scripts/PlayerScript.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 557bdfe4cbe3a40cc80469689b8bf691
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Scripts/PlayerTorch.cs
Normal file
40
Assets/Scripts/PlayerTorch.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerTorch : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject torch;
|
||||
private float previousTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
previousTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if ((Input.GetKeyDown(KeyCode.F) || Manette.IsTorch()) && GetComponent<PlayerScript>().GetNumberOfWood() > 0)
|
||||
{
|
||||
torch.SetActive(!torch.active);
|
||||
}
|
||||
if (Time.realtimeSinceStartup - previousTime > 1.0f && torch.active)
|
||||
{
|
||||
GetComponent<PlayerScript>().BurnObjects(10);
|
||||
previousTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
if (GetComponent<PlayerScript>().GetNumberOfWood() <= 0)
|
||||
{
|
||||
torch.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TorchIsActive ()
|
||||
{
|
||||
return torch.active;
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerTorch.cs.meta
Normal file
11
Assets/Scripts/PlayerTorch.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9760a960b14e61496abdf232e0dbb92d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
38
Assets/Scripts/Rain.cs
Normal file
38
Assets/Scripts/Rain.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Rain : MonoBehaviour
|
||||
{
|
||||
ParticleSystem particle;
|
||||
public float time = 0, updateTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
particle = GetComponent<ParticleSystem>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (updateTime > Time.realtimeSinceStartup) return;
|
||||
updateTime = Time.realtimeSinceStartup + 1;
|
||||
if (!particle.isPlaying && Random.value > 0.98)
|
||||
{
|
||||
particle.Play();
|
||||
time = Time.realtimeSinceStartup;
|
||||
time += Random.Range(10, 30);
|
||||
Debug.Log("Start Rain : " + (time - Time.realtimeSinceStartup));
|
||||
}
|
||||
else if (particle.isPlaying && time < Time.realtimeSinceStartup)
|
||||
{
|
||||
particle.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRaining()
|
||||
{
|
||||
return particle.isPlaying;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Rain.cs.meta
Normal file
11
Assets/Scripts/Rain.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d4903f4ed9c5ae5a8eef9b8b3ea993d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
86
Assets/Scripts/RandomSpawner.cs
Normal file
86
Assets/Scripts/RandomSpawner.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RandomSpawner : MonoBehaviour
|
||||
{
|
||||
public GameObject player, fire;
|
||||
public GameObject prefabBois, prefabTree;
|
||||
|
||||
public GameObject prefabTent;
|
||||
|
||||
public GameObject prefabMobBear, prefabMobOgre;
|
||||
|
||||
|
||||
|
||||
public UnityEngine.Tilemaps.Tilemap tileMap;
|
||||
public UnityEngine.Tilemaps.TileBase tileSprite;
|
||||
|
||||
private List<Vector2> treePositionList;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
this.treePositionList = new List<Vector2>();
|
||||
|
||||
GameObject prefabTentInstance = Instantiate(prefabTent,
|
||||
new Vector3(UnityEngine.Random.Range(-50, 50), UnityEngine.Random.Range(-50, 50), 0),
|
||||
Quaternion.identity);
|
||||
prefabTentInstance.GetComponent<Tent>().player = player;
|
||||
|
||||
GameObject prefabMobOgreInstance = Instantiate(prefabMobOgre,
|
||||
new Vector3(UnityEngine.Random.Range(-500, 500), UnityEngine.Random.Range(-500, 500), 0),
|
||||
Quaternion.identity);
|
||||
prefabMobOgreInstance.GetComponent<Ogres>().player = player;
|
||||
prefabMobOgreInstance.GetComponent<Ogres>().fire = fire;
|
||||
|
||||
for (int i = 0; i < UnityEngine.Random.Range(4, 10); i++)
|
||||
{
|
||||
GameObject prefabMobBearInstance = Instantiate(prefabMobBear,
|
||||
new Vector3(UnityEngine.Random.Range(-500, 500), UnityEngine.Random.Range(-500, 500), 0),
|
||||
Quaternion.identity);
|
||||
prefabMobBearInstance.GetComponent<Ours>().player = player;
|
||||
prefabMobBearInstance.GetComponent<Ours>().tent = prefabTentInstance;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
float playerX = player.gameObject.transform.position.x;
|
||||
float playerY = player.gameObject.transform.position.y;
|
||||
|
||||
float ratio = 1.5f;
|
||||
|
||||
for (int xIterator = -50; xIterator < 50; xIterator++)
|
||||
{
|
||||
for (int yIterator = -50; yIterator < 50; yIterator++)
|
||||
{
|
||||
float objectX = playerX + xIterator;
|
||||
float objectY = playerY + yIterator;
|
||||
|
||||
if (tileMap.GetTile(new Vector3Int((int)objectX, (int)objectY, 0)) == null)
|
||||
{
|
||||
tileMap.SetTile(new Vector3Int((int)objectX, (int)objectY, 0), tileSprite);
|
||||
}
|
||||
|
||||
Vector2 treePosition = new Vector2((int)objectX, (int)objectY);
|
||||
|
||||
if (Mathf.PerlinNoise(objectX * ratio, objectY * ratio) > 0.95 &&
|
||||
treePositionList.FindIndex(pos => ( pos.x == treePosition.x && pos.y == treePosition.y ) ) == -1 &&
|
||||
Math.Abs(objectX) > 4 && Math.Abs(objectY) > 4)
|
||||
{
|
||||
treePositionList.Add(treePosition);
|
||||
|
||||
float perlinNoise = Mathf.PerlinNoise(xIterator * ratio, yIterator * ratio);
|
||||
float p = UnityEngine.Random.value;
|
||||
GameObject g = Instantiate(p > 0.75 ? prefabTree : prefabBois,
|
||||
new Vector3(objectX, objectY, 0),
|
||||
p > 0.75 ? Quaternion.identity : Quaternion.Euler(0, 0, UnityEngine.Random.Range(0, 360)));
|
||||
g.GetComponent<SpriteRenderer>().flipX = p > 0.80;
|
||||
if (p > 0.75) g.GetComponent<TreeScript>().player = player.GetComponent<PlayerScript>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/RandomSpawner.cs.meta
Normal file
11
Assets/Scripts/RandomSpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 528da985c2c58d3ba8a5b7fdf4596ed1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/Tent.cs
Normal file
45
Assets/Scripts/Tent.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Tent : MonoBehaviour
|
||||
{
|
||||
public int protectionZone = 10;
|
||||
public int houseLevel = 15;
|
||||
public GameObject player;
|
||||
public Sprite maison;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool playerIsSafe()
|
||||
{
|
||||
return Vector2.Distance(this.transform.position, player.transform.position) < this.GetComponent<Tent>().protectionZone;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Vector2.Distance(player.transform.position, this.transform.position) < this.protectionZone &&
|
||||
player.GetComponent<PlayerScript>().GetNumberOfWood() >= 30)
|
||||
{
|
||||
player.GetComponent<PlayerScript>().SetInteractMessage(true, protectionZone >= houseLevel ? "maison" : "tente");
|
||||
|
||||
if (Input.GetKey(KeyCode.E) || Manette.IsUse())
|
||||
{
|
||||
player.GetComponent<PlayerScript>().SetInteractMessage(false, "");
|
||||
player.GetComponent<PlayerScript>().BurnObjects(300);
|
||||
protectionZone += 1;
|
||||
|
||||
if (protectionZone >= houseLevel)
|
||||
{
|
||||
this.GetComponent<SpriteRenderer>().sprite = maison;
|
||||
this.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tent.cs.meta
Normal file
11
Assets/Scripts/Tent.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e2eadae0263f614a9e093d10c4bccf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
92
Assets/Scripts/TreeScript.cs
Normal file
92
Assets/Scripts/TreeScript.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TreeScript : MonoBehaviour
|
||||
{
|
||||
public GameObject prefabBois;
|
||||
public int life = 5;
|
||||
public GameObject spawn;
|
||||
public PlayerScript player;
|
||||
|
||||
private PlayerScript playerTriggered;
|
||||
private bool isAlreadySpawn = false;
|
||||
private int startupOrder;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
startupOrder = this.GetComponent<Renderer>().sortingOrder;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (playerTriggered is PlayerScript)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) || Manette.IsUse())
|
||||
{
|
||||
if (--life <= 0)
|
||||
{
|
||||
int n = (int)Random.Range(2, 6);
|
||||
SpawnLoot(n);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
this.GetComponent<AudioSource>().Play();
|
||||
}
|
||||
}
|
||||
|
||||
if ((((int)Time.realtimeSinceStartup) % 2) == 0)
|
||||
{
|
||||
float p = Random.value;
|
||||
if (p < .005f && !isAlreadySpawn)
|
||||
{
|
||||
SpawnLoot(1);
|
||||
isAlreadySpawn = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isAlreadySpawn = false;
|
||||
}
|
||||
|
||||
if (player.transform.position.y > transform.position.y * 2 + player.transform.localScale.y)
|
||||
{
|
||||
this.GetComponent<Renderer>().sortingOrder = startupOrder + 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GetComponent<Renderer>().sortingOrder = startupOrder;
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnLoot (int n)
|
||||
{
|
||||
float x = spawn.gameObject.transform.position.x;
|
||||
float y = spawn.gameObject.transform.position.y;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
float nx = Random.Range(x - 0.5f, x + 0.5f);
|
||||
float ny = Random.Range(y - 0.5f, y + 0.5f);
|
||||
Instantiate(prefabBois, new Vector3(nx, ny, 0), Quaternion.Euler(0, 0, Random.Range(0, 360)));
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = c.gameObject.GetComponent<PlayerScript>();
|
||||
playerTriggered.SetInteractMessage(true, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D c)
|
||||
{
|
||||
if (c.gameObject.tag.Equals("Player"))
|
||||
{
|
||||
playerTriggered = null;
|
||||
c.gameObject.GetComponent<PlayerScript>().SetInteractMessage(false, this.gameObject.tag);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/TreeScript.cs.meta
Normal file
11
Assets/Scripts/TreeScript.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 15185681bc46576c1a8270ee81ff4488
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/UpdateScoreGame.cs
Normal file
20
Assets/Scripts/UpdateScoreGame.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UpdateScoreGame : MonoBehaviour
|
||||
{
|
||||
public PlayerScript player;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
GetComponent<Text>().text = "Score: " + player.GetScore();
|
||||
}
|
||||
}
|
11
Assets/Scripts/UpdateScoreGame.cs.meta
Normal file
11
Assets/Scripts/UpdateScoreGame.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a327b920fb2d86c98e4733f45b706e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue