/// <summary> /// Happens once when there's a collision with a ghost. /// </summary> private void GhostCollision(GameObject ghost) { switch (ghost.GetComponent <MoveComponent>().MovementState) { case MovementState.Chase: case MovementState.Scatter: OnGhostChaseCollision(); break; case MovementState.Frightened: ResetTimer(frightenedModeTime); ConsoleSprite consoleSprite = ghost.GetComponent <ConsoleSprite>(); consoleSprite.ChangeColor( ConsoleColor.Red, ConsoleColor.DarkBlue); MoveComponent moveComponent = ghost.GetComponent <MoveComponent>(); InvertGhostDirection(ghost); moveComponent.MovementState = MovementState.Eaten; moveComponent.AddMovementBehaviour( new BlinkyChaseBehaviour( ghost, map, new MapTransformComponent(13, 11), ghost.GetComponent <MapTransformComponent>(), 3)); break; } }
void GenerateSprite() { activeSprite = new ConsoleSprite(spriteWidth, spriteHeight); var chars = new char[spriteWidth, spriteHeight]; var colors = new short[spriteWidth, spriteHeight]; activeSprite.SetData(chars, colors); }
static void Main(string[] args) { ConsoleSprite mySprite = new ConsoleSprite(); mySprite.MoveTo(100, 150); mySprite.SetY(160); Console.WriteLine(mySprite.GetX()); mySprite.SetImage('X'); mySprite.Draw(); }
public static byte[] SamplePixel(this ConsoleSprite sprite, Vector2 uv) { int x = (int)Math.Floor(uv.x * sprite.Width); int y = (int)Math.Floor(uv.y * sprite.Height); int index = y * sprite.Width + x; if (index < 0 || index >= sprite.Characters.Length || index >= sprite.Colors.Length) { return(null); } return(new byte[] { sprite.Characters[index], sprite.Colors[index] }); }
static void Main(string[] args) { if (args.Length != 0) { string text = File.ReadAllText(args[0]); text = text.Replace("~", "~\r\n"); sprite = ConsoleSprite.Load(args[0], true); } //sprite = ConsoleSprite.Load(@"F:\Projekte\C#\ConsoleSprite Editor\ConsoleSprite Editor\bin\Release\netcoreapp2.2\publish\Sprites\Test.cpr", true); MyGame g = new MyGame(); g.Run(new Display(DisplayType.Console, "Lucida Console", 128, 88, 8, 8)); }
public DefaultState(Game parent, string name, object Data) : base(parent, name) { if (Data is ConsoleSprite) { activeSprite = (ConsoleSprite)Data; } else { spriteWidth = ((Tuple <int, int>)Data).Item1; spriteHeight = ((Tuple <int, int>)Data).Item2; GenerateSprite(); } spriteX = Parent.Screen.Width / 2 - spriteWidth / 2; spriteY = Parent.Screen.Height / 3 - spriteHeight / 2; }
public static ConsoleSprite NewSprite(int width, int height) { ConsoleSprite newSprite = (ConsoleSprite)ScriptableObject.CreateInstance("ConsoleSprite"); newSprite.width = width; newSprite.height = height; newSprite.type = new int[width * height]; newSprite.glyph = new int[width * height]; newSprite.front = new Color[width * height]; newSprite.back = new Color[width * height]; newSprite.param = new float[width * height * Tile.DEFAULT_PARAM_SIZE]; for (int i = 0; i < newSprite.param.Length; i++) { newSprite.param[i] = Tile.DEFAULT_PARAM; } newSprite.destructible = new bool[width * height]; newSprite.mask = new bool[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newSprite.type[x + width * y] = Tile.DEFAULT_TYPE; newSprite.glyph[x + width * y] = Tile.DEFAULT_GLYPH; newSprite.front[x + width * y] = new Color(1.0f, 1.0f, 1.0f, 1.0f); newSprite.back[x + width * y] = new Color(0.0f, 0.0f, 0.0f, 1.0f); for (int p = 0; p < Tile.DEFAULT_PARAM_SIZE; p++) { newSprite.param[(x + width * y) * Tile.DEFAULT_PARAM_SIZE + p] = Tile.DEFAULT_PARAM; } newSprite.destructible[x + width * y] = Tile.DEFAULT_DESTRUCTIBILITY; newSprite.mask[x + width * y] = true; } } return(newSprite); }
private void CopyRoadTileToRoad(ConsoleSprite tile, int x, int y) { int i, j, index; for (i = 0; i < ROAD_TILE_SIZE; i++) { for (j = 0; j < ROAD_TILE_SIZE; j++) { index = j + i * tile.width; roadTiles[x + j, y + i].type = tile.type[index]; roadTiles[x + j, y + i].glyph = tile.glyph[index]; roadFrontColors[x + j, y + i] = tile.front[index]; roadBackColors[x + j, y + i] = tile.back[index]; roadTiles[x + j, y + i].destructible = tile.destructible[index]; } } }
private void ApplySprite(ConsoleSprite sprite) { gridWidth = sprite.Width; gridHeight = sprite.Height; var pixels = new List <PixelEntry>(gridWidth * gridHeight); for (int i = 0; i < gridWidth * gridHeight; i++) { pixels.Add(new PixelEntry()); var e = Encoding.GetEncoding("437"); var s = e.GetString(new byte[] { sprite.Characters[i] }); pixels[i].Character = s[0]; pixels[i].Color = ColorEntry.FromConsoleColor((ConsoleColor)sprite.Colors[i]); } Pixels.Reset(pixels); SupportsTransparency = sprite.IsTransparent; OnPropertyChanged("GridHeight"); OnPropertyChanged("GridWidth"); OnPropertyChanged("PixelWidth"); }
/// <summary> /// Method that defines what happens when pacman collides with /// power pills. /// </summary> private void PowerPillCollision() { ResetTimer(frightenedModeTime); foreach (GameObject ghost in ghosts) { MoveComponent moveComponent = ghost.GetComponent <MoveComponent>(); if (moveComponent.MovementState == MovementState.Eaten) { continue; } ConsoleSprite consoleSprite = ghost.GetComponent <ConsoleSprite>(); consoleSprite.ChangeColor( ConsoleColor.Red, ConsoleColor.White); moveComponent.MovementState = MovementState.Frightened; SwitchFrightenedMode(ghost); InvertGhostDirection(ghost); } }
private void SaveFile() { var colors = new byte[GridWidth * GridHeight]; var characters = new byte[colors.Length]; for (int i = 0; i < Pixels.Count; i++) { if (Pixels[i].Color.ConsoleColor == ConsoleColor.Black || Pixels[i].Character == ' ') { colors[i] = (byte)ConsoleColor.Black; characters[i] = (byte)' '; continue; } colors[i] = (byte)Pixels[i].Color.ConsoleColor; characters[i] = charLookup[Pixels[i].Character]; } var sprite = new ConsoleSprite(GridWidth, GridHeight, characters, colors, supportsTransparency); var formatter = new BinaryFormatter(); var stream = new FileStream(SavePath, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, sprite); stream.Close(); IsDirty = false; }
public bool Intersects(ConsoleSprite sprite) { return(this[0].Intersects(sprite)); }
public void OnSceneGUI() { int i, j, k, stampYIndex, stampIndex; float z0; Color glyphColor, backColor; Event e; if ((Application.isEditor == true) && (console.setupComplete == true)) { z0 = consoleTransform.position.z; e = Event.current; if (e.type == EventType.MouseDrag) { DrawGrid(); } else if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { console.shouldRefresh = true; DrawGrid(); } else { if (console.shouldRefresh == true) { RefreshConsole(); EditorUtility.SetDirty(console); console.shouldRefresh = false; } FindPointedGlyph(); if ((pointedGlyphX != previousGlyphX) || (pointedGlyphY != previousGlyphY)) { previousGlyphX = pointedGlyphX; previousGlyphY = pointedGlyphY; Repaint(); HandleUtility.Repaint(); } if ((pointedGlyphX >= 0) && (pointedGlyphX < console.width) && (pointedGlyphY >= 0) && (pointedGlyphY < console.height)) { Handles.BeginGUI(); GUILayout.BeginArea(new Rect(10.0f, 10.0f, 215.0f, (6 + Tile.DEFAULT_PARAM_SIZE) * 18.0f), sceneGUIStyle); GUILayout.BeginVertical(); GUILayout.Label("Position : " + pointedGlyphX + "," + pointedGlyphY); GUILayout.Label("Glyph Index : " + console.tiles[pointedGlyphX + console.width * pointedGlyphY].glyph); //glyphColor = console.foreground.GetPixel ( pointedGlyphX, pointedGlyphY ); glyphColor = console.tiles[pointedGlyphX + console.width * pointedGlyphY].front; GUILayout.Label("Glyph Color : r=" + string.Format("{0:0.00}", glyphColor.r) + " g=" + string.Format("{0:0.00}", glyphColor.g) + " b=" + string.Format("{0:0.00}", glyphColor.b)); //backColor = console.background.GetPixel ( pointedGlyphX, pointedGlyphY ); backColor = console.tiles[pointedGlyphX + console.width * pointedGlyphY].back; GUILayout.Label("Back Color : r=" + string.Format("{0:0.00}", backColor.r) + " g=" + string.Format("{0:0.00}", backColor.g) + " b=" + string.Format("{0:0.00}", backColor.b)); GUILayout.Label("Type : " + console.tiles[pointedGlyphX + pointedGlyphY * console.width].type); for (i = 0; i < Tile.DEFAULT_PARAM_SIZE; i++) { GUILayout.Label("Param " + i + " : " + console.tiles[pointedGlyphX + pointedGlyphY * console.width].param[i]); } GUILayout.Label("Destructible : " + (console.tiles[pointedGlyphX + pointedGlyphY * console.width].destructible ? "yes" : "no")); GUILayout.EndVertical(); GUILayout.EndArea(); Handles.EndGUI(); switch (console.currentTool) { case PEN_TOOL_INDEX: DrawPointedGlyphFrame((float)pointedGlyphX, (float)pointedGlyphY, z0); break; case LINE_TOOL_INDEX: if (firstClick == true) { DrawPointedGlyphFrame((float)pointedGlyphX, (float)pointedGlyphY, z0); } else { console.ScanLine(firstClickX, firstClickY, pointedGlyphX, pointedGlyphY); for (i = 0; i < console.lineLength; i++) { DrawFrame(console.lineScan[4 * i], console.lineScan[4 * i + 1], z0, 1.0f, 1.0f, selectionFrameColor); } } break; case STAMP_TOOL_INDEX: if (console.hasStamp == true) { DrawFrame(pointedGlyphX, pointedGlyphY, z0, pointedGlyphX + console.stamp.width <= console.width ? console.stamp.width : console.width - pointedGlyphX, pointedGlyphY + console.stamp.height <= console.height ? console.stamp.height : console.height - pointedGlyphY, stampFrameColor); } else if (firstClick == true) { DrawPointedGlyphFrame((float)pointedGlyphX, (float)pointedGlyphY, z0); } else { DrawSelectionFrame(); } break; case STROKE_RECT_TOOL_INDEX: case FILL_RECT_TOOL_INDEX: if (firstClick == true) { DrawPointedGlyphFrame((float)pointedGlyphX, (float)pointedGlyphY, z0); } else { DrawSelectionFrame(); } break; default: break; } if ((e.type == EventType.keyDown) && (e.keyCode == KeyCode.Escape)) { firstClick = true; SceneView.RepaintAll(); } if ((e.type == EventType.mouseDown) && (e.button == LEFT_BUTTON) && (e.clickCount == 1)) { switch (console.currentTool) { case PEN_TOOL_INDEX: if (e.alt == true) { if (console.DrawGlyph == true) { console.Glyph = console.tiles[pointedGlyphX + pointedGlyphY * console.width].glyph; } if (console.DrawGlyphColor == true) { console.GlyphColor = console.foreground.GetPixel(pointedGlyphX, pointedGlyphY); } if (console.DrawBackgroundColor == true) { console.BackgroundColor = console.background.GetPixel(pointedGlyphX, pointedGlyphY); } if (console.SetType == true) { console.Type = console.tiles[pointedGlyphX + pointedGlyphY * console.width].type; } if (console.SetParam == true) { Console.CopyParams(console.tiles[pointedGlyphX + pointedGlyphY * console.width].param, console.currentParam); } if (console.SetDestructability == true) { console.Destructible = console.tiles[pointedGlyphX + pointedGlyphY * console.width].destructible; } } else { RegisterConsoleUndo("Pen"); DrawGlyphInSceneView(pointedGlyphX, pointedGlyphY); EditorUtility.SetDirty(console); firstClick = false; } break; case LINE_TOOL_INDEX: if (firstClick == false) { RegisterConsoleUndo("Stroke Line"); StrokeLineInSceneView(); EditorUtility.SetDirty(console); } break; case STROKE_RECT_TOOL_INDEX: if (firstClick == false) { RegisterConsoleUndo("Stroke Rectangle"); StrokeRectangleInSceneView(); EditorUtility.SetDirty(console); } break; case FILL_RECT_TOOL_INDEX: if (firstClick == false) { RegisterConsoleUndo("Fill Rectangle"); FillRectangleInSceneView(); EditorUtility.SetDirty(console); } break; case STAMP_TOOL_INDEX: if ((firstClick == true) && (e.alt == true)) { console.hasStamp = false; } if (firstClick == false) { console.hasStamp = true; console.stampX = firstClickX < pointedGlyphX ? firstClickX : pointedGlyphX; console.stampY = firstClickY < pointedGlyphY ? firstClickY : pointedGlyphY; console.stamp = ConsoleSprite.NewSprite(Mathf.Abs(pointedGlyphX - firstClickX) + 1, Mathf.Abs(pointedGlyphY - firstClickY) + 1); for (i = 0; i < console.stamp.height; i++) { stampYIndex = i * console.stamp.width; for (j = 0; j < console.stamp.width; j++) { stampIndex = j + stampYIndex; console.stamp.glyph[stampIndex] = console.tiles[(console.stampX + j) + (console.stampY + i) * console.width].glyph; console.stamp.front[stampIndex] = console.foreground.GetPixel(console.stampX + j, console.stampY + i); console.stamp.back[stampIndex] = console.background.GetPixel(console.stampX + j, console.stampY + i); if ((console.stamp.front[stampIndex].Equals(Color.black) == true) && (console.stamp.back[stampIndex].Equals(Color.black) == true)) { console.stamp.mask[stampIndex] = false; } else { console.stamp.mask[stampIndex] = true; } console.stamp.type[stampIndex] = console.tiles[(console.stampX + j) + (console.stampY + i) * console.width].type; for (k = 0; k < Tile.DEFAULT_PARAM_SIZE; k++) { console.stamp.param[stampIndex * Tile.DEFAULT_PARAM_SIZE + k] = console.tiles [(console.stampX + j) + (console.stampY + i) * console.width].param[k]; } console.stamp.destructible[stampIndex] = console.tiles[(console.stampX + j) + (console.stampY + i) * console.width].destructible; } } EditorUtility.SetDirty(console); } if ((firstClick == true) && (e.alt == false)) { if (console.hasStamp == true) { RegisterConsoleUndo("Stamp"); DrawConsoleSpriteInScene(); EditorUtility.SetDirty(console); } firstClick = false; } break; default: break; } if (firstClick == true) { firstClick = false; firstClickX = pointedGlyphX; firstClickY = pointedGlyphY; } else { firstClick = true; } } } } } }
public void Setup(InputSystem inputSystem, ResourcesSystem resourcesSystem) { this.inputSystem = inputSystem; Handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); Map = string.Empty; Map += "MMMMMMMMMMMMMMMM"; Map += "M..............M"; Map += "M..............M"; Map += "MFFFF..........M"; Map += "M..............M"; Map += "M..............M"; Map += "M..........OOOOM"; Map += "M..............M"; Map += "M..............M"; Map += "M..............M"; Map += "MMMMMMMMMMMMMMMM"; DisplayMap = string.Empty; DisplayMap += "###~LEVEL-1~####"; DisplayMap += "# #"; DisplayMap += "# #"; DisplayMap += "# #"; DisplayMap += "# #####"; DisplayMap += "# #"; DisplayMap += "# #"; DisplayMap += "##### #"; DisplayMap += "# #"; DisplayMap += "# #"; DisplayMap += "################"; ScreenSize = new Vector2Int(Console.WindowWidth, Console.WindowHeight); Cameras = new List <ICameraComponent>(); var camera = CreateCamera(); camera.ViewPort = new Rect(0f, 0f, 1f, 1f); camera.Entity.GetComponent <ITransformComponent>().Position = new Vector2(8f, 5f); Cameras.Add(camera); //var camera2 = CreateCamera(); //camera2.ViewPort = new Rect(0.5f, 0.5f, 0.5f, 0.5f); //camera2.Entity.GetComponent<ITransformComponent>().Position = new Vector2(8f, 5f); //Cameras.Add(camera2); wallMaterial = resourcesSystem.Load <ConsoleMaterial>("Materials/BrickMaterial"); floorSprite = resourcesSystem.Load <ConsoleSprite>("Textures/brick_wall"); Renderers = new List <IRendererComponent>(); var cat = CreateCat(); cat.Entity.GetComponent <ITransformComponent>().Position = new Vector2(8.5f, 8.5f); cat.Entity.GetComponent <IRendererComponent>().Material = resourcesSystem.Load <ConsoleMaterial>("Materials/CatMaterial"); Renderers.Add(cat); cat = CreateCat(); cat.Entity.GetComponent <ITransformComponent>().Position = new Vector2(9.5f, 9.5f); cat.Entity.GetComponent <IRendererComponent>().Material = resourcesSystem.Load <ConsoleMaterial>("Materials/CatMaterial"); Renderers.Add(cat); UpdateCharBuffer(); skybox = resourcesSystem.Load <SkyboxMaterial>("Materials/Skybox"); }
void HandleInput() { var prevMouseX = mouse.X; var prevMouseY = mouse.Y; mouse = Input.GetMouse(); if (Input.GetKey(Key.Escape).Pressed) { MyGame.ChangeStates(new InitialState(Parent, "Initial State")); } if (mouse.IsRightClick()) { var MouseXDelta = mouse.X - prevMouseX; var MouseYDelta = mouse.Y - prevMouseY; spriteX += MouseXDelta; spriteY += MouseYDelta; } if (Input.GetKey(Key.LeftShift).Held) { if (scale + mouse.Z * Parent.DeltaTime < 1) { scale = 1f; } else { scale += mouse.Z * Parent.DeltaTime; } } else { colorValue.Value += mouse.Z; } var x = (int)((mouse.X - spriteX) * (1f / (scale * scale))); var y = (int)((mouse.Y - spriteY) * (1f / (scale * scale)));//why the f**k does this work?!?!?!?!? if (mouse.IsLeftClick()) { activeSprite.SetChar(x, y, characterValue); activeSprite.SetColor(x, y, (byte)colorValue.Value); } cont--; if (colorValue.IsOnUp(mouse.X, mouse.Y) && mouse.IsLeftClick() && cont <= 0) { colorValue.Increment(); cont = freq; } if (colorValue.IsOnDown(mouse.X, mouse.Y) && mouse.IsLeftClick() && cont <= 0) { colorValue.Decrement(); cont = freq; } if (exportSprButton.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { stateValue = State.SpriteSave; } if (importPalButton.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { activeSprite = ConsoleSprite.Load("Test"); } if (palettePanel.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { var xPos = Parent.Screen.Width - 12; var yPos = Parent.Screen.Height - 2; colorIndex = (short)(mouse.X - (xPos) + (8 * (mouse.Y - yPos))); color = ColorChanger.GetColor(colorIndex); colorWindow.color = colorIndex; colorWindow.R.Value = color.R; colorWindow.G.Value = color.G; colorWindow.B.Value = color.B; stateValue = State.ColorWindow; } for (int i = 0; i < components.Count; i++) { if (components[i].IsInside(mouse.X, mouse.Y)) { components[i].BorderColor = 12; } else { components[i].BorderColor = 8; } if (components[i].Clickable && components[i].IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { components[i].BorderColor = 10; } } if (resetButton.IsInside(mouse.X, mouse.Y)) { resetButton.BorderColor = 12; } else { resetButton.BorderColor = 8; } if (resetButton.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { resetButton.BorderColor = 10; ColorChanger.SetColor(0, Color.FromArgb(0, 0, 0)); for (int i = 0; i < 16; i++) { ColorChanger.SetColor(i, ColorChanger.StandardColors.colors[i]); } } if (exportPalButton.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { stateValue = State.PaletteSave; } if (importPalButton.IsInside(mouse.X, mouse.Y) && mouse.IsLeftClick()) { ColorChanger.SetPalette(Palette.Load("TestPalette")); } }