Working on it

This commit is contained in:
2020-04-18 18:14:51 +10:00
commit a3b19da551
236 changed files with 16300 additions and 0 deletions

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0aaaa632174b054d4bd837b96202c530
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3cb5a455764fe0a9893b9793905f73c0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9031b04b82be9f34aa1d8f27d7621db8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3568a979977247a55a05ef45aca8d951
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26985665716a9ec3eaedc74ed0ddd51f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f848b3c767b145fcb528148f52492de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a2ab35da005f7d6c83a51f94e2b5490
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4beeacff2211776f08d07aba88e15714
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: