diff --git a/Harjoitustyo/Pomppupeli/Content/.DS_Store b/Harjoitustyo/Pomppupeli/Content/.DS_Store index 761e1d43ee2d9d79f62e4a4bf66b72e457c16850..2871c490fbd445c521571566bb9865ab14a7f3ec 100644 Binary files a/Harjoitustyo/Pomppupeli/Content/.DS_Store and b/Harjoitustyo/Pomppupeli/Content/.DS_Store differ diff --git a/Harjoitustyo/Pomppupeli/Content/kentta1.txt b/Harjoitustyo/Pomppupeli/Content/kentta1.txt index 2c300d448131a1505bd6f190d5413c72b0de87b2..f27b7431d77538748a60cb17f037bb27ed1809e8 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 0000000000000000000000000000000000000000..98ae0e45aebb9c5ce13976cf5a21bb755342e584 --- /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 0000000000000000000000000000000000000000..bfb5aa0953a72ac11dbbeb57cc9a0affccc7bc26 --- /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 58f6a684b9d892416e98b93850b81d8fb76d663e..ea1cf7637fc45175fffa3d67f59512eaaee0ed50 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 52cecf8fd2cf5de10dd458b7db62d8a2f94f2e4d..725dbae790909ba173a1dd55afa1deef4ff0cb82 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>