diff --git "a/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/.gitignore" "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..11128c4a86746f3cff8ce5cdb192307fd96029ca --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/.gitignore" @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/contentModel.xml +/modules.xml +/.idea.NukkuMatti -harjoitustyö.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git "a/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/indexLayout.xml" "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/indexLayout.xml" new file mode 100644 index 0000000000000000000000000000000000000000..7b08163cebc50fb3e777eea4881b68fcebc10590 --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.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/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/vcs.xml" "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.idea/vcs.xml" new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/.idea/.idea.NukkuMatti -harjoitusty\303\266/.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/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.sln" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.sln" new file mode 100644 index 0000000000000000000000000000000000000000..2de0d9871e13c45cd9af870e1b589efe2a76ac36 --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.sln" @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NukkuMatti -harjoitustyö", "NukkuMatti -harjoitustyö\NukkuMatti -harjoitustyö.csproj", "{1039CA95-7E69-4FCD-8CD2-CC33817F7978}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1039CA95-7E69-4FCD-8CD2-CC33817F7978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1039CA95-7E69-4FCD-8CD2-CC33817F7978}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1039CA95-7E69-4FCD-8CD2-CC33817F7978}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1039CA95-7E69-4FCD-8CD2-CC33817F7978}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git "a/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/nukkumatti.png" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/nukkumatti.png" new file mode 100644 index 0000000000000000000000000000000000000000..48681cbc36048f5b93a3bbc55f9a0e33ee908a92 Binary files /dev/null and "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/nukkumatti.png" differ diff --git "a/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/taivas.jpeg" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/taivas.jpeg" new file mode 100644 index 0000000000000000000000000000000000000000..0e4bbbf2ac1457beda7db671d4ac75eb1ddc9111 Binary files /dev/null and "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Content/taivas.jpeg" differ diff --git "a/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.cs" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.cs" new file mode 100644 index 0000000000000000000000000000000000000000..cf006035d1eecfcd836a465032d72380d3f794f1 --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.cs" @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using Jypeli; +using Jypeli.Assets; +using Jypeli.Controls; +using Jypeli.Widgets; + +namespace NukkuMatti__harjoitustyö; + +/// @author eeron +/// @version 14.03.2025 +/// <summary> +/// +/// </summary> +public class NukkuMatti__harjoitustyö : PhysicsGame +{ + public override void Begin() + { + // Kirjoita ohjelmakoodisi tähän + + PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); + Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); + } +} \ No newline at end of file diff --git "a/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.csproj" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..e4a97e8c7b936c948d873547c5c3a9672915bf9f --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266.csproj" @@ -0,0 +1,22 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>net8.0</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Jypeli.NET" Version="11.*"/> + <PackageReference Include="Jypeli.FarseerPhysics.NET" Version="2.*"/> + </ItemGroup> + + <ItemGroup> + <None Update="Content\taivas.jpeg"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + <None Update="Content\nukkumatti.png"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + </ItemGroup> + +</Project> diff --git "a/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Ohjelma.cs" "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Ohjelma.cs" new file mode 100644 index 0000000000000000000000000000000000000000..676af722692b84adceb8134fa80743c3bd6eba16 --- /dev/null +++ "b/NukkuMatti -harjoitusty\303\266/NukkuMatti -harjoitusty\303\266/Ohjelma.cs" @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using Jypeli; + +// Eero Salmen tekemä tasohyppelypeli osana ohjelmointi 1 -kurssia. Pelin nimi on NukkuMatti. +// Pelaajan tehtävänä on kuljettaa NukkuMattia tasolta toiselle, tippumatta alas. + +public class Tasohyppely : PhysicsGame +{ + // Muutama vakio arvo määritelty pelin mekaniikalle, jotta ne on helpommin hallittavissa samassa paikassa + + private const double GravityStrength = -800; + private const double HyppyVoima = 1100; + private const double TasoLeveys = 100; + private const double TasoKorkeus = 10; + private const double PelaajaWidth = 100; + private const double PelaajaHeight = 100; + private const double AlkuperainenHyppyNopeus = 1000; + private const double TasoPoistoMarginaali = 200; + private const double StartingHeight = -20; + + private PhysicsObject pelaaja; + private bool peliKaynnissa = true; + private GameObject taustakuva; + private Label gameOverTeksti; + private int score = 0; + private List<PhysicsObject> tasot = new List<PhysicsObject>(); + + public override void Begin() + { + // Asetetaan painovoima + Gravity = new Vector(0, GravityStrength); + + // Luodaan kentän elementit + LuoKentta(); + LisaaOhjaimet(); + LuoGameOverTeksti(); + + // Ajastin sille, kyinka usein uusia tasoja ilmestyy pelikenttään + Timer tasoAjastin = new Timer(); + tasoAjastin.Interval = 0.8; + tasoAjastin.Timeout += LuoTaso; + tasoAjastin.Start(); + + // Hyppynopeus + pelaaja.Velocity = new Vector(0, AlkuperainenHyppyNopeus); + } + + private void LuoKentta() + { + LuoTausta(); + LuoPelaaja(); + + // Asetetaan pelaajan ominaisuudet ja lisätään kentälle + pelaaja.Position = new Vector(0, StartingHeight); + pelaaja.CanRotate = false; + pelaaja.Restitution = 0; + Add(pelaaja); + + // Luodaan aloitustaso + PhysicsObject aloitusTaso = PhysicsObject.CreateStaticObject(200, TasoKorkeus); + aloitusTaso.Position = new Vector(0, -70); + aloitusTaso.Color = Color.White; + aloitusTaso.Tag = "taso"; + Add(aloitusTaso); + + // Laitetaan kamera seuraamaan pelaajaa + Camera.Follow(pelaaja); + + // Lisätään törmäysominaisuus + AddCollisionHandler(pelaaja, "taso", OsuiTasoon); + + // Luodaan muutama aloitustaso + for (int i = 0; i < 4; i++) + LuoTaso(); + } + + private void LuoTausta() + { + // Lisätään taustakuva ja sijoitetaan se taustalle + taustakuva = new GameObject(Level.Width * 2, Level.Height * 2); + taustakuva.Image = LoadImage("taivas.jpeg"); + taustakuva.Position = Camera.Position; + Add(taustakuva, -1); + } + + private void LuoGameOverTeksti() + { + // Asetetaan pelin päättymis teksti + gameOverTeksti = new Label("HÄVISIT PELIN"); + gameOverTeksti.TextColor = Color.Red; + gameOverTeksti.Font = Font.DefaultBold; + gameOverTeksti.Position = new Vector(0, 100); + gameOverTeksti.IsVisible = false; + Add(gameOverTeksti); + } + + private void LuoPelaaja() + { + //Luodaan hahmo + pelaaja = new PhysicsObject(PelaajaWidth, PelaajaHeight); + pelaaja.Image = LoadImage("nukkumatti.png"); + pelaaja.Restitution = 0; + } + + private void LuoTaso() + { + //Luodaan tasoja + double x = RandomGen.NextDouble(Level.Left + 100, Level.Right - 100); + double y = Camera.ScreenToWorld(new Vector(0, Screen.Height / 2)).Y + RandomGen.NextDouble(10, 10); + + PhysicsObject taso = PhysicsObject.CreateStaticObject(TasoLeveys, TasoKorkeus); + taso.Position = new Vector(x, y); + taso.Color = Color.White; + taso.Tag = "taso"; + Add(taso); + + tasot.Add(taso); + } + + private void LisaaOhjaimet() + { + // Asetetaan komennot näppäimistöltä + Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, null, -400.0); + Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, null, 400.0); + Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); + } + + private void Liikuta(double nopeus) + { + if (peliKaynnissa) + pelaaja.Velocity = new Vector(nopeus, pelaaja.Velocity.Y); + } + + private void OsuiTasoon(PhysicsObject pelaaja, PhysicsObject taso) + { + // Törmäys pelaajan ja tason välillä + if (pelaaja.Velocity.Y > 0 && pelaaja.Position.Y < taso.Top) + { + pelaaja.IgnoresCollisionResponse = true; + return; + } + + if (pelaaja.Velocity.Y <= 0 && Math.Abs(pelaaja.Bottom - taso.Top) < 5) + { + pelaaja.Y = taso.Top + pelaaja.Height / 2; + pelaaja.Velocity = new Vector(pelaaja.Velocity.X, HyppyVoima); + } + + pelaaja.IgnoresCollisionResponse = false; + } + + private void PoistaPoistuvatTasot() + { + // Turhat tasot poistetaan + for (int i = tasot.Count - 1; i >= 0; i--) + { + if (tasot[i].Y < Camera.ScreenToWorld(new Vector(0, -Screen.Height / 2)).Y - TasoPoistoMarginaali) + { + tasot[i].Destroy(); + tasot.RemoveAt(i); + } + } + } + + private void LopetaPeli() + { + // Pelin lopettamiskomento + + if (peliKaynnissa) + { + peliKaynnissa = false; + gameOverTeksti.IsVisible = true; + Timer.SingleShot(3.0, Exit); + } + } + + protected override void Update(Time time) + { + base.Update(time); + + // Taustakuva päivittyy kameran liikkeen mukaisesti + taustakuva.Position = taustakuva.Position + (Camera.Position - taustakuva.Position) * 0.1; + + PoistaPoistuvatTasot(); + + if (pelaaja.Y < Level.Bottom - 100) + LopetaPeli(); + } +} + +public class Program +{ + public static void Main() + { + using (var peli = new Tasohyppely()) + peli.Run(); + } +} diff --git "a/NukkuMatti -harjoitusty\303\266/nukkumatti.png" "b/NukkuMatti -harjoitusty\303\266/nukkumatti.png" new file mode 100644 index 0000000000000000000000000000000000000000..48681cbc36048f5b93a3bbc55f9a0e33ee908a92 Binary files /dev/null and "b/NukkuMatti -harjoitusty\303\266/nukkumatti.png" differ diff --git "a/NukkuMatti -harjoitusty\303\266/taivas.jpeg" "b/NukkuMatti -harjoitusty\303\266/taivas.jpeg" new file mode 100644 index 0000000000000000000000000000000000000000..0e4bbbf2ac1457beda7db671d4ac75eb1ddc9111 Binary files /dev/null and "b/NukkuMatti -harjoitusty\303\266/taivas.jpeg" differ diff --git a/NukkuMatti.sln b/NukkuMatti.sln deleted file mode 100644 index 1f8ec326405d45df4ebf2db4fdde703a7c4bdf3b..0000000000000000000000000000000000000000 --- a/NukkuMatti.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NukkuMatti", "NukkuMatti\NukkuMatti.csproj", "{8F811F58-345B-4BC6-83EA-12DD4B395340}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8F811F58-345B-4BC6-83EA-12DD4B395340}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8F811F58-345B-4BC6-83EA-12DD4B395340}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8F811F58-345B-4BC6-83EA-12DD4B395340}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8F811F58-345B-4BC6-83EA-12DD4B395340}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal