Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defense Skill #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Assets/Assets/Prefabs/BacteriumPrefab.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Transform:
- {fileID: 1408851698308124207}
- {fileID: 6169499343648172233}
- {fileID: 4398187354959171617}
- {fileID: 7995478584088451676}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -106,6 +107,8 @@ MonoBehaviour:
divisionEnergy: 15
immunityCooldown: 0.1
attackCooldown: 0.1
nn:
layers: []
nn:
layers: []
genome:
Expand Down Expand Up @@ -152,6 +155,87 @@ Rigidbody2D:
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!1 &3446237261596643405
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7995478584088451676}
- component: {fileID: 4127190785237039610}
m_Layer: 8
m_Name: shell
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7995478584088451676
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3446237261596643405}
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: 498506287629652864}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &4127190785237039610
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3446237261596643405}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
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_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: 4
m_Sprite: {fileID: 21300000, guid: 2898ac0a7c57bb1489666c110f03f48c, type: 3}
m_Color: {r: 0, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1.5, y: 2}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &3505681932696426641
GameObject:
m_ObjectHideFlags: 0
Expand Down
10 changes: 9 additions & 1 deletion Assets/Assets/Scripts/Bacterium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Bacterium : MonoBehaviour
GameObject jawObject;
GameObject flagellasObject;
GameObject eyesObject;
GameObject shellObject;

private bool takingDamageAnimation = false;

Expand All @@ -68,6 +69,7 @@ void Awake()
jawObject = gameObject.transform.GetChild(1).gameObject;
flagellasObject = gameObject.transform.GetChild(2).gameObject;
eyesObject = gameObject.transform.GetChild(3).gameObject;
shellObject = gameObject.transform.GetChild(4).gameObject;

if (energy == 0) energy = startEnergy;
}
Expand Down Expand Up @@ -318,7 +320,13 @@ public void RecolorBody(Color color)
filterMouthObject.GetComponent<SpriteRenderer>().color = color;
//Flagellas
flagellasObject.GetComponent<SpriteRenderer>().color = color;

//Shell
Color shellColor = color;
shellColor.r *= 0.75f;
shellColor.g *= 0.75f;
shellColor.b *= 0.75f;
shellColor.a = genome.defenceSkill.skillPercent;
shellObject.GetComponent<SpriteRenderer>().color = shellColor;
}

public void TakeDamage(float damage)
Expand Down
37 changes: 21 additions & 16 deletions Assets/Assets/Scripts/Genome.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using System.Linq;

[System.Serializable]
public class Genome
Expand All @@ -18,6 +19,7 @@ public class Genome
static string foodName = "Food Skill";
static string attackName = "Attack Skill";
static string sizeName = "Size Skill";
static string defenceName = "Defence Skill";

public Skill[] skills =
{
Expand All @@ -33,6 +35,7 @@ public class Genome
public Skill foodSkill { get { return skills[2]; } set { skills[2] = value; } }
public Skill attackSkill { get { return skills[3]; } set { skills[3] = value; } }
public Skill sizeSkill { get { return skills[4]; } set { skills[4] = value; } }
public Skill defenceSkill { get { return skills[5]; } set { skills[5] = value; } }

public Genome(int size)
{
Expand Down Expand Up @@ -93,20 +96,20 @@ public void Mutate(float value)
//Size increases food and attack max-min caps
foreach (Skill skill in skills)
{
if (skill.name == attackName || skill.name == foodName)
if (skill.name == attackName || skill.name == foodName || skill.name == defenceName)
{
float sizeBuff = sizeSkill.value;
skill.max = sizeBuff * skill.staticMax;
skill.min = sizeBuff * skill.staticMin;
skill.value = sizeBuff * skill.value;
skill.value = Mathf.Clamp(skill.value, skill.min, skill.max); //Just to make sure
skill.maxSkill = sizeSkill.currentSkill * skill.staticMaxSkill;
skill.minSkill = sizeSkill.currentSkill * skill.staticMinSkill;
skill.currentSkill = sizeSkill.currentSkill * skill.currentSkill;
skill.currentSkill = Mathf.Clamp(skill.currentSkill, skill.minSkill, skill.maxSkill); //Just to make sure
}
}

//Food and attack sum shoudn't be above 1
float limitFactor = GetLimitFactor(1, skills[2].percent, skills[3].percent);
skills[2].percent *= limitFactor;
skills[3].percent *= limitFactor;
//Food, attack and defence sum shoudn't be above 1
float limitFactor = GetLimitFactor(1, attackSkill.skillPercent, foodSkill.skillPercent, defenceSkill.skillPercent);
foodSkill.skillPercent *= limitFactor;
attackSkill.skillPercent *= limitFactor;
defenceSkill.skillPercent *= limitFactor;

//color = Color.Lerp(color, GenerateColor(), 1f/GameManager.instance.mutationBeforeNewID);
color = GenerateColor();
Expand All @@ -119,17 +122,19 @@ public void UpdateGenomeID()
public Color GenerateColor()
{
Color color = UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 1f, 1f, 1f, 1f);
color.r = 0.2f + 0.8f * skills[3].percent;
color.g = 0.2f + 0.8f * skills[2].percent;
color.b = 0.2f;
color.r = 0.25f + 0.75f * attackSkill.skillPercent;
color.g = 0.25f + 0.75f * foodSkill.skillPercent;
color.b = 0.25f + 0.75f * defenceSkill.skillPercent; ;
return color;
}
public float GetLimitFactor(float limit, float firstVar, float secondVar)
public float GetLimitFactor(float limit, params float[] vars)
{
float factor = 1;
if (firstVar + secondVar > limit)
//Sums vars
float sum = vars.Sum();
if (sum > limit)
{
factor = limit / (firstVar + secondVar);
factor = limit / sum;
}
return factor;
}
Expand Down
Binary file added Assets/Assets/Sprites/shell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions Assets/Assets/Sprites/shell.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.