mirror of
https://github.com/Ratstail91/Keep-It-Alive.git
synced 2025-11-29 02:24:27 +11:00
Working on it
This commit is contained in:
30
Assets/Scripts/FadeToBlack.cs
Normal file
30
Assets/Scripts/FadeToBlack.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FadeToBlack : MonoBehaviour {
|
||||
LevelController levelController;
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
}
|
||||
|
||||
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 = 1 - Mathf.Log(distance, 10) + levelController.globalLightLevel - 0.5f;
|
||||
|
||||
Color color = Color.white;
|
||||
color.r = brightness;
|
||||
color.g = brightness;
|
||||
color.b = brightness;
|
||||
|
||||
spriteRenderer.color = color;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/FadeToBlack.cs.meta
Normal file
11
Assets/Scripts/FadeToBlack.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aaaa632174b054d4bd837b96202c530
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/GameObjects.meta
Normal file
8
Assets/Scripts/GameObjects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cb5a455764fe0a9893b9793905f73c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Scripts/GameObjects/Character.cs
Normal file
67
Assets/Scripts/GameObjects/Character.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Character : MonoBehaviour {
|
||||
//components
|
||||
SpriteRenderer spriteRenderer;
|
||||
Rigidbody2D rb;
|
||||
|
||||
//movement
|
||||
float horizontalInput;
|
||||
float verticalInput;
|
||||
float lastHorizontalInput;
|
||||
float lastVerticalInput;
|
||||
const float deadZone = 0.15f;
|
||||
const float maxSpeed = 60f;
|
||||
const float moveForce = 400f;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
HandleInput();
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
HandleMovement();
|
||||
HandleAnimation();
|
||||
}
|
||||
|
||||
void HandleInput() {
|
||||
horizontalInput = GamePad.GetAxis(CAxis.LX);
|
||||
verticalInput = -GamePad.GetAxis(CAxis.LY);
|
||||
|
||||
if (Mathf.Abs(horizontalInput) > deadZone || Mathf.Abs(verticalInput) > deadZone) {
|
||||
lastHorizontalInput = horizontalInput;
|
||||
lastVerticalInput = verticalInput;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleMovement() {
|
||||
//stop the player if input in that direction has been removed
|
||||
if (horizontalInput * rb.velocity.x <= 0) {
|
||||
rb.velocity = new Vector2(rb.velocity.x * 0.65f, rb.velocity.y);
|
||||
}
|
||||
|
||||
if (verticalInput * rb.velocity.y <= 0) {
|
||||
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.65f);
|
||||
}
|
||||
|
||||
//move in the inputted direction, if not at max speed
|
||||
if (horizontalInput * rb.velocity.x < maxSpeed) {
|
||||
rb.AddForce(Vector2.right * horizontalInput * moveForce);
|
||||
}
|
||||
|
||||
if (verticalInput * rb.velocity.y < maxSpeed) {
|
||||
rb.AddForce(Vector2.up * verticalInput * moveForce);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleAnimation() {
|
||||
spriteRenderer.sortingOrder = -(int)Mathf.Floor(transform.localPosition.y * 100);
|
||||
spriteRenderer.flipX = lastHorizontalInput > 0f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/Character.cs.meta
Normal file
11
Assets/Scripts/GameObjects/Character.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9031b04b82be9f34aa1d8f27d7621db8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/Scripts/GameObjects/FadingTile.cs
Normal file
38
Assets/Scripts/GameObjects/FadingTile.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FadingTile : MonoBehaviour {
|
||||
static LevelController levelController;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
if (!levelController) {
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
//bugfix for tile under the fire
|
||||
if (distance == 0) {
|
||||
distance = 0.5f;
|
||||
}
|
||||
|
||||
float brightness = 1 - Mathf.Log(distance, 10) + levelController.globalLightLevel - 0.5f;
|
||||
|
||||
Color color = Color.white;
|
||||
color.a = brightness;
|
||||
|
||||
spriteRenderer.color = color;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/FadingTile.cs.meta
Normal file
11
Assets/Scripts/GameObjects/FadingTile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3568a979977247a55a05ef45aca8d951
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/GameObjects/Fire.cs
Normal file
39
Assets/Scripts/GameObjects/Fire.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Fire : MonoBehaviour {
|
||||
Animator animator;
|
||||
LevelController levelController;
|
||||
|
||||
[SerializeField]
|
||||
int size = 1;
|
||||
|
||||
void Awake() {
|
||||
animator = GetComponent<Animator>();
|
||||
levelController = GameObject.Find("Level Controller").GetComponent<LevelController>();
|
||||
}
|
||||
|
||||
void Start() {
|
||||
animator.speed = 1f / 10f;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
//change based on global light level
|
||||
if (levelController.globalLightLevel <= 0.3f) {
|
||||
size = 1;
|
||||
} else if (levelController.globalLightLevel < 0.7f) {
|
||||
size = 2;
|
||||
} else {
|
||||
size = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
HandleAnimation();
|
||||
}
|
||||
|
||||
void HandleAnimation() {
|
||||
animator.SetInteger("size", size);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/Fire.cs.meta
Normal file
11
Assets/Scripts/GameObjects/Fire.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26985665716a9ec3eaedc74ed0ddd51f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Assets/Scripts/GameObjects/Ground.cs
Normal file
42
Assets/Scripts/GameObjects/Ground.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Ground : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject tilePrefab;
|
||||
|
||||
[SerializeField]
|
||||
GameObject treePrefab;
|
||||
|
||||
void Awake() {
|
||||
//generate tiles
|
||||
const int size = 20;
|
||||
|
||||
for (int i = -size; i <= size; i++) {
|
||||
for (int j = -size; j <= size; j++) {
|
||||
Instantiate(tilePrefab, new Vector3(i * 32, j * 32, 0), Quaternion.identity, transform);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
GenerateTree(5, size);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
GenerateTree(2, 5);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateTree(float near, float far) {
|
||||
//geenrate trees
|
||||
float direction = Random.Range(0, 360); //angle
|
||||
float distance = Random.Range(near, far); //H & A
|
||||
|
||||
//SOH CAH TOA
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/Ground.cs.meta
Normal file
11
Assets/Scripts/GameObjects/Ground.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f848b3c767b145fcb528148f52492de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/GameObjects/Tree.cs
Normal file
13
Assets/Scripts/GameObjects/Tree.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Tree : MonoBehaviour {
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
spriteRenderer.sortingOrder = -(int)Mathf.Floor(transform.localPosition.y * 100);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameObjects/Tree.cs.meta
Normal file
11
Assets/Scripts/GameObjects/Tree.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a2ab35da005f7d6c83a51f94e2b5490
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/LevelController.cs
Normal file
13
Assets/Scripts/LevelController.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelController : MonoBehaviour {
|
||||
public float globalLightLevel = 1f;
|
||||
public float increment = 0f;
|
||||
|
||||
void FixedUpdate() {
|
||||
globalLightLevel += increment;
|
||||
globalLightLevel = Mathf.Clamp(globalLightLevel, 0, 1);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LevelController.cs.meta
Normal file
11
Assets/Scripts/LevelController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4beeacff2211776f08d07aba88e15714
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user