Killed Characters are put to the side

This commit is contained in:
firefighter198
2021-10-05 18:55:56 +02:00
parent cb3e7563a6
commit cc11f92f0a
7 changed files with 1937 additions and 107 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

@@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: bde12a919cdf6874cb517b5f5203db06
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+124 -71
View File
@@ -6,13 +6,19 @@ using UnityEngine;
public class Game : MonoBehaviour
{
public Camera cam;
private Cell[,] cells = new Cell[8, 8];
private Cell[] killedCharacCellsWhite = new Cell[16];
private int indexKilledCharacCellWhite = 0, indexKilledCharacCellBlack = 0;
private Cell[] killedCharacCellsBlack = new Cell[16];
public Teams currentTeam = Teams.White;
private bool areKilledCellsActive = false;
private Cell clickedCell = null;
private List<Cell> validMovesList = new List<Cell>();
public bool isPaused = false;
private void Start()
{
//Get all the Cells from the hierachy
@@ -23,82 +29,109 @@ public class Game : MonoBehaviour
cells[x, y] = GameObject.Find("Field" + y + "," + x).gameObject.GetComponent<Cell>();
}
}
for (int i = 0; i < 16; i++)
{
killedCharacCellsWhite[i] = GameObject.Find("AddCell" + i).gameObject.GetComponent<Cell>();
killedCharacCellsBlack[i] = GameObject.Find("AddCell" + i + " (1)").gameObject.GetComponent<Cell>();
}
}
private void Update()
{
//Check if left clicked
if (Input.GetMouseButtonDown(0))
if (!isPaused)
{
//Get the clicked cell
Cell tempCell = GetCellOnPositionMouse(Input.mousePosition);
//Check if left clicked
if (Input.GetMouseButtonDown(0))
{
//Get the clicked cell
Cell tempCell = GetCellOnPositionMouse(Input.mousePosition);
if(validMovesList.Contains(tempCell))
{
if (tempCell.connected != null)
if (tempCell != null)
{
Destroy(tempCell.connected.gameObject);
}
tempCell.connected = clickedCell.connected;
tempCell.connected.gameObject.transform.position = (tempCell.gameObject.transform.position + Vector3.back);
clickedCell.connected = null;
DeColorAllCells();
validMovesList.Clear();
if (currentTeam == Teams.White)
{
currentTeam = Teams.Black;
}
else
{
currentTeam = Teams.White;
}
}
else
{
//if the clickedCell == tempCell, deselect the cell
if (clickedCell == tempCell)
{
clickedCell = null;
DeColorAllCells();
validMovesList.Clear();
}
//else select the cell
else
{
clickedCell = tempCell;
ColorCellExclusive(clickedCell, new Color(.5f, .1f, .1f));
}
}
//check if there is a clicked cell
if(clickedCell != null)
{
//check if any character is on the cell
if (clickedCell.connected != null)
{
//check if the character belongs to the curren team
if (clickedCell.connected.team == currentTeam)
if (validMovesList.Contains(tempCell))
{
//get all the valid moves from the character based on the current grid
bool[,] validMoves = clickedCell.connected.GetValidMoves(cells, this);
for (int x = 0; x < 8; x++)
if (tempCell.connected != null)
{
for (int y = 0; y < 8; y++)
if (tempCell.connected.team == Teams.White)
{
if (validMoves[y, x])
tempCell.connected.gameObject.transform.position = killedCharacCellsWhite[indexKilledCharacCellWhite].gameObject.transform.position + Vector3.back;
killedCharacCellsWhite[indexKilledCharacCellWhite].connected = tempCell.connected;
indexKilledCharacCellWhite++;
}
else
{
tempCell.connected.gameObject.transform.position = killedCharacCellsBlack[indexKilledCharacCellBlack].gameObject.transform.position + Vector3.back;
killedCharacCellsBlack[indexKilledCharacCellBlack].connected = tempCell.connected;
indexKilledCharacCellBlack++;
}
}
tempCell.connected = clickedCell.connected;
tempCell.connected.gameObject.transform.position =
(tempCell.gameObject.transform.position + Vector3.back);
clickedCell.connected = null;
DeColorAllCells();
validMovesList.Clear();
if (currentTeam == Teams.White)
{
currentTeam = Teams.Black;
}
else
{
currentTeam = Teams.White;
}
}
else
{
//if the clickedCell == tempCell, deselect the cell
if (clickedCell == tempCell)
{
clickedCell = null;
DeColorAllCells();
validMovesList.Clear();
}
//else select the cell
else
{
clickedCell = tempCell;
ColorCellExclusive(clickedCell, new Color(.5f, .1f, .1f));
}
}
}
//check if there is a clicked cell
if (clickedCell != null)
{
//check if any character is on the cell
if (clickedCell.connected != null)
{
//check if the character belongs to the curren team
if (clickedCell.connected.team == currentTeam)
{
//get all the valid moves from the character based on the current grid
bool[,] validMoves = clickedCell.connected.GetValidMoves(cells, this);
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
if (cells[x, y].connected != null)
if (validMoves[y, x])
{
ColorCell(x, y, new Color(.6f, .4f, .2f));
if (cells[x, y].connected != null)
{
ColorCell(x, y, new Color(.6f, .4f, .2f));
}
else
{
ColorCell(x, y, new Color(.1f, .5f, .1f));
}
validMovesList.Add(cells[x, y]);
}
else
{
ColorCell(x, y, new Color(.1f, .5f, .1f));
}
validMovesList.Add(cells[x, y]);
}
}
}
@@ -119,12 +152,12 @@ public class Game : MonoBehaviour
}
}
}
//Color the selected cell and deColor all others
private void ColorCellExclusive(Cell cell, Color color)
{
int x = 0, y = 0;
for (int ix = 0; ix < 8; ix++)
{
for (int iy = 0; iy < 8; iy++)
@@ -136,7 +169,7 @@ public class Game : MonoBehaviour
}
}
}
ColorCellExclusive(x, y, color);
}
@@ -170,18 +203,38 @@ public class Game : MonoBehaviour
{
return GetCellOnPosition(cam.ScreenToWorldPoint(position));
}
public Cell GetCellOnPosition(Vector3 position)
{
Cell result = null;
//Shoot a raycast from mousePointer / touch position
RaycastHit2D hit = Physics2D.Raycast(position, Vector3.forward);
if (hit.collider != null)
{
result = hit.collider.gameObject.GetComponent<Cell>();
if (ArrayContainsCell2D(hit.collider.gameObject.GetComponent<Cell>(), cells) || areKilledCellsActive)
{
result = hit.collider.gameObject.GetComponent<Cell>();
}
}
return result;
}
}
private bool ArrayContainsCell2D(Cell cell, Cell[,] cells)
{
for (int x = 0; x < cells.GetLength(0); x++)
{
for (int y = 0; y < cells.GetLength(1); y++)
{
if (cells[x, y] == cell)
{
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,6 @@
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler
Cmd: compileSnippet
insize=3023 file=Assets/DefaultResourcesExtra/UI/UI/Default pass=Default cachingPP=1 ppOnly=0 stripLineD=0 buildPlatform=13 rsLen=0 pKW=UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING uKW= dKW=UNITY_UI_CLIP_RECT UNITY_UI_ALPHACLIP UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30 flags=0 lang=0 type=Vertex platform=d3d11 reqs=1 mask=6 start=49 ok=1 outsize=1338
@@ -0,0 +1,3 @@
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler
@@ -0,0 +1,6 @@
Base path: 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data', plugins path 'C:/Program Files/Unity/Hub/Editor/2021.1.13f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler
Cmd: compileSnippet
insize=3023 file=Assets/DefaultResourcesExtra/UI/UI/Default pass=Default cachingPP=1 ppOnly=0 stripLineD=0 buildPlatform=13 rsLen=0 pKW=UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_DESKTOP UNITY_HARDWARE_TIER3 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING uKW= dKW=UNITY_UI_CLIP_RECT UNITY_UI_ALPHACLIP UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30 flags=0 lang=0 type=Fragment platform=d3d11 reqs=1 mask=6 start=49 ok=1 outsize=550