new ball, collectable structure

main
Benjamin Kraft 1 year ago
parent be81262762
commit 9f770d399a
  1. 2
      Assets/Materials/Ball.mat
  2. 47
      Assets/Materials/NewBall.mat
  3. 8
      Assets/Materials/NewBall.mat.meta
  4. 220
      Assets/Prefabs/Collectables/NewBall.prefab
  5. 7
      Assets/Prefabs/Collectables/NewBall.prefab.meta
  6. 1
      Assets/Scenes/Game.unity
  7. 10
      Assets/Scripts/Game/Collectable.cs
  8. 12
      Assets/Scripts/Game/GameManager.cs
  9. 8
      Assets/Scripts/Game/Modification.cs
  10. 37
      Assets/Scripts/Game/NewBall.cs
  11. 3
      Assets/Scripts/Game/NewBall.cs.meta
  12. 3
      Assets/Scripts/Game/Wormhole.cs

@ -41,7 +41,7 @@ Material:
- PixelSnap: 0
- _EnableExternalAlpha: 0
m_Colors:
- _Color: {r: 0.740121, g: 1.9565982, b: 2.037736, a: 1}
- _Color: {r: 2, g: 2, b: 2, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []

@ -0,0 +1,47 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: NewBall
m_Shader: {fileID: 4800000, guid: da25e23f4bce4102a45b0743b67525c4, type: 3}
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- PixelSnap: 0
- _EnableExternalAlpha: 0
m_Colors:
- _Color: {r: 1.319508, g: 1.319508, b: 1.319508, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: efe64386af2c943be9fe140cdb79ee9b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,220 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2068902108434861102
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3019560421038336810}
- component: {fileID: 4286311027153464049}
m_Layer: 7
m_Name: MainColor
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3019560421038336810
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2068902108434861102}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.9, y: 0.9, z: 0.9}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 5863603256186968683}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &4286311027153464049
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2068902108434861102}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: efe64386af2c943be9fe140cdb79ee9b, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 1
m_Sprite: {fileID: 21300000, guid: 47e353a78c92b9838963e533e37462e5, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &5863603256186968685
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5863603256186968683}
- component: {fileID: 5863603256186968682}
- component: {fileID: 5863603256186968680}
- component: {fileID: 5863603256186968662}
- component: {fileID: 5863603256186968681}
m_Layer: 7
m_Name: NewBall
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5863603256186968683
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5863603256186968685}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.75, y: 0.75, z: 0.75}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 3019560421038336810}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &5863603256186968682
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5863603256186968685}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: efe64386af2c943be9fe140cdb79ee9b, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 47e353a78c92b9838963e533e37462e5, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!58 &5863603256186968680
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5863603256186968685}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.5
--- !u!114 &5863603256186968662
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5863603256186968685}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c1f92e3c448648a3977db1730f02b11d, type: 3}
m_Name:
m_EditorClassIdentifier:
permanentDuration: 5
temporaryDuration: 10
--- !u!114 &5863603256186968681
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5863603256186968685}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0b8e2f55b0355b500bb1a8ab627c8833
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1028,6 +1028,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 3237b9257f669690ea1a6f828451509e, type: 2}
- {fileID: 11400000, guid: c6de04aab82eeff81894387c19ac1310, type: 2}
wormholePrefab: {fileID: 7486271855853268360, guid: bf48a6813e1f5a2f7a63fc5c413808cb, type: 3}
newBallPrefab: {fileID: 5863603256186968685, guid: 0b8e2f55b0355b500bb1a8ab627c8833, type: 3}
--- !u!4 &2109945868
Transform:
m_ObjectHideFlags: 0

@ -1,8 +1,10 @@
using System.Collections;
using Unity.Netcode;
using UnityEngine;
namespace Game {
public abstract class Collectable : NetworkBehaviour {
private void OnTriggerEnter2D(Collider2D other) {
var player = other.GetComponent<Ball>().LastContactPlayer;
if (player != null) {
@ -11,6 +13,14 @@ namespace Game {
}
}
private IEnumerator Start() {
Setup();
yield return new WaitForSeconds(Duration());
Destroy(gameObject);
}
protected abstract void Setup();
protected abstract float Duration();
protected abstract void OnCollect(Player collector);
}
}

@ -15,6 +15,7 @@ namespace Game {
public Object modificationPrefab;
public ModificationProperties[] modifications;
public Object wormholePrefab;
public Object newBallPrefab;
public static GameManager Singleton { get; private set; }
@ -43,12 +44,14 @@ namespace Game {
SpawnModification();
yield return new WaitForSeconds(2);
SpawnWormhole();
yield return new WaitForSeconds(1);
SpawnNewBall();
}
}
private void SetupPlayers() {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.Hard;
Settings.Type = Type.AI;
Settings.AIDifficulty = Difficulty.VeryHard;
var p1Obj = Instantiate(playerPrefab);
var p2Obj = Instantiate(playerPrefab);
@ -89,6 +92,11 @@ namespace Game {
Player2 = p2;
}
private void SpawnNewBall() {
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5));
Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent<NewBall>().IsPermanent = Random.value > 0.8f;
}
private void SpawnWormhole() {
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5));
Instantiate(wormholePrefab, pos, Quaternion.identity);

@ -7,14 +7,16 @@ namespace Game {
public ModificationProperties Properties { get; set; }
private IEnumerator Start() {
protected override void Setup() {
gameObject.AddComponent<SpriteRenderer>().sprite = Properties.image;
yield return new WaitForSeconds(Properties.pickupDuration);
Destroy(gameObject);
}
protected override void OnCollect(Player collector) {
collector.StartCoroutine(collector.ProcessModification(Properties));
}
protected override float Duration() {
return Properties.pickupDuration;
}
}
}

@ -0,0 +1,37 @@
using UnityEngine;
namespace Game {
public class NewBall : Collectable {
public float permanentDuration;
public float temporaryDuration;
private bool isPermanent;
public bool IsPermanent {
private get => isPermanent;
set {
isPermanent = value;
const float intensity = 1f;
float factor = Mathf.Pow(2, intensity);
float r = value ? 1 : 0;
float g = 1;
float b = value ? 0 : 1;
Color borderColor = new Vector4(r, g, b, 1) * factor;
GetComponent<SpriteRenderer>().material.color = borderColor;
}
}
protected override void Setup() {
}
protected override float Duration() {
return IsPermanent ? permanentDuration : temporaryDuration;
}
protected override void OnCollect(Player player) {
GameManager.Singleton.SpawnBall(player, isPermanent);
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c1f92e3c448648a3977db1730f02b11d
timeCreated: 1681653966

@ -11,7 +11,7 @@ namespace Game {
private const float MaxSize = 10;
private float size;
public float Size {
private float Size {
get => size;
set {
size = value;
@ -54,6 +54,7 @@ namespace Game {
yield return Grow(duration * 0.2f);
yield return new WaitForSeconds(duration * 0.7f);
yield return Shrink(duration * 0.1f);
Destroy(gameObject);
}
private void FixedUpdate() {

Loading…
Cancel
Save