Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 222 additions and 43 deletions
...@@ -6,7 +6,7 @@ using UnityEngine; ...@@ -6,7 +6,7 @@ using UnityEngine;
public class Item : ScriptableObject { public class Item : ScriptableObject {
public int id; public int id;
public string name; public string nom;
public string description; public string description;
public Sprite image; public Sprite image;
......
...@@ -15,9 +15,12 @@ public class PlayerMovement : MonoBehaviour ...@@ -15,9 +15,12 @@ public class PlayerMovement : MonoBehaviour
{ {
public float speed; public float speed;
private Rigidbody2D myRigidbody; private Rigidbody2D myRigidbody;
private Vector3 change; private Vector2 moveDirection;
private Animator animator; private Animator animator;
public PlayerState currentState; public PlayerState currentState;
public GameObject player;
public bool[] ispassed;
public int stage;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -26,45 +29,51 @@ public class PlayerMovement : MonoBehaviour ...@@ -26,45 +29,51 @@ public class PlayerMovement : MonoBehaviour
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>(); myRigidbody = GetComponent<Rigidbody2D>();
animator.SetFloat("moveX", 0); animator.SetFloat("moveX", 0);
animator.SetFloat("moveY", -1); animator.SetFloat("moveY", -1);
ispassed = new bool[] { false, false, false, false };
stage = 0;
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
ProcessInputs();
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal");
change.y = Input.GetAxisRaw("Vertical");
if(currentState == PlayerState.walk) if(currentState == PlayerState.walk)
{ {
UpdateAnimationAndMove(); UpdateAnimationAndMove();
} }
Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
pos.x = Mathf.Clamp01(pos.x); pos.x = Mathf.Clamp01(pos.x);
pos.y = Mathf.Clamp01(pos.y); pos.y = Mathf.Clamp01(pos.y);
transform.position = Camera.main.ViewportToWorldPoint(pos); transform.position = Camera.main.ViewportToWorldPoint(pos);
gameIntelligence();
}
private void FixedUpdate()
{
moveDirection.Normalize();
myRigidbody.velocity = new Vector2(moveDirection.x * speed, moveDirection.y * speed);
} }
void MoveCharacter() private void ProcessInputs()
{ {
change.Normalize(); float moveX = Input.GetAxisRaw("Horizontal");
myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime); float moveY = Input.GetAxisRaw("Vertical");
moveDirection = new Vector2(moveX, moveY);
} }
void UpdateAnimationAndMove() void UpdateAnimationAndMove()
{ {
if (change != Vector3.zero) if (moveDirection != Vector2.zero)
{ {
MoveCharacter();
animator.SetFloat("moveX", change.x); animator.SetFloat("moveX", moveDirection.x);
animator.SetFloat("moveY", change.y); animator.SetFloat("moveY", moveDirection.y);
animator.SetBool("moving", true); animator.SetBool("moving", true);
} }
...@@ -72,6 +81,49 @@ public class PlayerMovement : MonoBehaviour ...@@ -72,6 +81,49 @@ public class PlayerMovement : MonoBehaviour
{ {
animator.SetBool("moving", false); animator.SetBool("moving", false);
} }
}
void gameIntelligence()
{
if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 0)
{
GenerateMap.instance.generateBoutique(0, 0, "chaussure");
stage++;
}
else if (stage == 1 && ispassed[0] == true)
{
GenerateMap.instance.generateUsine(0, 1);
stage++;
}
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 2)
{
GenerateMap.instance.generateBoutique(0, 2, "baton");
stage++;
}
else if (stage == 3 && ispassed[1] == true)
{
GenerateMap.instance.generateUsine(1, 1);
stage++;
}
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 4)
{
GenerateMap.instance.generateBoutique(1, 2, "rechaud");
stage++;
}
else if (stage == 5 && ispassed[2] == true)
{
GenerateMap.instance.generateUsine(2, 0);
stage++;
}
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 6)
{
GenerateMap.instance.generateBoutique(2, 1, "tente");
stage++;
}
else if (stage == 7 && ispassed[3] == true)
{
GenerateMap.instance.generateUsine(1, 0);
//stage++;
}
} }
} }
...@@ -44,16 +44,13 @@ public class PlayerNature : MonoBehaviour ...@@ -44,16 +44,13 @@ public class PlayerNature : MonoBehaviour
void Update() void Update()
{ {
//toutes les x secondes => on perd un certain nombre de secondes ////toutes les x secondes => on perd un certain nombre de secondes
if (Time.time > nextActionTime) //if (Time.time > nextActionTime)
{ //{
nextActionTime += period; // nextActionTime += period;
this.LooseNature(this.TimeDamage);
}
if (this.currentNature < 0) // this.LooseNature(this.TimeDamage);
GameOver(); //}
} }
// Perd un certain nombre de points de nature // Perd un certain nombre de points de nature
...@@ -72,18 +69,13 @@ public class PlayerNature : MonoBehaviour ...@@ -72,18 +69,13 @@ public class PlayerNature : MonoBehaviour
{ {
this.currentNature += bonus; this.currentNature += bonus;
this.natureBar.SetValue(this.currentNature); if (this.currentNature >= 100)
} this.currentNature = 100;
private void GameOver()
{
this.natureBar.SetValue(this.currentNature);
} }
// Singleton // Singleton
private void Awake() private void Awake()
{ {
...@@ -95,6 +87,4 @@ public class PlayerNature : MonoBehaviour ...@@ -95,6 +87,4 @@ public class PlayerNature : MonoBehaviour
instance = this; instance = this;
} }
} }
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
/// <summary>
/// Ce script n'est plus utilisé
/// </summary>
public class loadScene : MonoBehaviour public class loadScene : MonoBehaviour
{ {
public string nextYear; public string nextYear;
...@@ -14,19 +14,24 @@ public class loadScene : MonoBehaviour ...@@ -14,19 +14,24 @@ public class loadScene : MonoBehaviour
public string scene; public string scene;
public Animator animmator; public Animator animmator;
public string name; public string nom;
public void ChargerScene() {
animmator.SetBool("Change",true);
year.text=""+nextYear; public void ChargerScene()
city.text=name; {
animmator.SetBool("Change", true);
year.text = "" + nextYear;
city.text = nom;
StartCoroutine(nextLevelTimer()); StartCoroutine(nextLevelTimer());
} }
private IEnumerator nextLevelTimer() private IEnumerator nextLevelTimer()
{ {
yield return new WaitForSeconds(5); yield return new WaitForSeconds(5);
SceneManager.LoadScene(scene); SceneManager.LoadScene(scene);
} }
...@@ -37,7 +42,6 @@ public class loadScene : MonoBehaviour ...@@ -37,7 +42,6 @@ public class loadScene : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
public void ExitGame() public void ExitGame()
......
fileFormatVersion: 2
guid: 1d113792a68e92533a5ae096013dedfd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shopping : MonoBehaviour
{
private bool playerInRange;
private bool isBuy = false;
public Item sellItem = null;
//public GameObject[] itemForSale = new GameObject[2];
public List<GameObject> itemForSale = new List<GameObject>();
public GameObject panelEbutton;
public GameObject Ebutton;
public GameObject textEbutton;
public GameObject textEbuttonObject;
// Start is called before the first frame update
void Start()
{
panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
}
// Update is called once per frame
void Update()
{
if (playerInRange)
{
switch (sellItem.id)
{
case 1:
textEbuttonObject.GetComponent<Text>().text = "Chaussures de marche";
break;
case 2:
textEbuttonObject.GetComponent<Text>().text = "Bâton de marche";
break;
case 3:
textEbuttonObject.GetComponent<Text>().text = "Réchaud";
break;
case 4:
textEbuttonObject.GetComponent<Text>().text = "Tente";
break;
}
}
if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown("joystick button 1")) && playerInRange && sellItem && itemForSale.Count > 0)
{
if (!isBuy)
PlayerNature.instance.LooseNature(20);
switch (sellItem.id)
{
case 1:
Dialog.instance.setSituation("boutiqueChaussure");
isBuy = true;
break;
case 2:
Dialog.instance.setSituation("boutiqueBaton");
isBuy = true;
break;
case 3:
Dialog.instance.setSituation("boutiqueRechaud");
isBuy = true;
break;
case 4:
Dialog.instance.setSituation("boutiqueTente");
isBuy = true;
break;
}
panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
Inventory.instance.addItem(sellItem);
Debug.Log(sellItem.name.ToString() + " a bien ete ajouté a l'inventaire");
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
playerInRange = true;
if (isBuy == false)
{
panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
Ebutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
textEbutton.GetComponent<CanvasRenderer>().SetAlpha(1f);
textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(1f);
}
}
}
private void OnTriggerExit2D(Collider2D collision)
{
playerInRange = false;
panelEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
}
}
fileFormatVersion: 2
guid: 3aca29e63a372841dabe9b809fff6d12
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added