Skip to content

Commit

Permalink
Pacman reverted to Unity4 build, controls remained updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vilbeyli committed Mar 13, 2015
1 parent 28890c6 commit 1176d82
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 107 deletions.
4 changes: 4 additions & 0 deletions Assets/Data/crossdomain.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
Binary file modified Assets/Scenes/game.unity
Binary file not shown.
Binary file modified Assets/Scenes/menu.unity
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Scripts/GUI Scripts/MenuNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public void Credits()

public void SourceCode()
{
Application.OpenURL("https://github.com/vilbeyli/Pacman-Clone/");
Application.OpenURL("https://github.com/vilbeyli/Pacman-Clone/");
}
}
6 changes: 3 additions & 3 deletions Assets/Scripts/GhostMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void ChaseAI()
if (Vector3.Distance(transform.position, waypoint) > 0.000000000001)
{
Vector2 p = Vector2.MoveTowards(transform.position, waypoint, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
rigidbody2D.MovePosition(p);
}

// if at waypoint, run AI module
Expand All @@ -391,7 +391,7 @@ void RunAway()
if (Vector3.Distance(transform.position, waypoint) > 0.000000000001)
{
Vector2 p = Vector2.MoveTowards(transform.position, waypoint, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
rigidbody2D.MovePosition(p);
}

// if at waypoint, run AI run away logic
Expand All @@ -408,7 +408,7 @@ void MoveToWaypoint(bool loop = false)
{ // move towards it
_direction = Vector3.Normalize(waypoint - transform.position); // dont screw up waypoint by calling public setter
Vector2 p = Vector2.MoveTowards(transform.position, waypoint, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
rigidbody2D.MovePosition(p);
}
else // if waypoint is reached, remove it from the queue
{
Expand Down
203 changes: 102 additions & 101 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
public class PlayerController : MonoBehaviour
{

public float speed = 0.4f;
Vector2 _dest = Vector2.zero;
Vector2 _dir = Vector2.zero;
public float speed = 0.4f;
Vector2 _dest = Vector2.zero;
Vector2 _dir = Vector2.zero;
Vector2 _nextDir = Vector2.zero;

[Serializable]
Expand All @@ -19,130 +20,130 @@ public class PointSprites

public static int killstreak = 0;

// script handles
private GameGUINavigation GUINav;
private GameManager GM;
// script handles
private GameGUINavigation GUINav;
private GameManager GM;
private ScoreManager SM;

private bool _deadPlaying = false;

// Use this for initialization
void Start ()
{
GM = GameObject.Find ("Game Manager").GetComponent<GameManager>();
SM = GameObject.Find("Game Manager").GetComponent<ScoreManager>();
GUINav = GameObject.Find ("UI Manager").GetComponent<GameGUINavigation>();
_dest = transform.position;
}
// Update is called once per frame
void FixedUpdate ()
{
switch(GameManager.gameState)
{
case GameManager.GameState.Game:
ReadInputAndMove();
Animate ();
break;

case GameManager.GameState.Dead:
if(!_deadPlaying)
StartCoroutine("PlayDeadAnimation");
break;
}

}

IEnumerator PlayDeadAnimation()
{
_deadPlaying = true;
GetComponent<Animator>().SetBool("Die", true);
yield return new WaitForSeconds(1);
GetComponent<Animator>().SetBool("Die", false);
_deadPlaying = false;

if (GameManager.lives <= 0)
{
private bool _deadPlaying = false;

// Use this for initialization
void Start()
{
GM = GameObject.Find("Game Manager").GetComponent<GameManager>();
SM = GameObject.Find("Game Manager").GetComponent<ScoreManager>();
GUINav = GameObject.Find("UI Manager").GetComponent<GameGUINavigation>();
_dest = transform.position;
}

// Update is called once per frame
void FixedUpdate()
{
switch (GameManager.gameState)
{
case GameManager.GameState.Game:
ReadInputAndMove();
Animate();
break;

case GameManager.GameState.Dead:
if (!_deadPlaying)
StartCoroutine("PlayDeadAnimation");
break;
}


}

IEnumerator PlayDeadAnimation()
{
_deadPlaying = true;
GetComponent<Animator>().SetBool("Die", true);
yield return new WaitForSeconds(1);
GetComponent<Animator>().SetBool("Die", false);
_deadPlaying = false;

if (GameManager.lives <= 0)
{
Debug.Log("Treshold for High Score: " + SM.LowestHigh());
if (GameManager.score >= SM.LowestHigh())
GUINav.getScoresMenu();
else
GUINav.H_ShowGameOverScreen();
}
if (GameManager.score >= SM.LowestHigh())
GUINav.getScoresMenu();
else
GUINav.H_ShowGameOverScreen();
}

else
else
GM.ResetScene();
}

void Animate()
{
Vector2 dir = _dest - (Vector2)transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}

bool Valid(Vector2 direction)
{
// cast line from 'next to pacman' to pacman
}

void Animate()
{
Vector2 dir = _dest - (Vector2)transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}

bool Valid(Vector2 direction)
{
// cast line from 'next to pacman' to pacman
// not from directly the center of next tile but just a little further from center of next tile
Vector2 pos = transform.position;
direction += new Vector2(direction.x * 0.45f, direction.y * 0.45f);
direction += new Vector2(direction.x * 0.45f, direction.y * 0.45f);
RaycastHit2D hit = Physics2D.Linecast(pos + direction, pos);
return hit.collider.name == "pacdot" || (hit.collider == GetComponent<Collider2D>());
}

public void ResetDestination()
{
_dest = new Vector2(15f, 11f);
GetComponent<Animator>().SetFloat("DirX", 1);
GetComponent<Animator>().SetFloat("DirY", 0);
}

void ReadInputAndMove()
{
// move closer to destination
Vector2 p = Vector2.MoveTowards(transform.position, _dest, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
return hit.collider.name == "pacdot" || (hit.collider == GetComponent<Collider2D>());
}

public void ResetDestination()
{
_dest = new Vector2(15f, 11f);
GetComponent<Animator>().SetFloat("DirX", 1);
GetComponent<Animator>().SetFloat("DirY", 0);
}

void ReadInputAndMove()
{
// move closer to destination
Vector2 p = Vector2.MoveTowards(transform.position, _dest, speed);
GetComponent<Rigidbody2D>().MovePosition(p);

// get the next direction from keyboard
if (Input.GetKey("right")) _nextDir = Vector2.right;
if (Input.GetKey("left")) _nextDir = -Vector2.right;
if (Input.GetKey("up")) _nextDir = Vector2.up;
if (Input.GetKey("down")) _nextDir = -Vector2.up;
if (Input.GetKey("right")) _nextDir = Vector2.right;
if (Input.GetKey("left")) _nextDir = -Vector2.right;
if (Input.GetKey("up")) _nextDir = Vector2.up;
if (Input.GetKey("down")) _nextDir = -Vector2.up;

// if pacman is in the center of a tile
if(Vector2.Distance(_dest, transform.position) < 0.00001f)
if (Vector2.Distance(_dest, transform.position) < 0.00001f)
{
if (Valid(_nextDir))
if (Valid(_nextDir))
{
_dest = (Vector2)transform.position + _nextDir;
_dir = _nextDir;
}
else // if next direction is not valid
{
if(Valid(_dir)) // and the prev. direction is valid
if (Valid(_dir)) // and the prev. direction is valid
_dest = (Vector2)transform.position + _dir; // continue on that direction

// otherwise, do nothing
}
}
}

public Vector2 getDir()
{
return _dir;
}
}
}

public Vector2 getDir()
{
return _dir;
}

public void UpdateScore()
{
killstreak++;

// limit killstreak at 4
if (killstreak > 4) killstreak = 4;
Instantiate(points.pointSprites[killstreak-1], transform.position, Quaternion.identity);
GameManager.score += (int)Mathf.Pow(2, killstreak)*100;

Instantiate(points.pointSprites[killstreak - 1], transform.position, Quaternion.identity);
GameManager.score += (int)Mathf.Pow(2, killstreak) * 100;

}
}
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file removed ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 0 additions & 2 deletions ProjectSettings/ProjectVersion.txt

This file was deleted.

Binary file modified ProjectSettings/QualitySettings.asset
Binary file not shown.
Binary file modified ProjectSettings/TagManager.asset
Binary file not shown.

0 comments on commit 1176d82

Please sign in to comment.