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
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ using Jypeli.Widgets;
namespace Harjoitustyo;
/// @author Matias Tervo
/// @version 19.10.2023
/// @version 24.11.2023
/// <summary>
/// Shooter peli
/// </summary>
......@@ -92,10 +92,7 @@ public class Shooter : PhysicsGame
private IntMeter pistelaskuri;
private Timer aikalaskuri;
public List<PhysicsObject> viholliset = new List<PhysicsObject>();
public override void Begin()
{
LuoAlkuvalikko();
......@@ -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();
}
/// <summary>
/// muodostaa pelikentän
/// </summary>
private void LuoKentta()
{
ClearAll();
......@@ -189,13 +192,17 @@ public class Shooter : PhysicsGame
Add(pistenaytto);
}
/// <summary>
/// näyttää parhaat pisteet
/// </summary>
private void ParhaatPisteet()
{
topLista.Show();
}
/// <summary>
/// voisi määritellä peliin näppäimistöjä
/// </summary>
void Asetukset()
{}
......@@ -226,23 +233,31 @@ public class Shooter : PhysicsGame
vihu.Tag = "vihu";
vihu.StopVertical();
Add(vihu);
viholliset.Add(vihu);
PathFollowerBrain aivot = new PathFollowerBrain();
vihu.Brain = aivot;
List<Vector> polku = new List<Vector>();
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.Loop = true;
aivot.Speed = vihu.Nopeus;
for (int i = 0; i < 4; i++)
{
polku.Add(new Vector(RandomGen.NextDouble(Level.Left, Level.Right), paikka.Y));
aivot.Path = polku;
aivot.Loop = true;
aivot.Speed = vihu.Nopeus;
}
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)
{
LuoVihollinen(paikka, leveys, korkeus, vari);
......@@ -323,6 +338,10 @@ public class Shooter : PhysicsGame
/// <param name="kohde">mihin törmää</param>
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();
if (kohde is Pelihahmo)
{
......@@ -343,23 +362,23 @@ public class Shooter : PhysicsGame
rajahdys.UseShockWave = false;
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();
int luku = RandomGen.NextInt(0 ,5);
ajastin.Interval = 1.0 + 1.2 * luku;
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);
}
}
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();
int luku = RandomGen.NextInt(0 ,5);
......@@ -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();
int luku = RandomGen.NextInt(0 ,5);
ajastin.Interval = 1.0 + 1.2 * luku;
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);
}
}
if (pistelaskuri.Value > 500)
if (pistelaskuri.Value > maksimit)
{
LopetaPeli();
}
......@@ -394,7 +413,7 @@ public class Shooter : PhysicsGame
/// <summary>
/// kun peli loppuu voittoon
/// mitä tapahtuu, kun peli loppuu voittoon
/// </summary>
void LopetaPeli()
{
......@@ -405,7 +424,10 @@ public class Shooter : PhysicsGame
topLista.HighScoreWindow.Closed +=LuoAlkuvalikko;
}
/// <summary>
/// overload alkuvalikko kutsulle
/// </summary>
/// <param name="sender"></param>
private void LuoAlkuvalikko(Window sender)
{
LuoAlkuvalikko();
......@@ -478,19 +500,21 @@ public class Shooter : PhysicsGame
/// <returns>kokonaispisteet</returns>
private int LaskePisteet(Timer aika, IntMeter pisteet)
{
int aikaraja1 = 35;
int aikaraja2 = 60;
int kokonaisPisteet = pisteet.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;
}
if (aikaaKulunut > 35 && aikaaKulunut < 60)
if (aikaaKulunut > aikaraja1 && aikaaKulunut < aikaraja2)
{
kokonaisPisteet = pisteet.Value * 2;
}
if (aikaaKulunut > 60)
if (aikaaKulunut > aikaraja2)
{
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