mirror of
https://github.com/Ratstail91/Keep-It-Alive.git
synced 2025-11-29 02:24:27 +11:00
Mostly finished, just needs sound, polish and hosting online
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Character : MonoBehaviour {
|
||||
//components
|
||||
@@ -16,9 +17,14 @@ public class Character : MonoBehaviour {
|
||||
const float maxSpeed = 60f;
|
||||
const float moveForce = 400f;
|
||||
|
||||
//hunting
|
||||
FadeToBlack fadeToBlack;
|
||||
float huntingTime;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
fadeToBlack = GetComponent<FadeToBlack>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
@@ -28,6 +34,7 @@ public class Character : MonoBehaviour {
|
||||
void FixedUpdate() {
|
||||
HandleMovement();
|
||||
HandleAnimation();
|
||||
HandleHunted();
|
||||
}
|
||||
|
||||
void HandleInput() {
|
||||
@@ -64,4 +71,16 @@ public class Character : MonoBehaviour {
|
||||
spriteRenderer.sortingOrder = -(int)Mathf.Floor(transform.localPosition.y * 100);
|
||||
spriteRenderer.flipX = lastHorizontalInput > 0f;
|
||||
}
|
||||
|
||||
void HandleHunted() {
|
||||
if (fadeToBlack.brightness < 0f) {
|
||||
huntingTime -= Time.deltaTime;
|
||||
} else {
|
||||
huntingTime = 3f;
|
||||
}
|
||||
|
||||
if (huntingTime <= 0f) {
|
||||
SceneManager.LoadScene("Claws");
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Assets/Scripts/GameObjects/Eyes.cs
Normal file
42
Assets/Scripts/GameObjects/Eyes.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Eyes : MonoBehaviour {
|
||||
static LevelController levelController;
|
||||
static GameObject characterObject;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
if (!levelController) {
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
}
|
||||
|
||||
if (!characterObject) {
|
||||
characterObject = GameObject.Find("Character");
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
HandleAnimation();
|
||||
}
|
||||
|
||||
void HandleAnimation() {
|
||||
//determine the brightness based on distance from the center of the tilemap
|
||||
float distance = Vector3.Distance(transform.localPosition, Vector3.zero) / 32f;
|
||||
float brightness = Mathf.Log(distance, 10) - levelController.globalLightLevel;
|
||||
float spooked = Mathf.Log(Vector3.Distance(transform.localPosition, characterObject.transform.localPosition) / 32, 2) - 0.8f;
|
||||
|
||||
if (spooked < 1f && brightness >= 0f) {
|
||||
brightness *= spooked;
|
||||
}
|
||||
|
||||
Color color = Color.white;
|
||||
color.a = brightness;
|
||||
|
||||
spriteRenderer.color = color;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/Eyes.cs.meta
Normal file
11
Assets/Scripts/GameObjects/Eyes.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2e681ade087d56bd8f6f5a673b29279
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -33,6 +33,14 @@ public class Fire : MonoBehaviour {
|
||||
HandleAnimation();
|
||||
}
|
||||
|
||||
void OnTriggerStay2D() {
|
||||
if (GamePad.GetState().Pressed(CButton.Y) && levelController.globalWood > 0) {
|
||||
levelController.globalWood -= 1;
|
||||
levelController.globalLightLevel += 0.2f;
|
||||
levelController.globalLightLevel = Mathf.Clamp(levelController.globalLightLevel, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleAnimation() {
|
||||
animator.SetInteger("size", size);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ using UnityEngine;
|
||||
|
||||
public class Ground : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject tilePrefab;
|
||||
GameObject tilePrefab = null;
|
||||
|
||||
[SerializeField]
|
||||
GameObject treePrefab;
|
||||
GameObject treePrefab = null;
|
||||
|
||||
[SerializeField]
|
||||
GameObject eyesPrefab = null;
|
||||
|
||||
void Awake() {
|
||||
//generate tiles
|
||||
@@ -20,15 +23,19 @@ public class Ground : MonoBehaviour {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
GenerateTree(5, size);
|
||||
GenerateEntity(treePrefab, 5, size);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
GenerateTree(2, 5);
|
||||
for (int i = 0; i < 3 && eyesPrefab; i++) {
|
||||
GenerateEntity(treePrefab, 2, 5);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20 && eyesPrefab != null; i++) {
|
||||
GenerateEntity(eyesPrefab, 5, 10);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateTree(float near, float far) {
|
||||
void GenerateEntity(GameObject prefab, float near, float far) {
|
||||
//geenrate trees
|
||||
float direction = Random.Range(0, 360); //angle
|
||||
float distance = Random.Range(near, far); //H & A
|
||||
@@ -37,6 +44,6 @@ public class Ground : MonoBehaviour {
|
||||
float sin = Mathf.Sin(direction * Mathf.PI / 180f);
|
||||
float cos = Mathf.Cos(direction * Mathf.PI / 180f);
|
||||
|
||||
Instantiate(treePrefab, new Vector3(distance * cos * 32, distance * sin * 32, 0), Quaternion.identity, transform);
|
||||
Instantiate(prefab, new Vector3(distance * cos * 32, distance * sin * 32, 0), Quaternion.identity, transform);
|
||||
}
|
||||
}
|
||||
33
Assets/Scripts/GameObjects/MockFire.cs
Normal file
33
Assets/Scripts/GameObjects/MockFire.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MockFire : MonoBehaviour {
|
||||
LevelController levelController;
|
||||
Animator animator;
|
||||
|
||||
void Awake() {
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
void Start() {
|
||||
animator.speed = 1f / 10f;
|
||||
animator.SetInteger("size", 2);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (GamePad.GetState().Pressed(CButton.Y)) {
|
||||
SceneManager.LoadScene("Gameplay");
|
||||
}
|
||||
|
||||
if (levelController.globalLightLevel < 0.4f) {
|
||||
levelController.increment = 0.002f;
|
||||
}
|
||||
|
||||
if (levelController.globalLightLevel > 0.6f) {
|
||||
levelController.increment = -0.002f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/MockFire.cs.meta
Normal file
11
Assets/Scripts/GameObjects/MockFire.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8ef96580d66d15569418aaf508311d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,11 +3,50 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Tree : MonoBehaviour {
|
||||
static LevelController levelController;
|
||||
static GameObject character;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
int life = 3;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
spriteRenderer.sortingOrder = -(int)Mathf.Floor(transform.localPosition.y * 100);
|
||||
|
||||
if (!levelController) {
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
}
|
||||
|
||||
if (!character) {
|
||||
character = GameObject.Find("Character");
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay2D() {
|
||||
if (GamePad.GetState().Pressed(CButton.Y)) {
|
||||
life -= 1;
|
||||
|
||||
//wiggle
|
||||
StartCoroutine(Wiggle());
|
||||
|
||||
if (life <= 0) {
|
||||
Destroy(gameObject);
|
||||
levelController.globalWood++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Wiggle() {
|
||||
float time = 0.5f;
|
||||
|
||||
while (time > 0f) {
|
||||
float sign = Mathf.Sign(character.transform.localPosition.x - transform.localPosition.x);
|
||||
transform.rotation = Quaternion.Slerp(Quaternion.Euler(0, 0, 0), Quaternion.Euler(0, 0, sign * 10), time);
|
||||
time -= Time.deltaTime;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user