1
0
Fork 0

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Unknown 2018-04-21 15:45:47 +02:00
commit ad4e7ef3a4
9 changed files with 231 additions and 47 deletions

105
Assets/Prefabs/Door.prefab Normal file
View file

@ -0,0 +1,105 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1046373619020340}
m_IsPrefabParent: 1
--- !u!1 &1046373619020340
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4708397045567336}
- component: {fileID: 114712631247209960}
- component: {fileID: 61859685447846418}
- component: {fileID: 61191558022818200}
m_Layer: 0
m_Name: UpperDoor
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4708397045567336
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046373619020340}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 9.06, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &61191558022818200
BoxCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046373619020340}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.3731112, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 3.025469, y: 1}
m_EdgeRadius: 0
--- !u!61 &61859685447846418
BoxCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046373619020340}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.37311125, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 3.0254688, y: 1}
m_EdgeRadius: 0
--- !u!114 &114712631247209960
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046373619020340}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b8cc30ac6e59724bba6536a17fbf027, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 88e4526bbc633401ebdaaffa8a16c3aa
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -169,6 +169,31 @@ Prefab:
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: curveSpeed
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: turnSpeed
value: 3
objectReference: {fileID: 0}
- target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: drift
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: friction
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f,
type: 2}
propertyPath: acceleration
value: 5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2}
m_IsPrefabParent: 0

View file

@ -4,5 +4,5 @@ using UnityEngine;
public class Collectable : Entity{
public Collectable (EntityObjective referringObjective, GameObject entityPrefab) : base(referringObjective, entityPrefab) {}
public Collectable (EntityObjective referringObjective) : base(referringObjective) {}
}

View file

@ -2,31 +2,19 @@
using System.Collections.Generic;
using UnityEngine;
public abstract class Entity {
public abstract class Entity : MonoBehaviour{
EntityObjective referringObjective;
GameObject entityPrefab;
GameObject instance;
// Constructor
public Entity(EntityObjective referringObjective, GameObject entityPrefab)
public Entity(EntityObjective referringObjective)
{
this.referringObjective = referringObjective;
this.entityPrefab = entityPrefab;
}
// spawns the entity
public void Spawn(Transform spawnPoint)
{
// instance = GameObject.Instantiate (entityPrefab);
// instance.transform = spawnPoint;
}
// kills the entity
public void Kill()
{
GameObject.Destroy (instance);
referringObjective.Remove (this);
instance = null;
if(referringObjective != null)
referringObjective.Remove (this.gameObject);
}
}

View file

@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Mob : Entity {
readonly int maxHP;
int currentHP;
bool isDead;
// Constructor
public Mob(EntityObjective referringObjective, int maxHP) : base(referringObjective)
{
this.maxHP = maxHP;
currentHP = maxHP;
isDead = false;
}
// inflicts damage to this mob
public void InflictDamage(int damage)
{
currentHP -= damage;
if (!isDead && currentHP <= 0)
{
base.Kill ();
isDead = true;
}
}
// Heals the mob
public void Heal(int healAmount)
{
if (!isDead)
currentHP = (currentHP + healAmount > currentHP) ? maxHP : currentHP + healAmount;
}
}

View file

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

View file

@ -3,14 +3,14 @@ using System.Collections.Generic;
using UnityEngine;
public class EntityObjective : Objective{
List<Entity> entityList;
List<GameObject> prefabList;
List<GameObject> entityList;
List<Transform> spawnPointList;
// Constructor
public EntityObjective(Room objectiveCaller, List<Entity> entityList) : base(objectiveCaller)
public EntityObjective(Room objectiveCaller, List<GameObject> prefabList) : base(objectiveCaller)
{
this.entityList = entityList;
this.spawnPointList = spawnPointList;
this.prefabList = prefabList;
spawnPointList = objectiveCaller.GetSpawnpoints ();
}
@ -19,14 +19,17 @@ public class EntityObjective : Objective{
{
Random newRand = new Random ();
foreach (Entity i in entityList)
i.Spawn(spawnPointList[Random.Range(0, spawnPointList.Count)]);
foreach (GameObject i in prefabList)
{
GameObject tempObject = GameObject.Instantiate (i);
tempObject.transform.position = spawnPointList [Random.Range (0, spawnPointList.Count)].position;
}
objectiveCaller.Lock();
}
// Removes the entity from the list and completes the objective, if the list is empty
public void Remove(Entity inputEntity)
public void Remove(GameObject inputEntity)
{
entityList.Remove (inputEntity);
if (entityList.Count == 0)

View file

@ -2,42 +2,50 @@
public class PlayerMovement : MonoBehaviour {
public float power = 3;
public float turnpower = 2;
public float curveSpeed = 0.5f;
Vector3 curspeed;
[SerializeField]
public float acceleration = 3;
[SerializeField]
public float friction = 0.1f;
[SerializeField]
public float turnSpeed = 2;
[SerializeField]
public float drift = 1f;
Rigidbody2D rigidbody2D;
// Use this for initialization
void Start()
{
void Start() {
rigidbody2D = GetComponent<Rigidbody2D>();
}
void FixedUpdate() {
Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
float speed = speedVec.magnitude;
curspeed = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
//curspeed = curspeed.normalized;
//curspeed *= maxspeed;
rigidbody2D.AddForce(transform.up * power);
Vector3 forwardNorm = (transform.localRotation * Vector3.up).normalized * curspeed.magnitude;
Vector3 br = forwardNorm - curspeed;
br *= curveSpeed;
{ // Forward
rigidbody2D.AddForce(transform.up * acceleration);
}
{// Drag
Vector3 drag = speedVec.normalized * speed * speed * friction * -1;
rigidbody2D.AddForce(drag);
Debug.DrawLine(transform.position, transform.position + drag, Color.cyan, 0.01f, false);
}
{ // Drift
Vector3 forwardNorm = (transform.localRotation * Vector3.up).normalized * speedVec.magnitude;
Vector3 br = forwardNorm - speedVec;
br *= drift;
rigidbody2D.AddForce(br);
//Debug.Log(br);
Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false);
}
if (Input.GetKey(KeyCode.A)){
transform.Rotate(Vector3.forward * turnpower);
transform.Rotate(Vector3.forward * turnSpeed);
}
if (Input.GetKey(KeyCode.D)) {
transform.Rotate(Vector3.forward * -turnpower);
transform.Rotate(Vector3.forward * -turnSpeed);
}
// Debug lines
Debug.DrawLine(transform.position, transform.position + curspeed, Color.magenta, 0.01f, false);
Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false);
Debug.DrawLine(transform.position, transform.position + speedVec, Color.magenta, 0.01f, false);
Debug.DrawLine(transform.position, transform.position + transform.localRotation * Vector3.up, Color.yellow, 0.01f, false);
//Debug.Log(transform.localRotation.eulerAngles);