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 58 additions and 38 deletions
...@@ -15,12 +15,12 @@ public class PlayerMovement : MonoBehaviour ...@@ -15,12 +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 int stage = 0;
public GameObject player; public GameObject player;
public bool[] ispassed; 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()
...@@ -29,40 +29,70 @@ public class PlayerMovement : MonoBehaviour ...@@ -29,40 +29,70 @@ 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 }; 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);
}
private void ProcessInputs()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveY = Input.GetAxisRaw("Vertical");
moveDirection = new Vector2(moveX, moveY);
}
void UpdateAnimationAndMove()
{
if (moveDirection != Vector2.zero)
{
animator.SetFloat("moveX", moveDirection.x);
animator.SetFloat("moveY", moveDirection.y);
animator.SetBool("moving", true);
}
else
{
animator.SetBool("moving", false);
}
}
void gameIntelligence()
{
if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 0) if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 0)
{ {
GenerateMap.instance.generateBoutique(0, 1, "chaussure"); GenerateMap.instance.generateBoutique(0, 0, "chaussure");
stage++; stage++;
} }
else if (stage == 1 && ispassed[0] == true) else if (stage == 1 && ispassed[0] == true)
{ {
GenerateMap.instance.generateUsine(1, 1); GenerateMap.instance.generateUsine(0, 1);
stage++; stage++;
} }
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 2) else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 2)
...@@ -72,50 +102,28 @@ public class PlayerMovement : MonoBehaviour ...@@ -72,50 +102,28 @@ public class PlayerMovement : MonoBehaviour
} }
else if (stage == 3 && ispassed[1] == true) else if (stage == 3 && ispassed[1] == true)
{ {
GenerateMap.instance.generateUsine(1, 2); GenerateMap.instance.generateUsine(1, 1);
stage++; stage++;
} }
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 4) else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 4)
{ {
GenerateMap.instance.generateBoutique(2, 0, "rechaud"); GenerateMap.instance.generateBoutique(1, 2, "rechaud");
stage++; stage++;
} }
else if (stage == 5 && ispassed[2] == true) else if (stage == 5 && ispassed[2] == true)
{ {
GenerateMap.instance.generateUsine(2, 1); GenerateMap.instance.generateUsine(2, 0);
stage++; stage++;
} }
else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 6) else if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 6)
{ {
GenerateMap.instance.generateBoutique(0, 0, "tente"); GenerateMap.instance.generateBoutique(2, 1, "tente");
stage++; stage++;
} }
else if (stage == 7 && ispassed[3] == true) else if (stage == 7 && ispassed[3] == true)
{ {
GenerateMap.instance.generateUsine(1, 0); GenerateMap.instance.generateUsine(1, 0);
stage++; //stage++;
}
}
void MoveCharacter()
{
change.Normalize();
myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime);
}
void UpdateAnimationAndMove()
{
if (change != Vector3.zero)
{
MoveCharacter();
animator.SetFloat("moveX", change.x);
animator.SetFloat("moveY", change.y);
animator.SetBool("moving", true);
}
else
{
animator.SetBool("moving", false);
} }
} }
} }
fileFormatVersion: 2
guid: 1d113792a68e92533a5ae096013dedfd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -55,6 +55,9 @@ public class Shopping : MonoBehaviour ...@@ -55,6 +55,9 @@ public class Shopping : MonoBehaviour
if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown("joystick button 1")) && playerInRange && sellItem && itemForSale.Count > 0) if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown("joystick button 1")) && playerInRange && sellItem && itemForSale.Count > 0)
{ {
if (!isBuy)
PlayerNature.instance.LooseNature(20);
switch (sellItem.id) switch (sellItem.id)
{ {
case 1: case 1:
...@@ -78,6 +81,7 @@ public class Shopping : MonoBehaviour ...@@ -78,6 +81,7 @@ public class Shopping : MonoBehaviour
Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f); Ebutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f); textEbutton.GetComponent<CanvasRenderer>().SetAlpha(0f);
textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f); textEbuttonObject.GetComponent<CanvasRenderer>().SetAlpha(0f);
Inventory.instance.addItem(sellItem); Inventory.instance.addItem(sellItem);
Debug.Log(sellItem.name.ToString() + " a bien ete ajouté a l'inventaire"); Debug.Log(sellItem.name.ToString() + " a bien ete ajouté a l'inventaire");
} }
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: b0d67e78638d146bd8a6878c5027f9c5 guid: 3aca29e63a372841dabe9b809fff6d12
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
......
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
File added
File added
File added