public Chunk(Vector2s position, short[][] chunkData) { this._position = position; this._chunkData = chunkData; _isPlaced = false; }
public static Vector2s Next(this Random random, Vector2s min, Vector2s max) { return(new Vector2s( (short)random.Next(min.X, max.X + 1), (short)random.Next(min.Y, max.Y + 1) )); }
public WorldSlice(World world, Vector2s position) { this._world = world; this.position = position; this._blocks = world.GenerateBlocks(position); }
public BasicBlock(BlockType t, Vector2s i, BlockTexture texture, bool solid = true) { type = t; icon = i; blockTexture = texture; isSolid = solid; }
public async virtual ValueTask Update(CanvasTimingInformation timing) { if (Visible) { _showTimer.Run(timing); if (Vector2s.AreNear(_pacman.Position, Position, 4)) { await _mediator.Publish(new FruitEatenEvent(this)); Visible = false; } return; } if (_playerStats == null) { throw new InvalidOperationException("no player stats set!"); } var levelStats = _playerStats.LevelStats; if (levelStats.FruitSession.ShouldShow && !_isDemo) { Visible = true; _showTimer.Reset(); } SetFruitItem(levelStats.GetLevelProps().Fruit1); }
public static Vector2s Next(this Random random, Vector2s min, Vector2s max) { return new Vector2s( (short)random.Next(min.X, max.X + 1), (short)random.Next(min.Y, max.Y + 1) ); }
public async ValueTask <ActUpdateResult> Update(CanvasTimingInformation timing) { if (_finished) { return(ActUpdateResult.Finished); } _tempTimers.Update(timing); if (_ghostsChasing) { await _powerPillLegend.Update(timing); await _powerPillToEat.Update(timing); _ghostTimer.Run(timing); _pacTimer.Run(timing); _ghostEatenTimer.Run(timing); } await _pillLegend.Update(timing); _tempSprites.Update(timing); lerpPacMan(); foreach (var g in _ghosts) { if (!g.Alive) { continue; } lerpGhost(g); await g.Update(timing); if (Vector2s.AreNear(_pacMan.Position, g.Position, 2)) { ghostEaten(g); if (g.NickName == GhostNickname.Clyde) { _tempTimers.Add(new EggTimer(1.Seconds(), () => { _finished = true; })); } } } await _pacMan.Update(timing); return(ActUpdateResult.Running); }
// 增加材質座標 public void AddTexture(Vector2s side) { float textureSizeCols = 1f / world.basic.tileCols; float textureSizeRows = 1f / world.basic.tileRows; float c1 = side.y / world.basic.tileCols; float r1 = side.x / world.basic.tileRows; r1 = 1f - r1 - textureSizeRows; float c2 = c1 + textureSizeCols; float r2 = r1 + textureSizeRows; uvs.Add(new Vector2s(c1, r1)); uvs.Add(new Vector2s(c1, r2)); uvs.Add(new Vector2s(c2, r1)); uvs.Add(new Vector2s(c2, r2)); }
public void ChangeSkin(BlockType type) { _type = type; MeshFilter meshFilter = item.GetComponent <MeshFilter>(); List <Vector2s> uvs = new List <Vector2s>(); for (int p = 0; p < 6; p++) { Vector2s side = basic.Blocks[(int)_type].GetTextureID(p); float textureSizeCols = 1f / basic.tileCols; float textureSizeRows = 1f / basic.tileRows; float c1 = side.y / basic.tileCols; float r1 = side.x / basic.tileRows; r1 = 1f - r1 - textureSizeRows; float c2 = c1 + textureSizeCols; float r2 = r1 + textureSizeRows; for (int i = 0; i < 4; i++) { vertices.Add(VoxelData.voxelVerts[VoxelData.voxelTris[p, i]]); } uvs.Add(new Vector2s(c1, r1)); uvs.Add(new Vector2s(c1, r2)); uvs.Add(new Vector2s(c2, r1)); uvs.Add(new Vector2s(c2, r2)); triangles.Add(vertexIndex); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 2); triangles.Add(vertexIndex + 2); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 3); vertexIndex += 4; } meshFilter.mesh.vertices = World.sl3vl(vertices).ToArray(); meshFilter.mesh.SetTriangles(triangles.ToArray(), 0); meshFilter.mesh.uv = World.sl2vl(uvs).ToArray(); meshFilter.mesh.RecalculateNormals(); }
public int[][] GenerateBlocks(Vector2s position) { return new int[WorldSlice.DIMENSIONS][] { new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], new int[WorldSlice.DIMENSIONS], }; }
public WorldSlice this[Vector2s position] { get { if (worldSlices.ContainsKey(position)) return worldSlices[position]; return null; } set { if (!worldSlices.ContainsKey(position)) worldSlices[position] = value; else { // Check if same position foreach (var positionKey in worldSlices.Keys) { if (positionKey.Equals(positionKey, position)) { Debug.LogError("Tried to place duplicate chunk at x:" + position.x + ", y:" + position.y); return; } } // Actually a hash collision, let's find it foreach (var positionKey in worldSlices.Keys) { if (positionKey.GetHashCode() == position.GetHashCode()) { Debug.LogError("Hash collision for pos x:" + position.x + ", y:" + position.y + " && x:" + positionKey.x + ", y:" + positionKey.y); return; } } } } }
public KeyValuePair<Vector2s, WorldSlice>[] GetNeighbours(Vector2s pos) { var pos0 = new Vector2s((short)(pos.x - 1), (short)(pos.y - 1)); var pos1 = new Vector2s((short)(pos.x), (short)(pos.y - 1)); var pos2 = new Vector2s((short)(pos.x + 1), (short)(pos.y - 1)); var pos3 = new Vector2s((short)(pos.x - 1), (short)(pos.y)); var pos4 = new Vector2s((short)(pos.x + 1), (short)(pos.y)); var pos5 = new Vector2s((short)(pos.x - 1), (short)(pos.y + 1)); var pos6 = new Vector2s((short)(pos.x), (short)(pos.y + 1)); var pos7 = new Vector2s((short)(pos.x + 1), (short)(pos.y + 1)); return new KeyValuePair<Vector2s, WorldSlice>[8] { new KeyValuePair<Vector2s, WorldSlice> (pos0, this[pos0]), new KeyValuePair<Vector2s, WorldSlice> (pos1, this[pos1]), new KeyValuePair<Vector2s, WorldSlice> (pos2, this[pos2]), new KeyValuePair<Vector2s, WorldSlice> (pos3, this[pos3]), new KeyValuePair<Vector2s, WorldSlice> (pos4, this[pos4]), new KeyValuePair<Vector2s, WorldSlice> (pos5, this[pos5]), new KeyValuePair<Vector2s, WorldSlice> (pos6, this[pos6]), new KeyValuePair<Vector2s, WorldSlice> (pos7, this[pos7]), }; }
public BlockTexture(Vector2s s) { Side = s; Plane = s; Under = s; }
public BlockTexture(Vector2s s, Vector2s p) { Side = s; Under = p; Plane = p; }
void lerpPacMan() { _pacMan.Position = Vector2s.Lerp(_pacPositions.Start, _pacPositions.End, _pacTimer.Progress); }
void lerpGhost(AttractGhost ghost) { StartAndEndPos positions = _ghostPositions[ghost.NickName]; ghost.Position = Vector2s.Lerp(positions.Start, positions.End, _ghostTimer.Progress); }
public Vector2s(Vector2s clone) { x = clone.x; y = clone.y; }
bool isNearHouseEntrance() => Vector2s.AreNear(Ghost.Position, Maze.PixelHouseEntrancePoint, .75);
public void Read(BinaryReaderEx br) { long pos = br.BaseStream.Position; for (int i = 0; i < 9; i++) { ind[i] = br.ReadInt16(); } quadFlags = (QuadFlags)br.ReadUInt16(); bitvalue = br.ReadUInt32Big(); { drawOrderLow = (byte)(bitvalue & 0xFF); for (int i = 0; i < 4; i++) { byte val = (byte)(bitvalue >> 8 + 5 * i & 0x1F); faceFlags[i] = new FaceFlags(val); } extradata = (byte)(bitvalue & 0xF0000000 >> 28); } drawOrderHigh = br.ReadBytes(4); for (int i = 0; i < 4; i++) { ptrTexMid[i] = br.ReadUInt32(); } bb = new BoundingBox(br); byte tf = br.ReadByte(); if (tf > 20) { Helpers.Panic(this, "unexpected terrain flag value -> " + tf); } terrainFlag = (TerrainFlags)tf; WeatherIntensity = br.ReadByte(); WeatherType = br.ReadByte(); TerrainFlagUnknown = br.ReadByte(); id = br.ReadInt16(); trackPos = br.ReadByte(); midunk = br.ReadByte(); //midflags = br.ReadBytes(2); Debug.Log(br.BaseStream.Position); ptrTexLow = br.ReadUInt32(); offset2 = br.ReadInt32(); Debug.Log(offset2); for (int i = 0; i < 5; i++) { Vector2s v = new Vector2s(br); unk3.Add(v); Debug.Log(v); } //struct done //read texture layouts int texpos = (int)br.BaseStream.Position; Debug.Log(ptrTexLow); br.Jump(ptrTexLow); texlow = TextureLayout.FromStream(br); Debug.Log(ptrTexLow / 16 + ", " + ptrTexMid.Length); Debug.Log(ptrTexMid[0] + ", " + ptrTexMid[1] + ", " + ptrTexMid[2] + ", " + ptrTexMid[3] + "; "); if (38435 == ptrTexLow / 16) { Debug.Log("----------THE INTERESTING ONE----------"); } foreach (uint u in ptrTexMid) { if (u != 0) { br.Jump(u); tex.Add(new CtrTex(br)); } else { if (ptrTexLow != 0) { Console.WriteLine("!"); } } } br.BaseStream.Position = texpos; }
/// <summary>Read a <see cref="Vector2s"/>.</summary> public static void ReadVector2s(this BinaryReader reader , out Vector2s result) { result.X = reader.ReadInt16(); result.Y = reader.ReadInt16(); return; }
/// <summary>Read an array of <c>Vector2s</c> values.</summary> public static Vector2s[] ReadArrayVector2s(this BinaryReader reader, int count) { Vector2s[] array = new Vector2s[count]; reader.ReadArray(array, 0, count); return array; }
public static Vector2 s2v(Vector2s a) { return(new Vector2(a.x, a.y)); }
public void CreateInitialLevel() { const short lSize = 12; var realLevelChunks = new List<Chunk>(); _level = new Level(); var startPosition = new Vector2s(0,0); { var firstChunk = new Chunk(startPosition, ChunkData.SquareRoomEmpty()); _level[startPosition] = firstChunk; realLevelChunks.Add(firstChunk); } var previousPosition = startPosition; const int Num_Walks = 12; for (int number = 0; number < Num_Walks; number++) { Vector2s newPos; if (Random.value > 0.5f) newPos = new Vector2s((short)(previousPosition.x + 1), previousPosition.y); else newPos = new Vector2s(previousPosition.x, (short)(previousPosition.y + 1)); Chunk testChunk; if (number == Num_Walks - 1) testChunk = new Chunk(newPos, ChunkData.TreasureRoom()); else testChunk = new Chunk(newPos, ChunkData.SquareRoomRandom()); _level[newPos] = testChunk; realLevelChunks.Add(testChunk); previousPosition = new Vector2s(newPos.x, newPos.y); } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { if (Random.value > 0.6f) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SquareRoomRandom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); realLevelChunks.Add(newNeighbour); } } } } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { if (Random.value > 0.7f) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SquareRoomRandom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); realLevelChunks.Add(newNeighbour); } } } } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SolidRoom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); } } } /* for (short i = -lSize; i < lSize; i++) { for (short j = -lSize; j < lSize; j++) { var testPosition = new Vector2s(i, j); var testChunk = new Chunk(testPosition, ChunkData.SquareRoomRandom()); _level[testPosition] = testChunk; testChunk.Place(); } } */ }