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
rikantos
ohj1ht
Commits
3854283c
Commit
3854283c
authored
1 month ago
by
Rönkä Riku Antti Oskari
Browse files
Options
Downloads
Patches
Plain Diff
Iso päivitys. Esteet taulukkomuodossa, toiminnallisuus paljon parempi, ja uusi puu esteenä
parent
4bedde17
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Harjoitustyo/PinguLaskettelee/Content/puu.png
+0
-0
0 additions, 0 deletions
Harjoitustyo/PinguLaskettelee/Content/puu.png
Harjoitustyo/PinguLaskettelee/PinguLaskettelee/PinguLaskettelee.cs
+139
-66
139 additions, 66 deletions
...tyo/PinguLaskettelee/PinguLaskettelee/PinguLaskettelee.cs
with
139 additions
and
66 deletions
Harjoitustyo/PinguLaskettelee/Content/puu.png
0 → 100644
+
0
−
0
View file @
3854283c
13.7 KiB
This diff is collapsed.
Click to expand it.
Harjoitustyo/PinguLaskettelee/PinguLaskettelee/PinguLaskettelee.cs
+
139
−
66
View file @
3854283c
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net
;
using
System.Net.NetworkInformation
;
using
Jypeli
;
...
...
@@ -8,6 +9,8 @@ using Jypeli.Controls;
using
Jypeli.Widgets
;
using
SixLabors.ImageSharp.Processing.Processors.Filters
;
// TODO ~ Poista ylimääräset using direktiivit
namespace
PinguLaskettelee
;
/// @author Riku Rönkä
...
...
@@ -17,37 +20,63 @@ namespace PinguLaskettelee;
/// </summary>
public
class
PinguLaskettelee
:
PhysicsGame
{
// Pelin etenemisen nopeutta määrää laskuri
// Nämä rajoittavat laskurin
const
int
laskurinMaksimi
=
3
;
const
int
laskurinMinimi
=
0
;
/// Pingun kuvat eri tilanteissa
private
static
readonly
Image
pingunKuvaKolme
=
LoadImage
(
"pinguKolme"
);
private
static
readonly
Image
pingunKuvaKaksi
=
LoadImage
(
"pinguKaksi"
);
private
static
readonly
Image
pingunKuvaYksi
=
LoadImage
(
"pinguYksi"
);
private
static
readonly
Image
pingunKuvaNolla
=
LoadImage
(
"pinguNolla"
);
/// Kuvat esteistä
private
static
readonly
Image
kiviYksi
=
LoadImage
(
"kivi"
);
private
static
readonly
Image
puuYksi
=
LoadImage
(
"puu"
);
// Luodaan esteiden muodot kuvista.
// On ikävää, jos esteen muoto onkin erilainen, kun kuvasta päättelisi
private
Shape
kiviMuoto
=
Shape
.
FromImage
(
kiviYksi
);
private
Shape
puuMuoto
=
Shape
.
FromImage
(
puuYksi
);
private
Shape
pinguMuoto
=
Shape
.
FromImage
(
pingunKuvaKolme
);
/// <summary>
/// TODO ~ NÄMÄ PITÄÄ MUISTAA MUUTTAA VAKIOIKSI, OSA SIIRRETTÄVÄ PELIN SISÄLLE
/// </summary>
private
int
sydamet
=
3
;
private
int
esteenNopeus
=
300
;
private
int
esteidenMaara
=
0
;
private
int
tuhottu
=
0
;
private
double
interval
=
1
;
private
double
kuljettuMatka
=
0
;
private
PhysicsObject
pingu
;
private
PhysicsObject
kivi
;
private
PhysicsObject
suksi
;
private
Timer
ajastin
;
private
PhysicsObject
[]
este
=
new
PhysicsObject
[
1000
];
private
double
[]
esteTiedot
=
new
double
[
3
];
private
double
[]
pinguTiedot
=
new
double
[
3
];
public
IntMeter
sydanLaskuri
;
/// <summary>
/// Pingun kuvat eri tilanteissa
/// </summary>
private
static
readonly
Image
pingunKuvaKolme
=
LoadImage
(
"pinguKolme"
);
private
static
readonly
Image
pingunKuvaKaksi
=
LoadImage
(
"pinguKaksi"
);
private
static
readonly
Image
pingunKuvaYksi
=
LoadImage
(
"pinguYksi"
);
private
static
readonly
Image
pingunKuvaNolla
=
LoadImage
(
"pinguNolla"
);
public
IntMeter
sydanLaskuri
;
/// <summary>
/// Kuvat esteistä
/// Pääohjelma, joka aloittaa pelin.
/// Kutsuu LuoKentta aliohjelmaa, joka luo kentän, asettaa kameran, ja luo objektit.
/// </summary>
private
static
readonly
Image
kiviYksi
=
LoadImage
(
"Kivi"
);
public
override
void
Begin
()
{
LuoKentta
();
...
...
@@ -55,11 +84,19 @@ public class PinguLaskettelee : PhysicsGame
}
/// <summary>
/// LuoKentta luo kentän reunat, taustavärin, Pingun
/// kameran, laskurin, ohjaimet, esteitä muutaman
/// </summary>
private
void
LuoKentta
()
{
Level
.
CreateBorders
();
Level
.
BackgroundColor
=
Color
.
White
;
pingu
=
Pingu
();
// Camera.FollowedObject = pingu; TODO ~ Tämä on ihan hieno!
LisaaLaskuri
();
AsetaOhjaimet
();
Update
();
...
...
@@ -73,8 +110,8 @@ public class PinguLaskettelee : PhysicsGame
private
IntMeter
LuoLaskuri
()
{
IntMeter
laskuri
=
new
IntMeter
(
3
);
laskuri
.
M
ax
Value
=
3
;
laskuri
.
M
in
Value
=
0
;
laskuri
.
M
in
Value
=
laskurinMinimi
;
laskuri
.
M
ax
Value
=
laskurinMaksimi
;
Label
naytto
=
new
Label
();
naytto
.
BindTo
(
laskuri
);
...
...
@@ -96,7 +133,7 @@ public class PinguLaskettelee : PhysicsGame
}
private
void
LiikutaPingua
(
PhysicsObject
p
ingu
,
Vector
suunta
,
double
kulmanopeus
)
private
void
LiikutaPingua
(
PhysicsObject
p
elaaja
,
Vector
suunta
,
double
kulmanopeus
)
{
pingu
.
Push
(
suunta
);
}
...
...
@@ -104,10 +141,11 @@ public class PinguLaskettelee : PhysicsGame
private
void
Update
()
{
Timer
ajastin
=
new
Timer
();
ajastin
=
new
Timer
();
ajastin
.
Interval
=
interval
;
ajastin
.
Timeout
+=
Laskin
;
ajastin
.
Start
();
}
...
...
@@ -115,27 +153,34 @@ public class PinguLaskettelee : PhysicsGame
{
int
random
=
RandomGen
.
NextInt
(
0
,
100
);
esteenNopeus
+=
10
;
interval
+=
0.01
;
if
(
sydamet
==
0
)
esteenNopeus
=
0
;
Vector
vektori
=
new
Vector
(
0
,
esteenNopeus
);
for
(
int
i
=
0
;
i
<
esteidenMaara
;
i
++)
{
este
[
i
].
Velocity
=
vektori
;
if
(
este
[
i
].
Y
>
0
)
este
[
i
].
Destroy
();
}
if
(
ajastin
.
Interval
>
0.5
)
ajastin
.
Interval
-=
0.01
;
Console
.
WriteLine
(
"AJASTIN "
+
ajastin
.
Interval
);
Console
.
WriteLine
(
"interval on "
+
interval
);
kuljettuMatka
+=
interval
;
//Console.WriteLine(este[3].Y);
if
(
random
<
75
&&
sydamet
>
0
)
{
int
random2
=
RandomGen
.
NextInt
(
3
,
5
);
for
(
int
i
=
0
;
i
<
random2
;
i
++)
{
kivi
=
LuoEste
();
esteTiedot
[
0
]++;
if
(
kivi
.
Y
>
0
)
kivi
.
Destroy
();
// Console.WriteLine(esteTiedot[0]);
}
este
=
LuoEste
(
random2
,
100
);
esteTiedot
[
0
]++;
}
if
(
random
<
25
&&
sydamet
<
3
&&
sydamet
>
0
)
{
suksi
=
LuoSuksi
();
}
if
(
kuljettuMatka
>
10
0
)
StopAll
()
;
//Console.WriteLine("kuljettu matka on "+kuljettuMatka);
//
if (kuljettuMatka>10)
sydamet = 0
;
}
...
...
@@ -148,8 +193,8 @@ public class PinguLaskettelee : PhysicsGame
pingu
.
X
=
0
;
pingu
.
Y
=
0
;
pingu
.
Image
=
pingunKuvaKolme
;
pingu
.
RotateImage
=
tru
e
;
pingu
.
IgnoresCollisionResponse
=
tru
e
;
pingu
.
RotateImage
=
fals
e
;
pingu
.
IgnoresCollisionResponse
=
fals
e
;
pingu
.
MaxAngularVelocity
=
2
;
pingu
.
LinearDamping
=
0.998
;
//AddCollisionHandler(pingu, Tormays);
...
...
@@ -160,22 +205,35 @@ public class PinguLaskettelee : PhysicsGame
}
private
PhysicsObject
LuoEste
()
private
PhysicsObject
[]
LuoEste
(
int
montako
,
double
koko
)
{
int
randomX
=
RandomGen
.
NextInt
(-
450
,
450
);
int
randomY
=
RandomGen
.
NextInt
(-
850
,
-
450
);
Vector
vektori
=
new
Vector
(
0
,
esteenNopeus
);
PhysicsObject
este
=
new
PhysicsObject
(
100
,
100
);
este
.
Shape
=
Shape
.
Circle
;
este
.
Color
=
Color
.
Red
;
este
.
X
=
randomX
;
este
.
Y
=
randomY
;
este
.
Velocity
=
vektori
;
este
.
Tag
=
"este"
;
este
.
IgnoresCollisionResponse
=
true
;
este
.
Image
=
kiviYksi
;
Add
(
este
);
esteidenMaara
++;
for
(
int
i
=
0
;
i
<
montako
;
i
++)
{
int
randomX
=
RandomGen
.
NextInt
(-
450
,
450
);
int
randomY
=
RandomGen
.
NextInt
(-
850
,
-
450
);
PhysicsObject
kivi
=
new
PhysicsObject
(
koko
,
koko
);
kivi
.
Color
=
Color
.
Red
;
kivi
.
X
=
randomX
;
kivi
.
Y
=
randomY
;
kivi
.
Velocity
=
vektori
;
kivi
.
Tag
=
"este"
;
kivi
.
IgnoresCollisionResponse
=
true
;
int
mikaKuva
=
RandomGen
.
NextInt
(
1
,
3
);
if
(
mikaKuva
==
1
)
{
kivi
.
Image
=
kiviYksi
;
kivi
.
Shape
=
Shape
.
Circle
;
}
else
if
(
mikaKuva
==
2
)
{
kivi
.
Image
=
puuYksi
;
kivi
.
Shape
=
Shape
.
Circle
;
}
este
[
esteidenMaara
]
=
kivi
;
esteidenMaara
++;
Add
(
kivi
);
}
return
este
;
}
...
...
@@ -185,18 +243,18 @@ public class PinguLaskettelee : PhysicsGame
int
randomX
=
RandomGen
.
NextInt
(-
450
,
450
);
int
randomY
=
RandomGen
.
NextInt
(-
850
,
-
450
);
Vector
vektori
=
new
Vector
(
0
,
esteenNopeus
);
PhysicsObject
este
=
new
PhysicsObject
(
100
,
100
);
este
.
Shape
=
Shape
.
Circle
;
este
.
Color
=
Color
.
Red
;
este
.
X
=
randomX
;
este
.
Y
=
randomY
;
este
.
Velocity
=
vektori
;
este
.
Tag
=
"suksi"
;
este
.
IgnoresCollisionResponse
=
true
;
PhysicsObject
suksi
=
new
PhysicsObject
(
100
,
100
);
suksi
.
Shape
=
Shape
.
Circle
;
suksi
.
Color
=
Color
.
Red
;
suksi
.
X
=
randomX
;
suksi
.
Y
=
randomY
;
suksi
.
Velocity
=
vektori
;
suksi
.
Tag
=
"suksi"
;
suksi
.
IgnoresCollisionResponse
=
true
;
//este.Image = kiviYksi;
Add
(
este
);
esteidenMaara
++;
return
este
;
Add
(
suksi
);
//
esteidenMaara++;
return
suksi
;
}
/// <summary>
...
...
@@ -205,29 +263,42 @@ public class PinguLaskettelee : PhysicsGame
/// nopeutta hidastetaan. Myös objektien luonnin tahtia hidastetaan.
/// Aliohjelma myös muuttaa Pingun ulkonäköä sydänten mukaan
/// </summary>
/// <param name="p
ingu
"></param>
/// <param name="este"></param>
private
void
TormaysEste
(
PhysicsObject
p
ingu
,
PhysicsObject
este
)
/// <param name="p
elaaja
"></param>
/// <param name="este
et
"></param>
private
void
TormaysEste
(
PhysicsObject
p
elaaja
,
PhysicsObject
este
et
)
{
sydamet
-=
1
;
sydanLaskuri
.
Value
=
sydamet
;
esteenNopeus
-=
100
;
Vector
vektori
=
new
Vector
(
0
,
esteenNopeus
);
este
.
Velocity
=
vektori
;
interval
-=
0.5
;
for
(
int
i
=
0
;
i
<
esteidenMaara
;
i
++)
{
try
{
este
[
i
].
Velocity
=
vektori
;
}
catch
{
este
[
esteidenMaara
].
Velocity
=
vektori
;
}
}
ajastin
.
Interval
=
1
;
Console
.
WriteLine
(
sydamet
);
este
.
Destroy
();
este
et
.
Destroy
();
if
(
sydamet
==
2
)
pingu
.
Image
=
pingunKuvaKaksi
;
if
(
sydamet
==
1
)
pingu
.
Image
=
pingunKuvaYksi
;
if
(
sydamet
==
0
)
{
StopAll
();
este
.
Velocity
=
Vector
.
Zero
;
for
(
int
i
=
0
;
i
<
esteidenMaara
;
i
++)
{
este
[
i
].
Velocity
=
Vector
.
Zero
;
StopAll
();
}
pingu
.
LinearDamping
=
100
;
pingu
.
Image
=
pingunKuvaNolla
;
MessageDisplay
.
Add
(
$"Pingun after ski jäi nyt välistä"
);
// TulostaTiedot(esteTiedot, pinguTiedot)
//Console.WriteLine($"Esteiden määrä oli {esteidenMaara}");
// TODO ~ Tähän lisätään esteidenTiedot kutsu
}
}
...
...
@@ -237,7 +308,7 @@ public class PinguLaskettelee : PhysicsGame
if
(
sydamet
<=
3
)
sydamet
+=
1
;
sydanLaskuri
.
Value
=
sydamet
;
Console
.
WriteLine
(
sydamet
);
suksi
.
Destroy
();
//
suksi.Destroy();
if
(
sydamet
==
3
)
pingu
.
Image
=
pingunKuvaKolme
;
if
(
sydamet
==
2
)
pingu
.
Image
=
pingunKuvaKaksi
;
if
(
sydamet
==
1
)
pingu
.
Image
=
pingunKuvaYksi
;
...
...
@@ -256,6 +327,8 @@ public class PinguLaskettelee : PhysicsGame
private
void
TulostaTiedot
(
double
[]
esteTiedot
,
double
[]
pinguTiedot
)
{
// TODO ~~ pitää lisätä toiminnot, jotta tiedot tulostetaan pelin lopussa
// Tätä kutsutaan sitten, kun sydamet on nollassa.
// Lisäisikö aloita uudestaan napin tänne?
}
}
\ No newline at end of file
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