Project
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48145291481e31b42b5f43ca61cbab41
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CheckPoint : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void Anim()
|
||||
{
|
||||
animator.SetInteger("value", 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668968cd2658e7c42aed78d763e56573
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c18edcdb1bf02b4dac3a57754a4e1a4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Enemie : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float speed;
|
||||
private Vector2 velocity = new Vector2();
|
||||
[SerializeField] private float rayOffset = 0.6f;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
private Animator animator;
|
||||
private float timeHit = 0;
|
||||
[SerializeField] private float dieDelay;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
velocity.x = -speed;
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.Translate(velocity * Time.deltaTime);
|
||||
|
||||
if (timeHit != 0)
|
||||
{
|
||||
if (Time.time - timeHit > dieDelay)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col)
|
||||
{
|
||||
if(col != null)
|
||||
{
|
||||
if (col.tag.Equals("Player"))
|
||||
{
|
||||
if(col.GetComponent<Player>().velocity.y < 0)
|
||||
{
|
||||
col.GetComponent<Player>().BounceUp();
|
||||
Hit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.x *= -1;
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.x *= -1;
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX;
|
||||
}
|
||||
}
|
||||
|
||||
public void Hit()
|
||||
{
|
||||
Destroy(GetComponent<Collider2D>());
|
||||
velocity.x = 0;
|
||||
animator.SetInteger("value", 1);
|
||||
timeHit = Time.time;
|
||||
}
|
||||
|
||||
public void FlipX()
|
||||
{
|
||||
OnTriggerEnter2D(null);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
OnTriggerEnter2D(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60442abe595b11042b0bbca0d4268e75
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Mushroom : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
if(col.contacts[0].normal.x < -0.8f || col.contacts[0].normal.x > 0.8f)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 751521379053e754590c0ca299b9a7ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Saw : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f3fe87e57e37649a4606964b1d6347
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Spikes : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool moving;
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff10e84cfca03a94296fa9ab10ce3429
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75e4d3261030178468a1623173e5046e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FlyPlatform : MonoBehaviour
|
||||
{
|
||||
private Vector2 defaultPos;
|
||||
[SerializeField] private Vector2 targetPoint;
|
||||
[SerializeField] private float speed;
|
||||
|
||||
private bool move = false;
|
||||
|
||||
private float i = 0;
|
||||
|
||||
private Animator animator;
|
||||
|
||||
[SerializeField] private bool needToStepOn = false;
|
||||
|
||||
private int direction = 1;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
defaultPos = transform.localPosition;
|
||||
animator = GetComponent<Animator>();
|
||||
|
||||
if(!needToStepOn)
|
||||
{
|
||||
animator.SetInteger("value", 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(needToStepOn)
|
||||
{
|
||||
if (move)
|
||||
{
|
||||
transform.position = Vector2.Lerp(defaultPos, targetPoint, i);
|
||||
i += Time.deltaTime * speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = Vector2.Lerp(defaultPos, targetPoint, i);
|
||||
i -= Time.deltaTime * speed;
|
||||
}
|
||||
|
||||
if (i > 1) i = 1;
|
||||
if (i < 0) i = 0;
|
||||
|
||||
if (i == 1 || i == 0)
|
||||
{
|
||||
animator.SetInteger("value", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = Vector2.Lerp(defaultPos, targetPoint, i);
|
||||
i += Time.deltaTime * speed * direction;
|
||||
|
||||
if (i > 1 || i < 0)
|
||||
{
|
||||
direction *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col)
|
||||
{
|
||||
if(needToStepOn)
|
||||
{
|
||||
move = true;
|
||||
animator.SetInteger("value", 1);
|
||||
}
|
||||
|
||||
if(col.tag.Equals("Player"))
|
||||
{
|
||||
col.transform.SetParent(transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if(needToStepOn)
|
||||
{
|
||||
move = false;
|
||||
animator.SetInteger("value", 1);
|
||||
}
|
||||
|
||||
if(other.tag.Equals("Player"))
|
||||
{
|
||||
other.transform.SetParent(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f9479f386a5f684abba9ff7b68614e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TransparentBlock : MonoBehaviour
|
||||
{
|
||||
public void Trigger()
|
||||
{
|
||||
GetComponent<SpriteRenderer>().color = Color.white;
|
||||
GetComponent<BoxCollider2D>().isTrigger = false;
|
||||
gameObject.layer = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90b6217bd5147b64eae31a61d332aba1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f5738135462f334686c133aea4ca1f2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AppleValue : MonoBehaviour
|
||||
{
|
||||
public int value;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bb1ecbf7a7b8e6439fb4102807b0b17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
private float timeCollected = 0f;
|
||||
private const float delayDestroy = 0.5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timeCollected > 0)
|
||||
{
|
||||
if (Time.time - timeCollected > delayDestroy)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Collect()
|
||||
{
|
||||
Destroy(GetComponent<CircleCollider2D>());
|
||||
animator.SetInteger("value", 1);
|
||||
timeCollected = Time.time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acec425baaf8b534aba25766ae6b3096
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemBox : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
private float timeHit = 0;
|
||||
private float destroyDelay = 0.4f;
|
||||
[SerializeField] private GameObject itemPrefab;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timeHit != 0)
|
||||
{
|
||||
if (Time.time - timeHit > destroyDelay)
|
||||
{
|
||||
if(itemPrefab != null)
|
||||
{
|
||||
GameObject instance = Instantiate(itemPrefab);
|
||||
instance.transform.position = transform.position;
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Hit()
|
||||
{
|
||||
animator.SetInteger("value", 1);
|
||||
timeHit = Time.time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97fb1c1d099696d47aea104eb76de82d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,400 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float gravity;
|
||||
public Vector2 velocity = new Vector2(0, 0);
|
||||
public bool grounded = false;
|
||||
private const float rayDownLength = 0.67f;
|
||||
private Animator animator;
|
||||
private bool jumpRequest = false;
|
||||
private bool doubleJumpAvailable = true;
|
||||
[SerializeField] private float jumpForce;
|
||||
private bool lastJumpPressed = false, jumpPressed = false;
|
||||
private Vector2 moveAnchor = new Vector2();
|
||||
private bool moveActionHold = false;
|
||||
private Vector2 moveDirection = new Vector2();
|
||||
[SerializeField] private float moveSpeed;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private bool doubleJumpPerformed = false;
|
||||
private float timeDoubleJump = 0;
|
||||
|
||||
[SerializeField] private Image[] heartImages;
|
||||
[SerializeField] private Sprite[] heartSprites;
|
||||
|
||||
private int hp = 3;
|
||||
private int maxHp = 3;
|
||||
|
||||
private float hitTime = -5;
|
||||
private const float inocentTime = .6f;
|
||||
|
||||
private GameObject lastCheckPoint = null;
|
||||
[SerializeField] private AudioSource sourceWalk;
|
||||
[SerializeField] private AudioSource sourcePlayerDamage;
|
||||
[SerializeField] private AudioSource sourceJump;
|
||||
|
||||
private int applesCount = 0;
|
||||
private int minApples = 40;
|
||||
|
||||
[SerializeField] private TMP_Text applesText;
|
||||
|
||||
private const float rayHorizontalLength = 0.5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Application.targetFrameRate = 61;
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
animator = GetComponent<Animator>();
|
||||
UpdateHearts();
|
||||
|
||||
if (PlayerPrefs.HasKey("checkPointX"))
|
||||
{
|
||||
transform.position =
|
||||
new Vector3(PlayerPrefs.GetFloat("checkPointX") - 2, PlayerPrefs.GetFloat("checkPointY"), 5);
|
||||
}
|
||||
|
||||
hitTime = Time.time;
|
||||
animator.SetInteger("value", 5);
|
||||
|
||||
UpdateApples();
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
PlayerPrefs.DeleteKey("checkPointX");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//spieler fallen lassen, wenn dieser nicht auf dem boden steht
|
||||
if (!grounded)
|
||||
{
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
}
|
||||
|
||||
//überprüfen ob der spieler auf dem boden steht
|
||||
if (Physics2D.Raycast(transform.position, Vector2.down, rayDownLength))
|
||||
{
|
||||
grounded = true;
|
||||
doubleJumpAvailable = true;
|
||||
velocity.y = 0;
|
||||
}
|
||||
//spieler steht nicht mehr auf dem boden...
|
||||
else
|
||||
{
|
||||
grounded = false;
|
||||
}
|
||||
|
||||
//wenn eine jump action ausgeführt wurde (leertaste oder touch auf der rechten bildschirmhälfte)
|
||||
if (jumpRequest)
|
||||
{
|
||||
jumpRequest = false;
|
||||
|
||||
//spieler darf springen falls er auf dem boden steht
|
||||
if (grounded)
|
||||
{
|
||||
grounded = false;
|
||||
velocity.y = jumpForce;
|
||||
}
|
||||
//spieler darf springen falls ein doppelsprung verfügbar ist
|
||||
else if (doubleJumpAvailable)
|
||||
{
|
||||
timeDoubleJump = Time.time;
|
||||
velocity.y = jumpForce;
|
||||
doubleJumpPerformed = true;
|
||||
doubleJumpAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
//bewegung über move actions
|
||||
if (moveActionHold)
|
||||
{
|
||||
velocity.x = moveDirection.x * moveSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.x = 0;
|
||||
}
|
||||
|
||||
if (Physics2D.Raycast(transform.position, Vector2.left, rayHorizontalLength) && velocity.x < 0)
|
||||
{
|
||||
if(Physics2D.Raycast(transform.position, Vector2.left, rayHorizontalLength).collider.tag.Equals("Terrain"))
|
||||
{
|
||||
velocity.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (Physics2D.Raycast(transform.position, Vector2.right, rayHorizontalLength) && velocity.x > 0)
|
||||
{
|
||||
if(Physics2D.Raycast(transform.position, Vector2.right, rayHorizontalLength).collider.tag.Equals("Terrain"))
|
||||
{
|
||||
velocity.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//bewege den spieler
|
||||
transform.Translate(velocity * Time.deltaTime);
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
bool leftTouch = false, rightTouch = false;
|
||||
|
||||
//wenn der bildschirm berührt wurde...
|
||||
if (Input.touches.Length > 0)
|
||||
{
|
||||
//für jede berührung...
|
||||
foreach (Touch touch in Input.touches)
|
||||
{
|
||||
//wird die rechte hälfte des bildschirm berührt
|
||||
if (touch.position.x > Screen.width / 2)
|
||||
{
|
||||
rightTouch = true;
|
||||
}
|
||||
|
||||
|
||||
//wird die linke hälfte des bildschirms berührt
|
||||
if (touch.position.x < Screen.width / 2)
|
||||
{
|
||||
if (moveActionHold)
|
||||
{
|
||||
moveDirection = (touch.position - moveAnchor) / 100;
|
||||
moveDirection.y = 0;
|
||||
|
||||
if (Mathf.Abs(moveDirection.x) < 0.2f)
|
||||
{
|
||||
moveDirection.x = 0;
|
||||
}
|
||||
|
||||
if (Mathf.Abs(moveDirection.x) > 1)
|
||||
{
|
||||
moveDirection.Normalize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
moveAnchor = touch.position;
|
||||
}
|
||||
|
||||
leftTouch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jumpPressed = rightTouch;
|
||||
moveActionHold = leftTouch;
|
||||
|
||||
if (Input.GetAxis("Horizontal") != 0)
|
||||
{
|
||||
moveDirection.x = Input.GetAxis("Horizontal");
|
||||
moveActionHold = true;
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
jumpPressed = true;
|
||||
}
|
||||
|
||||
|
||||
//überprüfungen in welchen eingabe fällen der spieler springen darf
|
||||
if (jumpPressed && !lastJumpPressed || jumpPressed && grounded)
|
||||
{
|
||||
jumpRequest = true;
|
||||
}
|
||||
|
||||
//wenn keine leben mehr übrig sind...
|
||||
if (hp <= 0)
|
||||
{
|
||||
if(lastCheckPoint != null)
|
||||
{
|
||||
PlayerPrefs.SetFloat("checkPointX", lastCheckPoint.transform.position.x);
|
||||
PlayerPrefs.SetFloat("checkPointY", lastCheckPoint.transform.position.y);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
SceneManager.LoadScene(1, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
//animation
|
||||
if (velocity.x > 0)
|
||||
{
|
||||
spriteRenderer.flipX = false;
|
||||
if(grounded && !sourceWalk.isPlaying)
|
||||
{
|
||||
sourceWalk.Play();
|
||||
}
|
||||
}
|
||||
else if (velocity.x < 0)
|
||||
{
|
||||
spriteRenderer.flipX = true;
|
||||
if(grounded && !sourceWalk.isPlaying)
|
||||
{
|
||||
sourceWalk.Play();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceWalk.Stop();
|
||||
}
|
||||
|
||||
if (!grounded)
|
||||
{
|
||||
sourceWalk.Stop();
|
||||
}
|
||||
|
||||
if (Time.time - hitTime > inocentTime)
|
||||
{
|
||||
if (!doubleJumpPerformed)
|
||||
{
|
||||
if (transform.parent == null)
|
||||
{
|
||||
if (velocity.y < 0)
|
||||
{
|
||||
animator.SetInteger("value", 1);
|
||||
}
|
||||
else if (velocity.y == 0)
|
||||
{
|
||||
animator.SetInteger("value", 0);
|
||||
}
|
||||
else if (velocity.y > 0)
|
||||
{
|
||||
animator.SetInteger("value", 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.SetInteger("value", 0);
|
||||
}
|
||||
|
||||
if (grounded && velocity.x != 0)
|
||||
{
|
||||
animator.SetInteger("value", 3);
|
||||
animator.speed = Mathf.Abs(moveDirection.x) * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.speed = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (velocity.y <= 0)
|
||||
{
|
||||
doubleJumpPerformed = false;
|
||||
}
|
||||
|
||||
animator.SetInteger("value", 4);
|
||||
}
|
||||
}
|
||||
|
||||
//den aktuellen status der jumpaction speichern
|
||||
lastJumpPressed = jumpPressed;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
if (col.contacts[0].normal.y < -0.2f)
|
||||
{
|
||||
ItemBox box;
|
||||
|
||||
if ((box = col.gameObject.GetComponent<ItemBox>()) == true)
|
||||
{
|
||||
if(velocity.y > 0)
|
||||
{
|
||||
box.Hit();
|
||||
Destroy(col.collider);
|
||||
}
|
||||
}
|
||||
|
||||
velocity.y = -0.5f;
|
||||
}
|
||||
|
||||
if (col.gameObject.tag.Equals("Spikes"))
|
||||
{
|
||||
TakeDamage(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int amount)
|
||||
{
|
||||
if (Time.time - hitTime > inocentTime)
|
||||
{
|
||||
sourcePlayerDamage.Play();
|
||||
hp -= amount;
|
||||
hitTime = Time.time;
|
||||
animator.SetInteger("value", 5);
|
||||
UpdateHearts();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHearts()
|
||||
{
|
||||
for (int i = 0; i < hp; i++)
|
||||
{
|
||||
heartImages[i].sprite = heartSprites[0];
|
||||
}
|
||||
|
||||
if (hp >= 0)
|
||||
{
|
||||
for (int i = hp; i < maxHp; i++)
|
||||
{
|
||||
heartImages[i].sprite = heartSprites[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col)
|
||||
{
|
||||
CheckPoint checkPoint;
|
||||
if ((checkPoint = col.GetComponent<CheckPoint>()) == true)
|
||||
{
|
||||
checkPoint.Anim();
|
||||
lastCheckPoint = col.gameObject;
|
||||
}
|
||||
else if (col.tag.Equals("TransparentBlock"))
|
||||
{
|
||||
if (velocity.y > 0 &&
|
||||
Vector2.Distance(new Vector2(transform.position.x, 0), new Vector2(col.transform.position.x, 0)) < 0.325f)
|
||||
{
|
||||
col.GetComponent<TransparentBlock>().Trigger();
|
||||
velocity.y = -0.5f;
|
||||
}
|
||||
}
|
||||
else if (col.tag.Equals("Dead"))
|
||||
{
|
||||
TakeDamage(5);
|
||||
}
|
||||
else if (col.tag.Equals("Apple"))
|
||||
{
|
||||
col.GetComponent<Item>().Collect();
|
||||
applesCount += col.GetComponent<AppleValue>().value;
|
||||
UpdateApples();
|
||||
}
|
||||
else if (col.tag.Equals("Heal"))
|
||||
{
|
||||
col.GetComponent<Item>().Collect();
|
||||
hp += 1;
|
||||
if (hp > maxHp) hp = maxHp;
|
||||
UpdateHearts();
|
||||
}
|
||||
}
|
||||
|
||||
public void BounceUp()
|
||||
{
|
||||
velocity.y = jumpForce / 2;
|
||||
sourceJump.Play();
|
||||
}
|
||||
|
||||
private void UpdateApples()
|
||||
{
|
||||
applesText.text = applesCount + "/" + minApples;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8def6426ba2fd0a478e8088418ee44b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject player;
|
||||
|
||||
//abstand zwischen kamera und spieler
|
||||
private float yOffset;
|
||||
private float defaultYOffset;
|
||||
|
||||
//interpolationsfaktor zwischen spieler und kameraposition
|
||||
private float i = 0;
|
||||
|
||||
private float speedFactor = 50;
|
||||
|
||||
//ruckler im spiele vermeiden, aber kamera trotzdem flüssig bewegen
|
||||
private const float cameraAccuracy = 100f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//abstand kamera - spieler berechnen
|
||||
yOffset = transform.position.y - player.transform.position.y;
|
||||
defaultYOffset = yOffset;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//kamera auf der x-Achse bewegen
|
||||
transform.Translate(player.transform.position.x - transform.position.x, 0, 0);
|
||||
//kamera werte runden, um bildfehler zu vermeiden
|
||||
transform.position = new Vector3(Mathf.Round(transform.position.x * cameraAccuracy) / cameraAccuracy,
|
||||
Mathf.Round(transform.position.y * cameraAccuracy) / cameraAccuracy, -10);
|
||||
|
||||
//kamera in die niedrigste position snappen
|
||||
if (transform.position.y < 0.01f)
|
||||
{
|
||||
transform.position = new Vector3(transform.position.x, 0,
|
||||
-10);
|
||||
}
|
||||
//kamera schnell nach unten bewegen
|
||||
if (player.transform.position.y < -1.8f && transform.position.y > 0)
|
||||
{
|
||||
yOffset = defaultYOffset;
|
||||
speedFactor = 10f;
|
||||
}
|
||||
//normale kamera steuerung in höherem terrain
|
||||
else
|
||||
{
|
||||
yOffset = 0;
|
||||
speedFactor = 50;
|
||||
}
|
||||
|
||||
//interpolieren zwischen player - kamera um weiches verfolgen des spielers zu ermöglichen
|
||||
if ((player.transform.position.y >= 2f && player.transform.position.y <= 10f ||
|
||||
transform.position.y > 0 && player.transform.position.y <= 10f) && transform.position.y <= 8.31f)
|
||||
{
|
||||
transform.position = Vector2.Lerp(transform.position, player.transform.position + Vector3.up * yOffset, i);
|
||||
transform.position = new Vector3(transform.position.x, transform.position.y, -10);
|
||||
i += Time.deltaTime / speedFactor;
|
||||
}
|
||||
//keine interpolation ist das niedrigste terrain-level erreicht
|
||||
else if (player.transform.position.y < 2f)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
//fehlerhafte kamera werte ausgleichen (y)
|
||||
if (player.transform.position.y < 6.35f && transform.position.y > 8.31f)
|
||||
{
|
||||
transform.position = new Vector3(transform.position.x, 8.31f, -10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b14ea4cf4631bb747aa8140047f524dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30b25eb7909aa5545aec54627a2672f8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class HomeMenu : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject par1;
|
||||
[SerializeField] private GameObject par2;
|
||||
[SerializeField] private Image imageTransition;
|
||||
|
||||
private bool inStartScreen = true;
|
||||
private float transitionSpeed = 1000;
|
||||
private bool inTransition = false;
|
||||
private bool transitionBack = false;
|
||||
private bool activePar2 = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
par1.SetActive(true);
|
||||
par2.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(inStartScreen)
|
||||
{
|
||||
if (Input.touches.Length > 0)
|
||||
{
|
||||
inStartScreen = false;
|
||||
par1.SetActive(false);
|
||||
inTransition = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (activePar2)
|
||||
{
|
||||
par2.SetActive(true);
|
||||
}
|
||||
|
||||
if (inTransition)
|
||||
{
|
||||
if (imageTransition.rectTransform.rect.width >= Screen.width - 1000)
|
||||
{
|
||||
transitionBack = true;
|
||||
}
|
||||
|
||||
if(!transitionBack)
|
||||
{
|
||||
imageTransition.rectTransform.sizeDelta = new Vector2(
|
||||
imageTransition.rectTransform.rect.width + transitionSpeed * Time.deltaTime,
|
||||
imageTransition.rectTransform.rect.width + transitionSpeed * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageTransition.rectTransform.sizeDelta = new Vector2(
|
||||
imageTransition.rectTransform.rect.width - transitionSpeed * Time.deltaTime,
|
||||
imageTransition.rectTransform.rect.width - transitionSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (imageTransition.rectTransform.rect.width <= 0)
|
||||
{
|
||||
inTransition = false;
|
||||
activePar2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ButtonLevelPressed(Button button)
|
||||
{
|
||||
SceneManager.LoadScene(button.name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ecb830698fb3964ab52ef3f8c33ab98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user