From 102dc81b58ab4aa81c676a3c8591281bf2cbe935 Mon Sep 17 00:00:00 2001 From: Eronen Oskari Veikka Viljami <oskari.w.eronen@student.jyu.fi> Date: Mon, 14 Mar 2022 23:54:33 +0200 Subject: [PATCH] =?UTF-8?q?P=C3=A4ivitetty=20Ht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Harjoitustyo/Pomppupeli/Content/.DS_Store | Bin 6148 -> 6148 bytes Harjoitustyo/Pomppupeli/Content/kentta1.txt | 2 +- Harjoitustyo/Pomppupeli/Content/kentta2.txt | 10 +++ Harjoitustyo/Pomppupeli/Content/kentta3.txt | 10 +++ Harjoitustyo/Pomppupeli/Pomppupeli.cs | 69 ++++++++++++++++++-- Harjoitustyo/Pomppupeli/Pomppupeli.csproj | 3 + 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 Harjoitustyo/Pomppupeli/Content/kentta2.txt create mode 100644 Harjoitustyo/Pomppupeli/Content/kentta3.txt diff --git a/Harjoitustyo/Pomppupeli/Content/.DS_Store b/Harjoitustyo/Pomppupeli/Content/.DS_Store index 761e1d43ee2d9d79f62e4a4bf66b72e457c16850..2871c490fbd445c521571566bb9865ab14a7f3ec 100644 GIT binary patch delta 128 zcmZoMXfc=|#>B)qu~2NHo+2aL#DLw4KQJ;fvQ6e;wB+Yz$Yw}o$YUr0!bAq6$#RV1 z@_q~q42%DR0g%POfU3qAq=t1bP<;7jE5=0D&Fmcf96<9oKV<yQJegm_l7o?f0f-nF KHV24oVFmzMw;x#m delta 66 zcmZoMXfc=|#>B`mu~2NHo+2a5#DLw5ER%VdEH`gt3S-^aki)o{or9kPsA6*<^LOUS U{34bd3_!rhz`(RQKx7Lu06umPo&W#< diff --git a/Harjoitustyo/Pomppupeli/Content/kentta1.txt b/Harjoitustyo/Pomppupeli/Content/kentta1.txt index 2c300d4..f27b743 100644 --- a/Harjoitustyo/Pomppupeli/Content/kentta1.txt +++ b/Harjoitustyo/Pomppupeli/Content/kentta1.txt @@ -6,5 +6,5 @@ ####### ####### #### ######################################### * # * * - N # XX * # * # + N # XX * # * # M ############################################################################ \ No newline at end of file diff --git a/Harjoitustyo/Pomppupeli/Content/kentta2.txt b/Harjoitustyo/Pomppupeli/Content/kentta2.txt new file mode 100644 index 0000000..98ae0e4 --- /dev/null +++ b/Harjoitustyo/Pomppupeli/Content/kentta2.txt @@ -0,0 +1,10 @@ +############################################################################ +############################################################################ +############################################################################ +############################################################################ +####### ############################################################## +#### ## ####### #### ######################################### + * + # * * + N # XX * # * # M +############################################################################ \ No newline at end of file diff --git a/Harjoitustyo/Pomppupeli/Content/kentta3.txt b/Harjoitustyo/Pomppupeli/Content/kentta3.txt new file mode 100644 index 0000000..bfb5aa0 --- /dev/null +++ b/Harjoitustyo/Pomppupeli/Content/kentta3.txt @@ -0,0 +1,10 @@ +############################################################################ +############################################################################ +############################################################################ +############################################################################ +####### ############################################################## +####### ####### #### ## ###################################### + * + # * * + N # XX * # * # M +############################################################################ \ No newline at end of file diff --git a/Harjoitustyo/Pomppupeli/Pomppupeli.cs b/Harjoitustyo/Pomppupeli/Pomppupeli.cs index 58f6a68..ea1cf76 100644 --- a/Harjoitustyo/Pomppupeli/Pomppupeli.cs +++ b/Harjoitustyo/Pomppupeli/Pomppupeli.cs @@ -10,6 +10,7 @@ public class Pomppupeli : PhysicsGame private const double nopeus = 200; private const double hyppynopeus = 500; private const int ruudunKoko = 40; + private int kenttaNro = 1; private PlatformCharacter pelaaja1; @@ -17,36 +18,77 @@ public class Pomppupeli : PhysicsGame private Image rengasKuva = LoadImage("rengas.png"); private Image piikkiKuva = LoadImage("piikki.png"); private IntMeter pisteLaskuri; + private List<Label> valikonKohdat; public override void Begin() { Gravity = new Vector(0, -1000); - LuoKentta(); + Valikko(); + Mouse.IsCursorVisible = true; + } + + + private void AloitaPeli() + { + ClearAll(); + LuoKentta("kentta1"); LisaaNappaimet(); LuoPistelaskuri(); - + Camera.Follow(pelaaja1); Camera.ZoomFactor = 2.0; Camera.StayInLevel = true; - } - private void LuoKentta() + private void Valikko() { - TileMap kentta = TileMap.FromLevelAsset("kentta1.txt"); + + valikonKohdat = new List<Label>(); + + Label kohta1 = new Label("Aloita uusi peli"); + kohta1.Position = new Vector(0, 40); + valikonKohdat.Add(kohta1); + + Label kohta2 = new Label("Lopeta peli"); + kohta2.Position = new Vector(0, -40); + valikonKohdat.Add(kohta2); + + foreach (Label valikonKohta in valikonKohdat) + { + Add(valikonKohta); + } + + Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null); + Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, Exit, null); + + } + + + private void LuoKentta(string kentannumero) + { + ClearAll(); + TileMap kentta = TileMap.FromLevelAsset(kentannumero); kentta.SetTileMethod('#', LisaaTaso); kentta.SetTileMethod('*', LisaaRengas); kentta.SetTileMethod('N', LisaaPelaaja); kentta.SetTileMethod('X', LisaaPiikki); + kentta.SetTileMethod('M', LisaaMaali); kentta.Execute(ruudunKoko, ruudunKoko); Level.CreateBorders(); Level.Background.CreateGradient(Color.White, Color.SkyBlue); } + void SeuraavaKentta() + { + if (kenttaNro == 1) LuoKentta("kentta2"); + else if (kenttaNro == 2) LuoKentta("kentta3"); + } + + private void LisaaTaso(Vector paikka, double leveys, double korkeus) { PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); @@ -87,10 +129,22 @@ public class Pomppupeli : PhysicsGame pelaaja1.Image = palloKuva; AddCollisionHandler(pelaaja1, "rengas", TormaaRenkaaseen); AddCollisionHandler(pelaaja1, "piikki", TormaaPiikkiin); + AddCollisionHandler(pelaaja1, "maali", TormaaMaaliin); Add(pelaaja1); } + private void LisaaMaali(Vector paikka, double leveys, double korkeus) + { + PhysicsObject maali = PhysicsObject.CreateStaticObject(leveys, korkeus); + maali.IgnoresCollisionResponse = true; + maali.Position = paikka; + //maali.Image = maaliKuva; + maali.Tag = "maali"; + Add(maali); + } + + private void LisaaNappaimet() { Keyboard.Listen(Key.O, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); @@ -132,6 +186,11 @@ public class Pomppupeli : PhysicsGame ConfirmExit(); } + void TormaaMaaliin(PhysicsObject hahmo, PhysicsObject maali) + { + kenttaNro++; + SeuraavaKentta(); + } private void LuoPistelaskuri() { diff --git a/Harjoitustyo/Pomppupeli/Pomppupeli.csproj b/Harjoitustyo/Pomppupeli/Pomppupeli.csproj index 52cecf8..725dbae 100644 --- a/Harjoitustyo/Pomppupeli/Pomppupeli.csproj +++ b/Harjoitustyo/Pomppupeli/Pomppupeli.csproj @@ -22,6 +22,9 @@ <None Update="Content\tahti.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> + <None Update="Content\kentta1.txt"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> </Project> -- GitLab