diff --git a/Matopeli/Matopeli/Matopeli.cs b/Matopeli/Matopeli/Matopeli.cs index 86a3411aa81f34d8f610806c82e045884330470f..e06f8bd1c9a6c1f30dd439bcd63ae6acc5603e77 100644 --- a/Matopeli/Matopeli/Matopeli.cs +++ b/Matopeli/Matopeli/Matopeli.cs @@ -22,7 +22,7 @@ public class matopeli : PhysicsGame "# #", "# #", "# #", - "# #", + "# o #", "# #", "# #", "# #", @@ -43,8 +43,8 @@ public class matopeli : PhysicsGame public List<Vector> MatoSijainti = new List<Vector>(); public List<PhysicsObject> MatoKeho = new List<PhysicsObject>(); - public int leveys = 30; - public int korkeus = 30; + public int leveys = 40; + public int korkeus = 40; private static readonly Image seinakuva = LoadImage("seina.png"); private static readonly Image matopaakuva = LoadImage("matopaa.png"); @@ -72,17 +72,16 @@ public class matopeli : PhysicsGame public void AloitaUusiPeli() { - Level.CreateBorders(0.0,true,Color.Green); ClearAll(); + TileMap tiles = TileMap.FromStringArray(tasonkuva); + tiles['#'] = LuoSeina; + tiles['o'] = LuoMato; + tiles.Insert(leveys,korkeus); SuuntaAlas = true; - LuoMato(); Asetaohjaimet(); LuoAikalaskuri(); LuoOmena(); - TileMap tiles = TileMap.FromStringArray(tasonkuva); - tiles['#'] = LuoSeina; - tiles.Insert(leveys,korkeus); } private void Asetaohjaimet() { @@ -107,38 +106,36 @@ public class matopeli : PhysicsGame /// <returns></returns> private PhysicsObject LuoOmena() { - - Vector paikka = Level.GetRandomPosition(); + int x = 0; + int y = 0; - for (int i = 0; i < 100; i++) + for (int i = 0; i < MatoKeho.Count - 1; i++) { - if (paikka.X-Mato.X<5) - { - paikka = Level.GetRandomPosition(); - } - if (paikka.X-Mato.Y<5) - { - paikka= Level.GetRandomPosition(); - } - if (paikka.X<30) + x = RandomGen.NextInt(-300, 300); + y = RandomGen.NextInt(-300, 300); + + if (x - MatoKeho[i].X < 4) { - if (paikka.X < -30) + if (y - MatoKeho[i].Y < 4) { - paikka = Level.GetRandomPosition(); + x = RandomGen.NextInt(-300, 300); + y = RandomGen.NextInt(-300, 300); } } - if (paikka.Y<30) + } + + if (x-Mato.X<4) { - if (paikka.Y<-30) + if (y - Mato.Y < 4) { - paikka = Level.GetRandomPosition(); - } - } - else - { - break; + x = RandomGen.NextInt(-300, 300); + y = RandomGen.NextInt(-300, 300); + } + } - } + + Vector paikka = new Vector(x, y); + Omena = new Objektit(korkeus, leveys); Omena.Shape = Shape.Circle; @@ -163,7 +160,7 @@ public class matopeli : PhysicsGame /// </summary> public PhysicsObject LuoMatoKeho() { - MatoMuu = new Objektit(leveys-8, korkeus-8); + MatoMuu = new Objektit(leveys-4, korkeus-4); MatoMuu.Tag = "matokeho"; MatoMuu.Image = matokehokuva; Vector Paikka = MatoSijainti[MatoSijainti.Count - 1 - MatoKeho.Count]; @@ -290,6 +287,7 @@ public class matopeli : PhysicsGame private void LiikutaMatoa() { + MatoLiikkunut = false; if (SuuntaYlos==true) { Mato.Y = Mato.Y + leveys; @@ -312,6 +310,8 @@ public class matopeli : PhysicsGame Mato.Angle = Angle.FromDegrees(180); } + + MatoLiikkunut = true; } /// <summary>