Skip to content
Snippets Groups Projects
Commit 5680786b authored by Tervo Matias Heikki Juhani's avatar Tervo Matias Heikki Juhani
Browse files

korjaukset, silmukka + muuttujat

parent 5d652847
Branches main
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ using Jypeli.Widgets; ...@@ -7,7 +7,7 @@ using Jypeli.Widgets;
namespace Harjoitustyo; namespace Harjoitustyo;
/// @author Matias Tervo /// @author Matias Tervo
/// @version 19.10.2023 /// @version 24.11.2023
/// <summary> /// <summary>
/// Shooter peli /// Shooter peli
/// </summary> /// </summary>
...@@ -92,10 +92,7 @@ public class Shooter : PhysicsGame ...@@ -92,10 +92,7 @@ public class Shooter : PhysicsGame
private IntMeter pistelaskuri; private IntMeter pistelaskuri;
private Timer aikalaskuri; private Timer aikalaskuri;
public List<PhysicsObject> viholliset = new List<PhysicsObject>();
public override void Begin() public override void Begin()
{ {
LuoAlkuvalikko(); LuoAlkuvalikko();
...@@ -147,12 +144,18 @@ public class Shooter : PhysicsGame ...@@ -147,12 +144,18 @@ public class Shooter : PhysicsGame
} }
private void AloitaPeli(Window sender) //overflow AloitaPeli kutsulle /// <summary>
/// overloand aloitapeli kutsulle
/// </summary>
/// <param name="sender">alkuvalikon kutsu</param>
private void AloitaPeli(Window sender)
{ {
AloitaPeli(); AloitaPeli();
} }
/// <summary>
/// muodostaa pelikentän
/// </summary>
private void LuoKentta() private void LuoKentta()
{ {
ClearAll(); ClearAll();
...@@ -189,13 +192,17 @@ public class Shooter : PhysicsGame ...@@ -189,13 +192,17 @@ public class Shooter : PhysicsGame
Add(pistenaytto); Add(pistenaytto);
} }
/// <summary>
/// näyttää parhaat pisteet
/// </summary>
private void ParhaatPisteet() private void ParhaatPisteet()
{ {
topLista.Show(); topLista.Show();
} }
/// <summary>
/// voisi määritellä peliin näppäimistöjä
/// </summary>
void Asetukset() void Asetukset()
{} {}
...@@ -226,23 +233,31 @@ public class Shooter : PhysicsGame ...@@ -226,23 +233,31 @@ public class Shooter : PhysicsGame
vihu.Tag = "vihu"; vihu.Tag = "vihu";
vihu.StopVertical(); vihu.StopVertical();
Add(vihu); Add(vihu);
viholliset.Add(vihu);
PathFollowerBrain aivot = new PathFollowerBrain(); PathFollowerBrain aivot = new PathFollowerBrain();
vihu.Brain = aivot; vihu.Brain = aivot;
List<Vector> polku = new List<Vector>(); List<Vector> polku = new List<Vector>();
polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y)); for (int i = 0; i < 4; i++)
polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y)); {
polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y)); polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y));
polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y)); aivot.Path = polku;
aivot.Path = polku; aivot.Loop = true;
aivot.Loop = true; aivot.Speed = vihu.Nopeus;
aivot.Speed = vihu.Nopeus; }
vihu.Ajastin.Timeout += () => VihuAmpuu(vihu.Ase, vihu); vihu.Ajastin.Timeout += () => VihuAmpuu(vihu.Ase, vihu);
} }
/// <summary>
/// luo uusia vihollisia erilaisilla arvoilla
/// </summary>
/// <param name="paikka">mihin paikkaan</param>
/// <param name="leveys">vihun leveys</param>
/// <param name="korkeus">vihun korkeus</param>
/// <param name="vari">minkä värinen</param>
private void LuoUusiVihollinen(Vector paikka, double leveys, double korkeus, Color vari) private void LuoUusiVihollinen(Vector paikka, double leveys, double korkeus, Color vari)
{ {
LuoVihollinen(paikka, leveys, korkeus, vari); LuoVihollinen(paikka, leveys, korkeus, vari);
...@@ -323,6 +338,10 @@ public class Shooter : PhysicsGame ...@@ -323,6 +338,10 @@ public class Shooter : PhysicsGame
/// <param name="kohde">mihin törmää</param> /// <param name="kohde">mihin törmää</param>
private void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) private void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde)
{ {
int maksimit = 500;
double pisteraja1 = maksimit * 0.12;
double pisteraja2 = maksimit * 0.24;
double pisteraja3 = maksimit * 0.48;
ammus.Destroy(); ammus.Destroy();
if (kohde is Pelihahmo) if (kohde is Pelihahmo)
{ {
...@@ -343,23 +362,23 @@ public class Shooter : PhysicsGame ...@@ -343,23 +362,23 @@ public class Shooter : PhysicsGame
rajahdys.UseShockWave = false; rajahdys.UseShockWave = false;
Add(rajahdys); Add(rajahdys);
if (pistelaskuri.Value == 60 && pistelaskuri.Value < 120) //näihin ois pitäny saada jotain järkevämpää if (pistelaskuri.Value > pisteraja1 && pistelaskuri.Value < pisteraja2)
{ {
for (int i = 0; i < 7; i++) for (int i = 0; i < 2; i++)
{ {
Timer ajastin = new Timer(); Timer ajastin = new Timer();
int luku = RandomGen.NextInt(0 ,5); int luku = RandomGen.NextInt(0 ,5);
ajastin.Interval = 1.0 + 1.2 * luku; ajastin.Interval = 1.0 + 1.2 * luku;
ajastin.Timeout += () => LuoUusiVihollinen(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), ajastin.Timeout += () => LuoUusiVihollinen(new Vector(RandomGen.NextDouble(Level.Left, Level.Right),
Level.Top -100), 24, 24, Color.Lime); RandomGen.NextDouble(Level.Bottom + 400, Level.Top -50)), 24, 24, Color.Lime);
ajastin.Start(1); ajastin.Start(1);
} }
} }
if (pistelaskuri.Value == 120 && pistelaskuri.Value < 200) if (pistelaskuri.Value > pisteraja2 && pistelaskuri.Value < pisteraja3)
{ {
for (int i = 0; i < 12; i++) for (int i = 0; i < 2; i++)
{ {
Timer ajastin = new Timer(); Timer ajastin = new Timer();
int luku = RandomGen.NextInt(0 ,5); int luku = RandomGen.NextInt(0 ,5);
...@@ -371,21 +390,21 @@ public class Shooter : PhysicsGame ...@@ -371,21 +390,21 @@ public class Shooter : PhysicsGame
} }
} }
if (pistelaskuri.Value == 200) if (pistelaskuri.Value > pisteraja3)
{ {
for (int i = 0; i < 20; i++) for (int i = 0; i < 2; i++)
{ {
Timer ajastin = new Timer(); Timer ajastin = new Timer();
int luku = RandomGen.NextInt(0 ,5); int luku = RandomGen.NextInt(0 ,5);
ajastin.Interval = 1.0 + 1.2 * luku; ajastin.Interval = 1.0 + 1.2 * luku;
ajastin.Timeout += () => LuoUusiVihollinen(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), ajastin.Timeout += () => LuoUusiVihollinen(new Vector(RandomGen.NextDouble(Level.Left, Level.Right),
RandomGen.NextDouble(Level.Bottom + 400, Level.Top -50)), 20, 20, Color.Red); RandomGen.NextDouble(Level.Bottom + 400, Level.Top -50)), 20, 20, Color.MediumTurquoise);
ajastin.Start(1); ajastin.Start(1);
} }
} }
if (pistelaskuri.Value > 500) if (pistelaskuri.Value > maksimit)
{ {
LopetaPeli(); LopetaPeli();
} }
...@@ -394,7 +413,7 @@ public class Shooter : PhysicsGame ...@@ -394,7 +413,7 @@ public class Shooter : PhysicsGame
/// <summary> /// <summary>
/// kun peli loppuu voittoon /// mitä tapahtuu, kun peli loppuu voittoon
/// </summary> /// </summary>
void LopetaPeli() void LopetaPeli()
{ {
...@@ -405,7 +424,10 @@ public class Shooter : PhysicsGame ...@@ -405,7 +424,10 @@ public class Shooter : PhysicsGame
topLista.HighScoreWindow.Closed +=LuoAlkuvalikko; topLista.HighScoreWindow.Closed +=LuoAlkuvalikko;
} }
/// <summary>
/// overload alkuvalikko kutsulle
/// </summary>
/// <param name="sender"></param>
private void LuoAlkuvalikko(Window sender) private void LuoAlkuvalikko(Window sender)
{ {
LuoAlkuvalikko(); LuoAlkuvalikko();
...@@ -478,19 +500,21 @@ public class Shooter : PhysicsGame ...@@ -478,19 +500,21 @@ public class Shooter : PhysicsGame
/// <returns>kokonaispisteet</returns> /// <returns>kokonaispisteet</returns>
private int LaskePisteet(Timer aika, IntMeter pisteet) private int LaskePisteet(Timer aika, IntMeter pisteet)
{ {
int aikaraja1 = 35;
int aikaraja2 = 60;
int kokonaisPisteet = pisteet.Value; int kokonaisPisteet = pisteet.Value;
double aikaaKulunut = aika.SecondCounter.Value; double aikaaKulunut = aika.SecondCounter.Value;
if (aikaaKulunut < 35) //voisi laittaa useamman portaan niin olisi enemmän vaihtelua if (aikaaKulunut < aikaraja1)
{ {
kokonaisPisteet = pisteet.Value * 5; kokonaisPisteet = pisteet.Value * 5;
} }
if (aikaaKulunut > 35 && aikaaKulunut < 60) if (aikaaKulunut > aikaraja1 && aikaaKulunut < aikaraja2)
{ {
kokonaisPisteet = pisteet.Value * 2; kokonaisPisteet = pisteet.Value * 2;
} }
if (aikaaKulunut > 60) if (aikaaKulunut > aikaraja2)
{ {
kokonaisPisteet = pisteet.Value * 1; kokonaisPisteet = pisteet.Value * 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment