Skip to content

Commit

Permalink
Merge pull request #9 from Prefab5/S1-#31-Score
Browse files Browse the repository at this point in the history
S1 #31 Score
  • Loading branch information
dyllandry authored Jul 3, 2016
2 parents 5e63d7b + fc6bbd4 commit 715c1b3
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 57 deletions.
11 changes: 6 additions & 5 deletions djGame/Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
Expand All @@ -38,22 +38,23 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll</HintPath>
<HintPath>C:/Program Files/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll</HintPath>
<HintPath>C:/Program Files/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\scripts\Chunk.cs" />
<Compile Include="Assets\scripts\ChunkController.cs" />
<Compile Include="Assets\scripts\PlaceholderMovement.cs" />
<Compile Include="Assets\scripts\PlayerController.cs" />
<Compile Include="Assets\scripts\ScoreController.cs" />
<Reference Include="UnityEngine.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
14 changes: 14 additions & 0 deletions djGame/Assets/scenes/test_scene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ MonoBehaviour:
groundMask:
serializedVersion: 2
m_Bits: 256
scoreObject: {fileID: 2036509773}
--- !u!50 &1000382898
Rigidbody2D:
serializedVersion: 2
Expand Down Expand Up @@ -441,6 +442,7 @@ GameObject:
m_Component:
- 4: {fileID: 2036509775}
- 132: {fileID: 2036509774}
- 114: {fileID: 2036509776}
m_Layer: 0
m_Name: Score Text
m_TagString: Untagged
Expand Down Expand Up @@ -484,3 +486,15 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
--- !u!114 &2036509776
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2036509773}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cc5123a07fe7c4648acecabc0dead047, type: 3}
m_Name:
m_EditorClassIdentifier:
scoreRate: 0
1 change: 0 additions & 1 deletion djGame/Assets/scripts/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ go ahead and skip the first 7 units. We don't want to spawn anything
too close to the player.*/
if (chunkNumber == 1 && i == 0 && prefabName != "Ground")
{
print("Offset");
i = 15;
indexPosition.x += 15;
}
Expand Down
118 changes: 68 additions & 50 deletions djGame/Assets/scripts/PlayerController.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,84 @@
using UnityEngine;
/************************************************
* Definition: Methods for controlling the player.
*
* Created: ??/??/??
* **********************************************/

using UnityEngine;
using System.Collections;

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

public ChunkController chunkController;

private float jumpHeight = 500f;
private float knockDownTime = 2f;
private float timeKnockedDown = 0;
private bool collision = false;

public ChunkController chunkController;
//For detecting grounded state to allow jumping.
public Transform groundPoint;
public float groundPointRadius;
public LayerMask groundMask;
bool isGrounded;

private float jumpHeight = 500f;
private float knockDownTime = 2f;
private float timeKnockedDown = 0;
private bool collision = false;
Rigidbody2D rb2D;

public Transform groundPoint;
public float groundPointRadius;
public LayerMask groundMask;
//For controlling the score.
public GameObject scoreObject;
private ScoreController score;

bool isGrounded;
Rigidbody2D rb2D;

void Start()
{
rb2D = GetComponent<Rigidbody2D>();
}
void Start ()
{
rb2D = GetComponent<Rigidbody2D> ();
score = scoreObject.GetComponent<ScoreController> ();
score.SetScoreRate (10);
}

void Update()
{
//Checks to see if player is in contact with ground directly beneath them.
isGrounded = Physics2D.OverlapCircle(groundPoint.position, groundPointRadius, groundMask);
void Update ()
{
JumpControl ();

//Jumping controls.
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb2D.AddForce(new Vector2(0, jumpHeight));
if (collision) {
KnockDown ();
}

}
}

PlayerCollision();
void JumpControl ()
{
//Checks to see if player is in contact with ground directly beneath them.
isGrounded = Physics2D.OverlapCircle (groundPoint.position, groundPointRadius, groundMask);

}
//Jumping controls.
if (Input.GetKeyDown (KeyCode.Space) && isGrounded) {
rb2D.AddForce (new Vector2 (0, jumpHeight));

void OnTriggerEnter2D(Collider2D other)
{
}
}

void OnTriggerEnter2D (Collider2D other)
{

if (other.gameObject.tag == "collision_obstacle")
{
chunkController.PlayerCollision();
collision = true;
}
}

void PlayerCollision()
{
if (collision)
{
timeKnockedDown += Time.deltaTime;

if(timeKnockedDown > knockDownTime)
{
timeKnockedDown = 0;
collision = false;
chunkController.GetComponent<ChunkController>().ResumeMovement();
}
}
}
if (other.gameObject.tag == "collision_obstacle") {
chunkController.PlayerCollision ();
collision = true;
score.PauseScore ();
}
}

void KnockDown ()
{
timeKnockedDown += Time.deltaTime;

if (timeKnockedDown > knockDownTime) {
timeKnockedDown = 0;
collision = false;
chunkController.GetComponent<ChunkController> ().ResumeMovement ();
score.ResumeScore ();
}
}

}
56 changes: 56 additions & 0 deletions djGame/Assets/scripts/ScoreController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************
* Definition: Methods for controlling the score.
* Requirements: PlayerController references the gameObject
* containing this script.
*
* Created: 7/3/16
* ******************************************************************/

using UnityEngine;
using System.Collections;

public class ScoreController : MonoBehaviour
{

public int scoreRate;
private float score;
private bool pause = false;

void Start ()
{

}

void Update ()
{
IncrementScore ();
}

void IncrementScore ()
{
if (scoreRate != null && !pause) {
score += scoreRate * Time.deltaTime;
UpdateScore ();
}
}

void UpdateScore ()
{
gameObject.GetComponent<GUIText> ().text = "Score: " + Mathf.Round (score).ToString();
}

public void PauseScore ()
{
pause = true;
}

public void ResumeScore ()
{
pause = false;
}

public void SetScoreRate (int RatePerSecond)
{
scoreRate = RatePerSecond;
}
}
12 changes: 12 additions & 0 deletions djGame/Assets/scripts/ScoreController.cs.meta

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

30 changes: 29 additions & 1 deletion djGame/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,49 @@ PlayerSettings:
XboxOnePersistentLocalStorageSize: 0
intPropertyNames:
- Android::ScriptingBackend
- Metro::ScriptingBackend
- Standalone::ScriptingBackend
- WebGL::ScriptingBackend
- WebGL::audioCompressionFormat
- WebGL::exceptionSupport
- WebGL::memorySize
- WebPlayer::ScriptingBackend
- iOS::Architecture
- iOS::EnableIncrementalBuildSupportForIl2cpp
- iOS::ScriptingBackend
- tvOS::Architecture
- tvOS::EnableIncrementalBuildSupportForIl2cpp
- tvOS::ScriptingBackend
Android::ScriptingBackend: 0
Metro::ScriptingBackend: 2
Standalone::ScriptingBackend: 0
WebGL::ScriptingBackend: 1
WebGL::audioCompressionFormat: 4
WebGL::exceptionSupport: 1
WebGL::memorySize: 256
WebPlayer::ScriptingBackend: 0
iOS::Architecture: 2
iOS::EnableIncrementalBuildSupportForIl2cpp: 1
iOS::ScriptingBackend: 1
tvOS::Architecture: 1
tvOS::EnableIncrementalBuildSupportForIl2cpp: 0
tvOS::ScriptingBackend: 1
boolPropertyNames:
- WebGL::analyzeBuildSize
- WebGL::dataCaching
- WebGL::useEmbeddedResources
- XboxOne::enus
WebGL::analyzeBuildSize: 0
WebGL::dataCaching: 0
WebGL::useEmbeddedResources: 0
XboxOne::enus: 1
stringPropertyNames: []
stringPropertyNames:
- WebGL::emscriptenArgs
- WebGL::template
- additionalIl2CppArgs::additionalIl2CppArgs
WebGL::emscriptenArgs:
WebGL::template: APPLICATION:Default
additionalIl2CppArgs::additionalIl2CppArgs:
cloudProjectId:
projectName:
organizationId:
Expand Down

0 comments on commit 715c1b3

Please sign in to comment.