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
jahalmtv
ohj1ht
Commits
1ace9694
Commit
1ace9694
authored
3 days ago
by
jahalmtv
Browse files
Options
Downloads
Patches
Plain Diff
Peli esitys valmiina
parent
c29d711c
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Merirosvo-peli/Merirosvo-peli/Merirosvo-peli.cs
+16
-18
16 additions, 18 deletions
Merirosvo-peli/Merirosvo-peli/Merirosvo-peli.cs
with
16 additions
and
18 deletions
Merirosvo-peli/Merirosvo-peli/Merirosvo-peli.cs
+
16
−
18
View file @
1ace9694
...
...
@@ -13,7 +13,7 @@ public class Merirosvo_peli : PhysicsGame
private
const
double
PALLON_KOKO
=
50
;
private
const
int
PISTEEN_ARVO
=
1
;
private
const
double
KANUUNANKUULAN_TODENNARKYISYYS
=
0.5
;
private
const
double
PALLON_LISAYS_VAL
E
=
1
.5
;
private
const
double
PALLON_LISAYS_VAL
I
=
1
;
private
const
double
PELAAJAN_KOKO
=
80
;
private
const
double
PELAAJAN_Y_SIJAINTI
=
60
;
private
const
double
PISTELASKURIN_Y_SIJAINTI
=
-
50
;
...
...
@@ -22,6 +22,10 @@ public class Merirosvo_peli : PhysicsGame
private
IntMeter
pisteet
;
private
Timer
pallojenLisaaja
;
private
List
<
PhysicsObject
>
kaikkiPallot
=
new
List
<
PhysicsObject
>();
private
static
readonly
Image
PelaajaKuva
=
LoadImage
(
"Merirosvo.png"
);
private
static
readonly
Image
EsineKuva
=
LoadImage
(
"Kolikko"
);
private
static
readonly
Image
EsteKuva
=
LoadImage
(
"Kanuunankuula"
);
/// <summary>
/// Aloittaa pelin kutsumalla kentän luontia, ohjaimia ja pallojen lisäystä.
...
...
@@ -44,14 +48,15 @@ public class Merirosvo_peli : PhysicsGame
pelaaja
=
new
PhysicsObject
(
PELAAJAN_KOKO
,
PELAAJAN_KOKO
)
{
Shape
=
Shape
.
Circle
,
Color
=
Color
.
Brown
,
Shape
=
Shape
.
Rectangle
,
X
=
0
,
Y
=
Level
.
Bottom
+
PELAAJAN_Y_SIJAINTI
,
Restitution
=
0.0
,
Tag
=
"pelaaja"
,
IgnoresCollisionResponse
=
true
};
pelaaja
.
Image
=
PelaajaKuva
;
Add
(
pelaaja
);
PhysicsObject
pohja
=
Level
.
CreateBottomBorder
();
...
...
@@ -87,14 +92,8 @@ public class Merirosvo_peli : PhysicsGame
private
void
PysaytaLiike
()
{
pelaaja
.
Velocity
=
Vector
.
Zero
;
EstaPelaajanLiikkuminen
();
}
private
void
EstaPelaajanLiikkuminen
()
{
if
(
pelaaja
.
Left
<=
Level
.
Left
)
pelaaja
.
X
=
Level
.
Left
+
pelaaja
.
Width
/
2
;
if
(
pelaaja
.
Right
>=
Level
.
Right
)
pelaaja
.
X
=
Level
.
Right
-
pelaaja
.
Width
/
2
;
if
(
pelaaja
.
Left
<=
Level
.
Left
)
pelaaja
.
X
=
Level
.
Left
+
pelaaja
.
Width
/
2
;
if
(
pelaaja
.
Right
>=
Level
.
Right
)
pelaaja
.
X
=
Level
.
Right
-
pelaaja
.
Width
/
2
;
}
/// <summary>
...
...
@@ -122,7 +121,7 @@ public class Merirosvo_peli : PhysicsGame
{
pallojenLisaaja
=
new
Timer
{
Interval
=
PALLON_LISAYS_VAL
E
Interval
=
PALLON_LISAYS_VAL
I
};
pallojenLisaaja
.
Timeout
+=
LuoPallojaAalloittain
;
pallojenLisaaja
.
Start
();
...
...
@@ -148,7 +147,6 @@ public class Merirosvo_peli : PhysicsGame
double
x
=
RandomGen
.
NextDouble
(
Level
.
Left
+
50
,
Level
.
Right
-
50
);
PhysicsObject
pallo
=
new
PhysicsObject
(
PALLON_KOKO
,
PALLON_KOKO
)
{
Shape
=
Shape
.
Circle
,
Position
=
new
Vector
(
x
,
Level
.
Top
),
Velocity
=
new
Vector
(
0
,
-
PALLON_NOPEUS
),
Restitution
=
0.0
,
...
...
@@ -157,13 +155,13 @@ public class Merirosvo_peli : PhysicsGame
if
(
RandomGen
.
NextDouble
(
0.0
,
1.0
)
>
KANUUNANKUULAN_TODENNARKYISYYS
)
{
pallo
.
Color
=
Color
.
Yellow
;
pallo
.
Tag
=
"pistepallo"
;
pallo
.
Image
=
EsineKuva
;
}
else
{
pallo
.
Color
=
Color
.
Black
;
pallo
.
Tag
=
"kanuunankuula"
;
pallo
.
Image
=
EsteKuva
;
}
kaikkiPallot
.
Add
(
pallo
);
...
...
@@ -178,11 +176,11 @@ public class Merirosvo_peli : PhysicsGame
/// </summary>
private
void
PelaajaOsuiPalloon
(
PhysicsObject
pallo
,
PhysicsObject
pelaaja
)
{
if
(
pallo
.
Tag
.
ToString
()
==
"kanuunankuula"
)
if
(
pallo
.
Tag
==
"kanuunankuula"
)
{
ResetoiPeli
();
}
else
if
(
pallo
.
Tag
.
ToString
()
==
"pistepallo"
)
else
if
(
pallo
.
Tag
==
"pistepallo"
)
{
pisteet
.
Value
+=
PISTEEN_ARVO
;
pallo
.
Destroy
();
...
...
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