Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ohj1ht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tervomhj
ohj1ht
Commits
5680786b
Commit
5680786b
authored
1 year ago
by
Tervo Matias Heikki Juhani
Browse files
Options
Downloads
Patches
Plain Diff
korjaukset, silmukka + muuttujat
parent
5d652847
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Harjoitustyo/Harjoitustyo/Shooter.cs
+54
-30
54 additions, 30 deletions
Harjoitustyo/Harjoitustyo/Shooter.cs
with
54 additions
and
30 deletions
Harjoitustyo/Harjoitustyo/Shooter.cs
+
54
−
30
View file @
5680786b
...
@@ -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
.1
0
.2023
/// @version
24
.1
1
.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
<
1
2
;
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
<
2
0
;
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
.
R
ed
);
RandomGen
.
NextDouble
(
Level
.
Bottom
+
400
,
Level
.
Top
-
50
)),
20
,
20
,
Color
.
M
ed
iumTurquoise
);
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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment