diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..bf5beaa66886f6d7eaf28cbf18c29b892d18c7ca --- /dev/null +++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.Cat Rescue.iml +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml new file mode 100644 index 0000000000000000000000000000000000000000..7b08163cebc50fb3e777eea4881b68fcebc10590 --- /dev/null +++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="UserContentModel"> + <attachedFolders /> + <explicitIncludes /> + <explicitExcludes /> + </component> +</project> \ No newline at end of file diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/Cat Rescue/Cat Rescue.sln b/Cat Rescue/Cat Rescue.sln new file mode 100644 index 0000000000000000000000000000000000000000..dcb20c9473db3d8fad2d92d0b60da6f48f0ce8be --- /dev/null +++ b/Cat Rescue/Cat Rescue.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cat Rescue", "Cat Rescue\Cat Rescue.csproj", "{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Cat Rescue/Cat Rescue/Cat Rescue.cs b/Cat Rescue/Cat Rescue/Cat Rescue.cs new file mode 100644 index 0000000000000000000000000000000000000000..25c38b4b3d4c48374e2ec30f9ab0ed9a404a9327 --- /dev/null +++ b/Cat Rescue/Cat Rescue/Cat Rescue.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using Jypeli; +using Jypeli.Assets; +using Jypeli.Controls; +using Jypeli.Widgets; + +namespace Cat_Rescue; + +/// @author Tomi +/// @version 14.03.2025 +/// <summary> +/// +/// </summary> +public class Cat_Rescue : Game +{ + private static readonly String[] lines1 = { + " YYYYYYYYYYYYYYYYYYYYYYYY ", + " Y X Y ", + " Y # X = Y ", + " Y * X Y ", + " Y X XXX XXX Y ", + " Y X X X Y ", + " YXX XXXX X X Y ", + " Y X X Y ", + " Y = X X Y ", + " Y X X Y ", + " YXX XXXXXXXX X Y ", + " Y X X Y ", + " Y X X Y ", + " Y # X # X Y ", + " Y X X C Y ", + " Y X X Y ", + " YYYYYYYYYYYYYYYYYYYYYYYY ", + }; + private static readonly String[] level1 = { + " YYYYYYYYYYYYYYYYYYYYYYYY ", + " Y X Y ", + " Y 0 X = Y ", + " Y X Y ", + " Y X XXX XXX Y ", + " Y X X X Y ", + " YXX XXXX X X Y ", + " Y X X Y ", + " Y = X X Y ", + " Y X X Y ", + " YXX XXXXXXXX X Y ", + " Y X X Y ", + " Y X X Y ", + " Y 1 X 2 X Y ", + " Y X X Y ", + " YC * X X Y ", + " YYYYYYYYYYYYYYYYYYYYYYYY ", + }; + + private int[] playerPos = new int[2]; + private bool playerMoveCooldown = true; + + private int[,] map_entities = new int[24,24]; + + //private Image planksImage = LoadImage(""); + //private Image oWallImage = LoadImage(""); + //private Image iWallImage = LoadImage(""); + //private Image keyImage = LoadImage(""); + //private Image cageImage = LoadImage(""); + + private GameObject player; + private GameObject key; + private GameObject[] cage = new GameObject[3]; + + private bool keyHeld = false; + + public override void Begin() + { + CreateMap(); + + CreateKeys(); + + PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); + Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); + } + + private void CreateMap() + { + Level.Background.CreateGradient(Color.SlateGray, Color.ForestGreen); + + CreateFloor(750, 500, Color.LightGray); + + + + TileMap tiles = TileMap.FromStringArray(level1); + tiles.SetTileMethod('X', CreateWall, Color.Gray); + tiles.SetTileMethod('Y', CreateWall, Color.DarkGray); + tiles.SetTileMethod('*', CreateKey, Color.LightYellow); + tiles.SetTileMethod('=', CreateGuard, Color.Salmon); + tiles.SetTileMethod('C', CreatePlayer, Color.White); + for (int i = 0; i < 3; i++) + { + tiles.SetTileMethod(Convert.ToChar((char)(i+48)), CreateCage, Color.LightBlue, i); + } + + tiles.Execute(32, 32); + Camera.ZoomToLevel(); + } + + + + private void CreateWall(Vector location, double width, double height, Color color) + { + GameObject wall = new GameObject(width, height); + wall.Position = location; + wall.Color = color; + map_entities[Convert.ToInt16(wall.X/32+11.5), Convert.ToInt16(wall.Y/32+8)] = 1; + Add(wall); + } + + private void CreateFloor(double width, double height, Color color) + { + GameObject floor = new GameObject(width, height); + floor.Color = color; + Add(floor); + } + + private void CreateCage(Vector location, double width, double height, Color color, int id) + { + cage[id] = new GameObject(width, height); + cage[id].Position = location; + cage[id].Color = color; + map_entities[Convert.ToInt16(cage[id].X/32+11.5), Convert.ToInt16(cage[id].Y/32+8)] = (id + 3); + Add(cage[id]); + } + + private void CreateKey(Vector location, double width, double height, Color color) + { + key = new GameObject(width, height); + key.Position = location; + key.Color = color; + map_entities[Convert.ToInt16(key.X/32+11.5), Convert.ToInt16(key.Y/32+8)] = 2; + Add(key); + } + + private void CreateGuard(Vector location, double width, double height, Color color) + { + GameObject guard = new GameObject(width, height); + guard.Position = location; + guard.Color = color; + Add(guard); + } + + private void CreatePlayer(Vector location, double width, double height, Color color) + { + player = new GameObject(width, height); + player.Position = location; + player.Color = color; + player.Tag = "Player"; + playerPos[0] = 1; + playerPos[1] = 1; + + Add(player); + } + + private void CreateKeys() + { + Keyboard.Listen(Key.W, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 0, 1); + Keyboard.Listen(Key.A, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, -1, 0); + Keyboard.Listen(Key.S, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 0, -1); + Keyboard.Listen(Key.D, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 1, 0); + } + + private void MovePlayer(GameObject entity, int x, int y) + { + if (playerMoveCooldown) + { + if (map_entities[playerPos[0] + x, playerPos[1] + y] != 1) + { + playerMoveCooldown = false; + if (map_entities[playerPos[0] + x, playerPos[1] + y] == 2) + { + key.Destroy(); + keyHeld = true; + Console.WriteLine("Key Found!"); + } + if (map_entities[playerPos[0] + x, playerPos[1] + y] > 2 && keyHeld == true) + { + for (int i = 0; i < 3; i++) + { + if (map_entities[playerPos[0] + x, playerPos[1] + y] == (i + 3)) + { + cage[i].Destroy(); + } + } + Console.WriteLine("Cat Freed!"); + } + player.MoveTo(new Vector((playerPos[0]-11.5+ x)*32, (playerPos[1]-8+y)*32), 50, playerPosSet(x, y)); + } + } + } + + private System.Action playerPosSet(int x, int y) + { + playerPos[0] += x; + playerPos[1] += y; + playerMoveCooldown = true; + return null; + } + + private void KillMe() + { + Console.WriteLine("Fuck!"); + } +} \ No newline at end of file diff --git a/Cat Rescue/Cat Rescue/Cat Rescue.csproj b/Cat Rescue/Cat Rescue/Cat Rescue.csproj new file mode 100644 index 0000000000000000000000000000000000000000..661798488341a5e912a75630c26b5d167a7e3053 --- /dev/null +++ b/Cat Rescue/Cat Rescue/Cat Rescue.csproj @@ -0,0 +1,12 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>net8.0</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Jypeli.NET" Version="11.*"/> + </ItemGroup> + +</Project> diff --git a/Cat Rescue/Cat Rescue/Images/floortile32.png b/Cat Rescue/Cat Rescue/Images/floortile32.png new file mode 100644 index 0000000000000000000000000000000000000000..b1e4207843bebc91c186b622eb1a47346cd88630 Binary files /dev/null and b/Cat Rescue/Cat Rescue/Images/floortile32.png differ diff --git a/Cat Rescue/Cat Rescue/Ohjelma.cs b/Cat Rescue/Cat Rescue/Ohjelma.cs new file mode 100644 index 0000000000000000000000000000000000000000..4f52c6e963d8db8115871751f10593539d8951e2 --- /dev/null +++ b/Cat Rescue/Cat Rescue/Ohjelma.cs @@ -0,0 +1,26 @@ +#region Using Statements + +using System; +using System.Collections.Generic; +using System.Linq; + +#endregion + +namespace Cat_Rescue +{ + /// <summary> + /// The main class. + /// </summary> + public static class Program + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main() + { + using var game = new Cat_Rescue(); + game.Run(); + } + } +} \ No newline at end of file