Skip to content

Commit

Permalink
Emergency Push
Browse files Browse the repository at this point in the history
Ive been working all day and havent pushed in a while
  • Loading branch information
aps16104 committed Apr 23, 2020
1 parent d67c297 commit f9c628b
Show file tree
Hide file tree
Showing 44 changed files with 6,754 additions and 5,600 deletions.
134 changes: 0 additions & 134 deletions Platformer/Assets/Scripts/Controller2D.cs

This file was deleted.

8 changes: 8 additions & 0 deletions Platformer/Assets/Scripts/Items&HUD.meta

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

File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Platformer/Assets/Scripts/Menus&Camera.meta

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

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Controller2D))]
[RequireComponent(typeof(Controller2D))]
public class Player_Controller : MonoBehaviour
{
Controller2D controller; //controller

float moveSpeed = 10; //How Fast He moves


float gravity; //Gravity (No Rigid Body)
float jumpVelocity;
Vector3 velocity; //Velocity (Again since using raycasting need to create alll this)
Expand All @@ -20,7 +18,9 @@ public class Player_Controller : MonoBehaviour
public float jumpHeight = 4; //height
public float timeToJumpApex = .4f; //time to get there
float accelerationTimeAirborne = .2f; //acceleration time
float accelerationTimeGrounded = .05f; //time to ground
float accelerationTimeGrounded = .15f; //time to

Controller2D controller; //controller


public int currentHealth; //health
Expand Down
106 changes: 106 additions & 0 deletions Platformer/Assets/Scripts/Player&Enemy/Player_Controller.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Controller2D))]
public class Player_Controller : MonoBehaviour
{
Controller2D controller; //controller

float moveSpeed = 10; //How Fast He moves


float gravity; //Gravity (No Rigid Body)
float jumpVelocity;
Vector3 velocity; //Velocity (Again since using raycasting need to create alll this)
float velocityXSmoothing;

//Jumping
public float jumpHeight = 4; //height
public float timeToJumpApex = .4f; //time to get there
float accelerationTimeAirborne = .2f; //acceleration time
float accelerationTimeGrounded = .15f; //time to


public int currentHealth; //health
private int maxHealth = 100; //max health
public HealthBar healthbar; //Healthbar

public GameObject door; //Public so I could drag door in

void Start()
{
controller = GetComponent<Controller2D>(); //Get Components controller2d

gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2); //Derived from equation
jumpVelocity = Mathf.Abs(gravity) * timeToJumpApex; //Derived from equation
print("Gravity: " + gravity + " Jump Velocity: " + jumpVelocity);

door.SetActive(false); // Turn off the door
currentHealth = maxHealth; //Reset to max health
healthbar.SetMaxHealth(maxHealth); //Health bar to max
}

void Update()
{
if (controller.collisions.above || controller.collisions.below) //if true reset y
{
velocity.y = 0;
}

Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.below) //Jumping (and on something)
{
velocity.y = jumpVelocity;
}

float targetVelocityX = input.x * moveSpeed;

velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); //Movement in the x direction
velocity.y += gravity * Time.deltaTime; //Movement in the y Direction
controller.Move(velocity * Time.deltaTime); //How to actually move, in controller script
}


//Damage Function
void TakeDamage(int damage)
{
currentHealth -= damage; //take damage
healthbar.SetHealth(currentHealth); //modify health bar
if (currentHealth < 1)
{
Time.timeScale = 0f;
}
}



//Ontrigger Enter (AKA TAGS)
void OnTriggerEnter2D(Collider2D other) //Pickups
{
if (other.gameObject.CompareTag("Key")) //If you got the key
{
other.gameObject.SetActive(false); //key is not actice
door.SetActive(true); // Door is accessible
}

if (other.gameObject.CompareTag("Heart"))
{
other.gameObject.SetActive(false); // heart dissapears
currentHealth = maxHealth; // Full Health
healthbar.SetHealth(currentHealth); //Full HealthBar
}

if (other.gameObject.CompareTag("Enemy"))
{
TakeDamage(20);
}

//Ninja star is in the weapon script (easier that way for some reason )
}



}
File renamed without changes.
8 changes: 8 additions & 0 deletions Platformer/Assets/Scripts/Raycast.meta

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

Loading

0 comments on commit f9c628b

Please sign in to comment.