1
0
Fork 0

Add coins as collection event | Added GetPlayer() to Objective

This commit is contained in:
Saibotk 2018-04-23 23:14:55 +02:00
parent 55a0a24914
commit 0fb7631b77
14 changed files with 642 additions and 410 deletions

145
Assets/Prefabs/Coin.prefab Normal file
View file

@ -0,0 +1,145 @@
%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: 1974526777167790}
m_IsPrefabParent: 1
--- !u!1 &1797689433515008
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4913752447394922}
- component: {fileID: 212353043096038578}
m_Layer: 0
m_Name: coin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1974526777167790
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4395446404358834}
- component: {fileID: 58442750661671820}
- component: {fileID: 114638934637166232}
m_Layer: 0
m_Name: Coin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4395446404358834
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1974526777167790}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4913752447394922}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4913752447394922
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1797689433515008}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4395446404358834}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!58 &58442750661671820
CircleCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1974526777167790}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.010867804, y: 0}
serializedVersion: 2
m_Radius: 0.38045308
--- !u!114 &114638934637166232
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1974526777167790}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba8e1d7b878a1234390e852ac146280f, type: 3}
m_Name:
m_EditorClassIdentifier:
collector: {fileID: 0}
--- !u!212 &212353043096038578
SpriteRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1797689433515008}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 1310459315
m_SortingLayer: -1
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: bdae77f5d1df9744baf4a2e174270ffa, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 10, y: 10}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0

View file

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

View file

@ -799,52 +799,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &809524311
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4665188581213052, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
m_IsPrefabParent: 0
--- !u!1 &816024604
GameObject:
m_ObjectHideFlags: 0
@ -1459,7 +1413,7 @@ Prefab:
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2}
propertyPath: m_AnchoredPosition.x
value: 64.16286
value: 64.21245
objectReference: {fileID: 0}
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2}
@ -1992,6 +1946,52 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &1915345372
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4395446404358834, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
m_IsPrefabParent: 0
--- !u!1 &2012930729
GameObject:
m_ObjectHideFlags: 0
@ -2284,6 +2284,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
scorpion: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2}
bug: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2}
coin: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2}
BorderOuter: {fileID: 1062532744197412, guid: bc306521f11be424f9833117977b4319,
type: 2}
BorderInner: {fileID: 1893245914782828, guid: 7326753bf2b213d4e8c2ee93d78ba7d9,

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Assets.Scripts.Entities {
[RequireComponent(typeof(Collider2D))]
public class Coin : Entity {
void OnTriggerEnter2D(Collider2D bumper) {
if ( objective == null )
return;
Player ply = objective.GetPlayer();
if ( ply != null && ply.gameObject != null && bumper.gameObject.Equals(ply.gameObject) ) {
Debug.Log("Collected coin...");
objective.RemoveEntity(this);
GameObject.Destroy(this.gameObject);
}
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a1c36145cdffcde4c83f575b19b85c88
guid: ba8e1d7b878a1234390e852ac146280f
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,3 +0,0 @@
public class Collectable : Entity {
public Collectable() : base() { }
}

View file

@ -5,10 +5,6 @@ using Assets.Scripts.Entities.Attack;
namespace Assets.Scripts.Entities {
public class Enemy : Mob {
public enum Enemys {
SCORPION,
BUG
}
[SerializeField]
private float speed = 1;
@ -31,11 +27,23 @@ namespace Assets.Scripts.Entities {
ps.Play();
}
}
if ( objective != null ) {
Player ply = objective.GetPlayer();
if ( ply != null )
victim = ply.gameObject;
}
}
void Update() {
if ( victim == null || attack == null ) {
if ( objective != null ) {
Player ply = objective.GetPlayer();
if ( ply != null )
victim = ply.gameObject;
}
return;
}
@ -64,9 +72,5 @@ namespace Assets.Scripts.Entities {
}
public void SetVictim(GameObject g) {
victim = g;
}
}
}

View file

@ -3,6 +3,12 @@ using System.Collections.Generic;
using UnityEngine;
public abstract class Entity : MonoBehaviour {
public enum Entities {
SCORPION,
BUG,
COIN
}
protected EntityObjective objective;
/// <summary>

View file

@ -12,7 +12,7 @@ namespace Assets.Scripts.Entities
}
private void Start()
protected override void Start()
{
SetAttack(new SingleShot(this.gameObject));
}

View file

@ -13,11 +13,13 @@ public class GameController : MonoBehaviour {
}
// Enemy Prefabs
[Header("Enemys")]
[Header("Entities")]
[SerializeField]
GameObject scorpion;
[SerializeField]
GameObject bug;
[SerializeField]
GameObject coin;
[Space(10)]
// Generation Settings
@ -76,7 +78,7 @@ public class GameController : MonoBehaviour {
GameObject Flag;
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
private Dictionary<Enemy.Enemys, GameObject> enemyPrefabs;
private Dictionary<Entity.Entities, GameObject> entitiesPrefabs;
[Space(10)]
[Header("References")]
@ -135,9 +137,10 @@ public class GameController : MonoBehaviour {
{ GenerationProcessor.ExtendedTileType.DoorOuter, DoorOuter },
{ GenerationProcessor.ExtendedTileType.Flag, Flag }
};
enemyPrefabs = new Dictionary<Enemy.Enemys, GameObject> {
{ Enemy.Enemys.SCORPION, scorpion },
{ Enemy.Enemys.BUG, bug }
entitiesPrefabs = new Dictionary<Entity.Entities, GameObject> {
{ Entity.Entities.SCORPION, scorpion },
{ Entity.Entities.BUG, bug },
{ Entity.Entities.COIN, coin }
};
}
@ -327,8 +330,8 @@ public class GameController : MonoBehaviour {
return ui.GetComponent<UIController>();
}
public Dictionary<Enemy.Enemys, GameObject> GetEnemyPrefabs() {
return enemyPrefabs;
public Dictionary<Entity.Entities, GameObject> GetEntitiesPrefabs() {
return entitiesPrefabs;
}
public bool GameEnded() {

View file

@ -442,18 +442,18 @@ public class DungeonGenerator {
}
public static void GenerateObjective(Room r) {
Dictionary<Enemy.Enemys, GameObject> enemyPrefabs = GameController.instance.GetEnemyPrefabs(); // TODO not so cool
Dictionary<Entity.Entities, GameObject> enemyPrefabs = GameController.instance.GetEntitiesPrefabs(); // TODO not so cool
Objective o = null;
int rand = UnityEngine.Random.Range(0, 2);
int rand = UnityEngine.Random.Range(0, 3);
switch (rand) {
case 0: {
// Scorpion Attack!!!!:
List<GameObject> lg = new List<GameObject>();
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
for ( int c = 0; c < count; c++ ) {
lg.Add(enemyPrefabs[Enemy.Enemys.SCORPION]);
lg.Add(enemyPrefabs[Entity.Entities.SCORPION]);
}
EntityObjective eo = new EntityObjective(r, lg);
o = eo;
@ -464,12 +464,23 @@ public class DungeonGenerator {
List<GameObject> lg = new List<GameObject>();
int count = UnityEngine.Random.Range(1, r.GetSpawnpoints().Count);
for ( int c = 0; c < count; c++ ) {
lg.Add(enemyPrefabs[Enemy.Enemys.BUG]);
lg.Add(enemyPrefabs[Entity.Entities.BUG]);
}
EntityObjective eo = new EntityObjective(r, lg);
o = eo;
}
break;
case 2: {
// Coins!!!!:
List<GameObject> lg = new List<GameObject>();
int count = UnityEngine.Random.Range(1, (int) Mathf.Floor(r.GetSpawnpoints().Count / 2));
for ( int c = 0; c < count; c++ ) {
lg.Add(enemyPrefabs[Entity.Entities.COIN]);
}
EntityObjective eo = new EntityObjective(r, lg);
o = eo;
}
break;
}
r.SetObjective(o);

View file

@ -38,8 +38,7 @@ public class EntityObjective : Objective {
GameObject tempObject = GameObject.Instantiate(i);
List<Transform> spawnPointList = room.GetSpawnpoints();
tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position;
tempObject.GetComponent<Enemy>().SetVictim(player.gameObject);
tempObject.GetComponent<Enemy>().SetObjective(this);
tempObject.GetComponent<Entity>().SetObjective(this);
entityList.Add(tempObject);
}

View file

@ -47,5 +47,9 @@ public abstract class Objective {
return finished;
}
public Player GetPlayer() {
return player;
}
}

View file

@ -43,7 +43,7 @@ TextureImporter:
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spritePixelsToUnits: 1000
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
@ -67,6 +67,39 @@ TextureImporter:
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []