Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding PCSpawner to correct branch #4

Open
wants to merge 12 commits into
base: player-spawning-and-placement
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Assets/Prefabs/Player.prefab
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/Prefabs/Player.prefab.meta

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

Binary file modified Assets/Scenes/Level01.unity
Binary file not shown.
Binary file modified Assets/Scenes/Level02.unity
Binary file not shown.
13 changes: 5 additions & 8 deletions Assets/Scripts/Entities/Enemies/BigBaddieController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,18 @@ IEnumerator OnTriggerEnter2D(Collider2D collision) {
yield return new WaitForSeconds(0.397f);
Destroy(this.gameObject);

// Go to win scene.
Application.LoadLevel("WinScreen");
// Go to win scene and destroy player.
playerObject.SendMessage("Die");
}

playerObject.SendMessage("Knockback", knockback);


} else // if(playerScript.playerLevel < enemyLevel)
// The player should die
{
}
else {
Debug.Log("Player should die. playerLevel: " +
playerLevel + " enemyLevel: " +
enemyLevel);
// Go to gameover scene.
Application.LoadLevel("WinScreen");
playerObject.SendMessage("Die");
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions Assets/Scripts/Entities/Player/PCSpawner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;
using System.Collections;

public class PCSpawner : MonoBehaviour {

public Transform player;
private GameObject playerObject;
private PlayerController pc;
public bool canSpawn; //At the moment, this isn't necessary


// Use this for initialization
void Start () {
Instantiate(player, new Vector3(0f, -4.259603f, 0f), Quaternion.identity);
playerObject = GameObject.FindGameObjectsWithTag("Player")[0];
pc = playerObject.GetComponent<PlayerController>();
}

// Update is called once per frame
void Update () {
//as long as the player isn't swimming, let user determine x position
if (pc.Swimming == false && Application.loadedLevelName.Equals("Level01")) {
Vector3 mPos = Input.mousePosition;
mPos = Camera.main.ScreenToWorldPoint(mPos);
playerObject.transform.position = new Vector3(mPos.x, playerObject.transform.position.y, 0f);

//the player hits the left mouse button to select the X position
if (Input.GetButtonDown("Fire1")){
pc.Swimming = true;
}
}
}
}
8 changes: 8 additions & 0 deletions Assets/Scripts/Entities/Player/PCSpawner.cs.meta

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

48 changes: 41 additions & 7 deletions Assets/Scripts/Entities/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
using System.Collections;

public class PlayerController : MonoBehaviour {
private bool canSpawn;
public static PlayerController pcontrol;

private bool _canSpawn;
private bool _swimming; // To track whether the player has begun his fishy journey
private Vector3 currentPosition;
public float moveSpeed = 1.5f;


void Awake() {
if(pcontrol == null) {
DontDestroyOnLoad(gameObject);
pcontrol = this;
} else if(pcontrol != this) {
// There can be only one!
Destroy(gameObject);
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some of the old code got mixed up with some of the new stuff. I'll do some surgery.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was always there. It resolved the issue of a shitload of players
spawning when level02 loaded. I admit i don't know why it helped, or if
it's still necessary though... Like I said, sometimes i just fix shit
without regard for best practice

On Fri, Aug 15, 2014 at 5:09 PM, zerosalife [email protected]
wrote:

In Assets/Scripts/Entities/Player/PlayerController.cs:

private Vector3 currentPosition;
public float moveSpeed = 1.5f;

  • void Awake() {
  • if(pcontrol == null) {
  •  DontDestroyOnLoad(gameObject);
    
  •  pcontrol = this;
    
  • } else if(pcontrol != this) {
  •  // There can be only one!
    
  •  Destroy(gameObject);
    
  • }
  • }

Looks like some of the old code got mixed up with some of the new stuff.
I'll do some surgery.


Reply to this email directly or view it on GitHub
https://github.com/zerosalife/okeanos/pull/4/files#r16318047.

// Use this for initialization
void Start () {
currentPosition = gameObject.transform.position;
Expand All @@ -17,19 +31,39 @@ void Start () {
void Update () {
currentPosition = transform.position;

// Always march up.
Vector3 target = Vector3.up * moveSpeed + currentPosition;
transform.position = Vector3.Lerp(currentPosition, target, Time.deltaTime);

// If we're off the top of the screen, go to the next screen.
if(currentPosition.y >= 5.5) {
Application.LoadLevel("Level02");
if(_swimming) {

// Always march up.
Vector3 target = Vector3.up * moveSpeed + currentPosition;
transform.position = Vector3.Lerp(currentPosition, target, Time.deltaTime);

// If we're off the top of the screen, go to the next screen.
if(currentPosition.y >= 5.5 && Application.loadedLevelName.Equals("Level01")) {
Application.LoadLevel("Level02");
transform.position = new Vector3(0f, -4f, 0f);
}
}
}



///////////////////////////
//// Setters & Getters //
///////////////////////////

public bool Swimming {
get { return this._swimming; }
set { this._swimming = value; }
}

///////////////////////////
//// Our Utility Methods
///////////////////////////
void Die() {
// Application.LoadLevel("Gameover");
Destroy(this.gameObject);
Debug.Log("Player was destroyed");
Application.LoadLevel("WinScreen");
}

Expand Down
6 changes: 4 additions & 2 deletions Assets/Sprites/fish-blue.png.meta

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

6 changes: 4 additions & 2 deletions Assets/Sprites/fish-green.png.meta

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

6 changes: 4 additions & 2 deletions Assets/Sprites/fish-orange.png.meta

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

6 changes: 4 additions & 2 deletions Assets/Sprites/fish-red.png.meta

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

6 changes: 4 additions & 2 deletions Assets/Sprites/fish-yellow.png.meta

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

Binary file modified ProjectSettings/Physics2DSettings.asset
Binary file not shown.