Skip to content

Commit

Permalink
Camera transisions (#30)
Browse files Browse the repository at this point in the history
* #23: Fixed Camera Transitions

Transitions are working better now.  However, still need to work on transitions to allow back and forth movement.  May need to remove level boundries fr

* #23: Camera Transitions fixed

Fixed Camera Transitions. Added a Min ad Max camera position.  Also, fixed the checkpoint system. Updated a few prefabs as well.
  • Loading branch information
Alriightyman committed Dec 30, 2019
1 parent aae08f0 commit 4ac300a
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 65 deletions.
Binary file not shown.
7 changes: 7 additions & 0 deletions MegaEngine/Assets/Prefabs/Common/CamTrigger.prefab.meta

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

Binary file added MegaEngine/Assets/Prefabs/Common/Camera.prefab
Binary file not shown.
7 changes: 7 additions & 0 deletions MegaEngine/Assets/Prefabs/Common/Camera.prefab.meta

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

Binary file not shown.
7 changes: 7 additions & 0 deletions MegaEngine/Assets/Prefabs/Common/Checkpoint.prefab.meta

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

Binary file modified MegaEngine/Assets/Prefabs/Enemies/Pipi.prefab
Binary file not shown.
Binary file not shown.

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

Binary file not shown.
Binary file modified MegaEngine/Assets/Scenes/Airman.unity
Binary file not shown.
14 changes: 8 additions & 6 deletions MegaEngine/Assets/Scripts/Common/BossDoor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ protected void Reset()
isOpening = false;
isClosing = false;
hasPlayerGoneThrough = false;
}

//
protected void scaleCube(float scaleAmount)
gameObject.GetComponent<Collider2D>().enabled = true;

}

//
protected void scaleCube(float scaleAmount)
{
Vector3 sc = transform.localScale;
Vector3 pos = transform.localPosition;
Expand All @@ -97,15 +99,15 @@ protected void scaleCube(float scaleAmount)
public void OpenDoor()
{
GameEngine.SoundManager.Play(AirmanLevelSounds.BOSS_DOOR);
gameObject.GetComponent<Collider2D>().isTrigger = true;
gameObject.GetComponent<Collider2D>().enabled = false;
isOpening = true;
}

//
public void CloseDoor()
{
GameEngine.SoundManager.Play(AirmanLevelSounds.BOSS_DOOR);
gameObject.GetComponent<Collider2D>().isTrigger = false;
gameObject.GetComponent<Collider2D>().enabled = true;
isClosing = true;
}

Expand Down
23 changes: 20 additions & 3 deletions MegaEngine/Assets/Scripts/Common/CameraTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class CameraTrigger : MonoBehaviour
[SerializeField] protected bool shouldMoveCamera;
[SerializeField] protected float transitionDuration;
[SerializeField] protected Vector3 freezeEndPosition;

[SerializeField] private Vector3 NewCameraMaxPosition;
[SerializeField] private Vector3 NewCameraMinPosition;

// Protected Instance Variables
protected LevelCamera levelCamera;
protected float transitionStatus = 0.0f;
Expand Down Expand Up @@ -50,13 +52,16 @@ protected void Update ()

if (transitionStatus >= 1.0)
{
GameEngine.Player.IsFrozen = false;
isTransitioning = false;
levelCamera.IsTransitioning = false;
levelCamera.CameraPosition = freezeEndPosition;
levelCamera.CanMoveLeft = onExitCanMoveLeft;
levelCamera.CanMoveRight = onExitCanMoveRight;
levelCamera.CanMoveUp = onExitCanMoveUp;
levelCamera.CanMoveDown = onExitCanMoveDown;
levelCamera.MinPosition = NewCameraMinPosition;
levelCamera.MaxPosition = NewCameraMaxPosition;
}
}
}
Expand All @@ -71,6 +76,11 @@ protected void OnTriggerEnter2D(Collider2D other)
levelCamera.CanMoveUp = onEnterCanMoveUp;
levelCamera.CanMoveDown = onEnterCanMoveDown;

if(!onEnterCanMoveRight)
{
levelCamera.MaxPosition = levelCamera.transform.position;
}

if (isABossDoorTrigger)
{
bossDoor.OpenDoor();
Expand All @@ -80,10 +90,12 @@ protected void OnTriggerEnter2D(Collider2D other)

if (shouldMoveCamera == true)
{
GameEngine.Player.IsFrozen = true;
startPosition = levelCamera.CameraPosition;
isTransitioning = true;
startTime = Time.time;
levelCamera.IsTransitioning = true;

}
}
}
Expand All @@ -97,8 +109,13 @@ protected void OnTriggerExit2D(Collider2D other)
levelCamera.CanMoveRight = onExitCanMoveRight;
levelCamera.CanMoveUp = onExitCanMoveUp;
levelCamera.CanMoveDown = onExitCanMoveDown;

if (isABossDoorTrigger)


levelCamera.MaxPosition = NewCameraMaxPosition;
levelCamera.MinPosition = NewCameraMinPosition;


if (isABossDoorTrigger)
{
GameEngine.Player.IsFrozen = false;
bossDoor.CloseDoor();
Expand Down
21 changes: 15 additions & 6 deletions MegaEngine/Assets/Scripts/Common/Checkpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ public class Checkpoint : MonoBehaviour
[SerializeField] protected bool cameraCanMoveUp;
[SerializeField] protected bool cameraCanMoveDown;

#endregion


#region MonoBehaviour
// Properties
public Vector3 PlayerPosition { get { return playerPosition; } }
public Vector3 CameraPosition { get { return cameraPosition; } }
public bool CanMoveRight { get { return cameraCanMoveRight; } }
public bool CanMoveLeft { get { return cameraCanMoveLeft; } }
public bool CanMoveUp { get { return cameraCanMoveUp; } }
public bool CanMoveDown { get { return cameraCanMoveDown; } }
#endregion


#region MonoBehaviour

// Called when the Collider other enters the trigger.
protected void OnTriggerEnter2D(Collider2D other)
// Called when the Collider other enters the trigger.
protected void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Expand All @@ -30,6 +37,8 @@ protected void OnTriggerEnter2D(Collider2D other)
cam.CheckpointCanMoveRight = cameraCanMoveRight;
cam.CheckpointCanMoveUp = cameraCanMoveUp;
cam.CheckpointCanMoveDown = cameraCanMoveDown;
cam.CheckpointMinPosition = cam.MinPosition;
cam.CheckpoiontMaxPosition = cam.MaxPosition;
Destroy(this.gameObject);
}
}
Expand Down
116 changes: 81 additions & 35 deletions MegaEngine/Assets/Scripts/Common/LevelCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,64 @@ public class LevelCamera : MonoBehaviour
#region Variables

// Public Properties
public Vector3 CameraPosition { get{return transform.position;} set{transform.position = value;} }
public Vector3 CheckpointPosition { get; set; }
public Vector3 CameraPosition { get{return transform.position;} set{transform.position = value;} }
public Vector3 CheckpointPosition { get; set; }
public bool CheckpointCanMoveLeft { get; set; }
public bool CheckpointCanMoveRight { get; set; }
public bool CheckpointCanMoveUp { get; set; }
public bool CheckpointCanMoveDown { get; set; }
public bool CanMoveLeft { get; set; }
public bool CanMoveRight { get; set; }
public bool CanMoveUp { get; set; }
public bool CanMoveDown { get; set; }
public bool IsTransitioning { get; set; }
public bool ShouldStayStill { get; set; }

// Private Instance Variables
public bool CheckpointCanMoveUp { get; set; }
public bool CheckpointCanMoveDown { get; set; }
public bool CanMoveLeft { get; set; }
public bool CanMoveRight { get; set; }
public bool CanMoveUp { get; set; }
public bool CanMoveDown { get; set; }
public bool IsTransitioning { get; set; }
public bool ShouldStayStill { get; set; }
public Vector3 CheckpoiontMaxPosition { get; set; }
public Vector3 CheckpointMinPosition { get; set; }
public Transform MaxTransform;
public Transform MinTransform;
public Vector3 MaxPosition;
public Vector3 MinPosition;
private GameObject LeftBound, RightBound;

// Private Instance Variables
private Vector3 playerCheckpointPosition;
private Vector3 playerPos;
private Vector3 deltaPos;

[SerializeField]
private Transform startPosition;
#endregion

[SerializeField] private Checkpoint startPosition;
#endregion


#region MonoBehaviour

// Use this for initialization
protected void Start ()
#region MonoBehaviour
protected void Awake()
{
LeftBound = GameObject.Find("LeftBound");
RightBound = GameObject.Find("RightBound");
}
// Use this for initialization
protected void Start ()
{
Vector3 position = startPosition != null ? startPosition.CameraPosition : CheckpointPosition;
GameEngine.Player.CheckpointPosition = startPosition != null ? startPosition.PlayerPosition : GameEngine.Player.transform.position;
//Vector3 startPosition = new Vector3(13.34303f, 11.51588f, -10f);
transform.position = new Vector3(startPosition.position.x, startPosition.position.y, -10f);
CheckpointPosition = new Vector3(startPosition.position.x, startPosition.position.y, -10f);
transform.position = new Vector3(position.x, position.y, -10f);
CheckpointPosition = new Vector3(position.x, position.y, -10f);

MinPosition = CheckpointPosition;

ShouldStayStill = false;
IsTransitioning = false;
CanMoveRight = true;
CanMoveLeft = true;
CanMoveUp = false;
CanMoveDown = false;
CanMoveRight = startPosition != null ? startPosition.CanMoveRight : CanMoveRight;
CanMoveLeft = startPosition != null ? startPosition.CanMoveLeft : CanMoveLeft;
CanMoveUp = startPosition != null ? startPosition.CanMoveUp : CanMoveUp;
CanMoveDown = startPosition != null ? startPosition.CanMoveDown : CanMoveDown;
CheckpointCanMoveLeft = false;
CheckpointCanMoveRight = true;
CheckpointCanMoveUp = false;
CheckpointCanMoveDown = false;

//GameEngine.Player.CheckpointPosition = startPosition != null ? startPosition.PlayerPosition : GameEngine.Player.CheckpointPosition;
}

// Update is called once per frame
Expand All @@ -62,21 +79,48 @@ protected void Update ()
// Make the camera follow the player...
playerPos = GameEngine.Player.transform.position;
deltaPos = playerPos - transform.position;

var newPosition = transform.position;


// Check the x pos
if ((deltaPos.x < 0.0f && CanMoveLeft) || (deltaPos.x > 0.0f && CanMoveRight) || GameEngine.LevelStarting)
if ( (deltaPos.x < 0.0f && CanMoveLeft)
|| (deltaPos.x > 0.0f && CanMoveRight))
{
transform.position = new Vector3(playerPos.x, transform.position.y, transform.position.z);
newPosition = new Vector3(playerPos.x, newPosition.y, newPosition.z);
}

// Check the y pos
if ((deltaPos.y < 0.0f && CanMoveDown) || (deltaPos.y > 0.0f && CanMoveUp) || GameEngine.LevelStarting)
if ((deltaPos.y < 0.0f && CanMoveDown) || (deltaPos.y > 0.0f && CanMoveUp))
{
transform.position = new Vector3(transform.position.x, playerPos.y, transform.position.z);
newPosition = new Vector3(newPosition.x, playerPos.y, newPosition.z);
}

// Make the level restart if the user presses escape...
if (Input.GetKeyDown (KeyCode.Escape))
// check if camera has gone too far
if(newPosition.x >= MaxPosition.x)
{
newPosition = new Vector3(MaxPosition.x, newPosition.y, newPosition.z);
}

if (newPosition.x <= MinPosition.x)
{
newPosition = new Vector3(MinPosition.x, newPosition.y, newPosition.z);
}

if (newPosition.y >= MaxPosition.y)
{
newPosition = new Vector3(newPosition.x, MaxPosition.y, newPosition.z);
}

if (newPosition.y <= MinPosition.y)
{
newPosition = new Vector3(newPosition.x, MinPosition.y, newPosition.z);
}


transform.position = newPosition;

// Make the level restart if the user presses escape...
if (Input.GetKeyDown (KeyCode.Escape))
{
SceneManager.LoadScene(0);
}
Expand All @@ -101,8 +145,10 @@ public void Reset()
CanMoveLeft = CheckpointCanMoveLeft;
CanMoveRight = CheckpointCanMoveRight;
CanMoveUp = CheckpointCanMoveUp;
CanMoveDown = CheckpointCanMoveDown;
transform.position = CameraPosition;
CanMoveDown = CheckpointCanMoveDown;
MinPosition = CheckpointMinPosition;
MaxPosition = CheckpoiontMaxPosition;
GameEngine.Player.transform.position = GameEngine.Player.CheckpointPosition;
}
#endregion
}
4 changes: 2 additions & 2 deletions MegaEngine/Assets/Scripts/Enemies/CirclingPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CirclingPlatform : MonoBehaviour//, IResetable
#region MonoBehaviour
private void Awake()
{
initPos = transform.position;
GameEngine.AddResetCallback(new System.Action(ResetObject));

}
Expand Down Expand Up @@ -126,12 +127,11 @@ private static void DrawEllipse(Vector3 pos, Vector3 forward, Vector3 up, float

public void ResetObject()
{
currentPos = transform.position;
transform.position = initPos;
convertFromDeg = (fullCircle / fullCircleInDeg);
circleCenter = transform.position;
ShouldAnimate = false;
start = true;
initPos = new Vector3(currentPos.x, currentPos.y, currentPos.z);
}
#endregion
}
7 changes: 0 additions & 7 deletions MegaEngine/Assets/Scripts/Enemies/PipiTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class PipiTrigger : MonoBehaviour//, IResetable

protected void Awake()
{
//GameEngine.GetResetableObjectList().Add(this);
GameEngine.AddResetCallback(new System.Action(ResetObject));
}
// Called when the Collider other enters the trigger.
protected void OnTriggerEnter2D(Collider2D other )
Expand All @@ -22,9 +20,4 @@ protected void OnTriggerEnter2D(Collider2D other )
}

#endregion

public void ResetObject()
{
gameObject.GetComponent<Collider2D>().enabled = true;
}
}
8 changes: 6 additions & 2 deletions MegaEngine/Assets/Scripts/Player/Movement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public class Movement : MonoBehaviour
[SerializeField] protected float hurtingForce = 1.0f;
[SerializeField] protected Vector3 moveVector = Vector3.zero;
[SerializeField] protected Vector3 startPositionLocation;
[SerializeField] protected GameObject StartPosition;
/// <summary>
/// Used for debugging purposes
/// </summary>
[SerializeField] protected GameObject DebugStartPosition;


// Protected Instance Variables
Expand All @@ -58,7 +61,8 @@ protected void Awake()
protected void Start ()
{
float offset = 128f;
startPositionLocation = StartPosition.transform.position;

startPositionLocation = DebugStartPosition != null ? DebugStartPosition.transform.position : CheckPointPosition;
CheckPointPosition = startPositionLocation;
IsHurting = false;
//transform.position = CheckPointPosition = startPositionLocation;
Expand Down
Loading

0 comments on commit 4ac300a

Please sign in to comment.