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
salmatel
ohj1ht
Commits
dcb3241b
Commit
dcb3241b
authored
1 year ago
by
Salonen Matteus Elmeri
Browse files
Options
Downloads
Patches
Plain Diff
HT2 chekki ja lisäyksiä
parent
4deb4123
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Harjoitustyo/HyttysPeli/HyttysPeli.cs
+52
-35
52 additions, 35 deletions
Harjoitustyo/HyttysPeli/HyttysPeli.cs
with
52 additions
and
35 deletions
Harjoitustyo/HyttysPeli/HyttysPeli.cs
+
52
−
35
View file @
dcb3241b
using
System
;
using
System.Collections.Generic
;
using
Jypeli
;
using
Jypeli.Assets
;
using
Jypeli.Controls
;
using
Jypeli.Effects
;
using
Jypeli.Widgets
;
// ReSharper disable All
namespace
HyttysPeli
;
...
...
@@ -15,51 +12,69 @@ namespace HyttysPeli;
/// </summary>
public
class
HyttysPeli
:
PhysicsGame
{
Image
taustaKuva
=
LoadImage
(
"taustakuva"
);
private
Image
taustaKuva
=
LoadImage
(
"taustakuva"
);
private
IntMeter
pistelaskuri
;
private
IntMeter
helttilaskuri
;
private
PhysicsObject
pelaaja
;
private
Image
kuvaAmpiainen
=
LoadImage
(
"ampiainen"
);
public
override
void
Begin
()
{
MasterVolume
=
0.05
;
SetWindowSize
(
1920
,
1080
,
true
);
Level
.
Background
.
Image
=
taustaKuva
;
LuoPistelaskuri
();
LuoHelttilaskuri
();
BoundingRectangle
alaosa
=
new
BoundingRectangle
(
new
Vector
(
Level
.
Left
,
0
),
Level
.
BoundingRect
.
BottomRight
);
BoundingRectangle
ylaosa
=
new
BoundingRectangle
(
Level
.
BoundingRect
.
TopLeft
,
new
Vector
(
Level
.
Right
,
0
));
Level
.
CreateBorders
();
PhysicsObject
pelaaja
=
new
PhysicsObject
(
25
,
100
,
Shape
.
Rectangle
);
pelaaja
.
Position
=
RandomGen
.
NextVector
(
alaosa
);
pelaaja
.
Image
=
LoadImage
(
"hyttyskarkoite"
);
Add
(
pelaaja
);
Keyboard
.
Listen
(
Key
.
F1
,
ButtonState
.
Pressed
,
ShowControlHelp
,
"Näytä avustus"
);
Keyboard
.
Listen
(
Key
.
Up
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja ylös"
,
pelaaja
,
new
Vector
(
0
,
20
));
Keyboard
.
Listen
(
Key
.
Down
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja alas"
,
pelaaja
,
new
Vector
(
0
,
-
20
));
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja vasemmalle"
,
pelaaja
,
new
Vector
(-
20
,
0
));
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja oikealle"
,
pelaaja
,
new
Vector
(
20
,
0
));
BoundingRectangle
[]
reunat
=
LuoKentta
();
LuoPelaaja
();
LuoOhjaimet
();
//Luo aliohjelmat näille, paranna reunat, tee lopetus
for
(
int
i
=
0
;
i
<
25
;
i
++)
{
LuoHyttynen
(
this
,
ylaosa
,
60
,
"hyttynen"
);
LuoHyttynen
(
this
,
reunat
[
0
]
,
60
,
"hyttynen"
);
}
for
(
int
j
=
0
;
j
<
10
;
j
++)
{
LuoAmpiainen
(
this
,
ylaosa
,
60
,
"ampiainen"
);
LuoAmpiainen
(
this
,
reunat
[
0
]
,
60
,
"ampiainen"
);
}
AddCollisionHandler
(
pelaaja
,
"hyttynen"
,
PelaajaTormasiHyttyseen
);
AddCollisionHandler
(
pelaaja
,
"ampiainen"
,
PelaajaTormasiAmpiaiseen
);
PhoneBackButton
.
Listen
(
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
}
private
void
LuoOhjaimet
()
{
Keyboard
.
Listen
(
Key
.
F1
,
ButtonState
.
Pressed
,
ShowControlHelp
,
"Näytä avustus"
);
Keyboard
.
Listen
(
Key
.
Up
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja ylös"
,
pelaaja
,
new
Vector
(
0
,
20
));
Keyboard
.
Listen
(
Key
.
Down
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja alas"
,
pelaaja
,
new
Vector
(
0
,
-
20
));
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja vasemmalle"
,
pelaaja
,
new
Vector
(-
20
,
0
));
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Down
,
LyoHyttysta
,
"Pelaaja oikealle"
,
pelaaja
,
new
Vector
(
20
,
0
));
}
private
void
LuoPelaaja
()
{
pelaaja
=
new
PhysicsObject
(
25
,
100
,
Shape
.
Rectangle
);
pelaaja
.
Y
=
Level
.
Bottom
;
pelaaja
.
X
=
50
;
pelaaja
.
Image
=
LoadImage
(
"hyttyskarkoite"
);
Add
(
pelaaja
);
AddCollisionHandler
(
pelaaja
,
"hyttynen"
,
PelaajaTormasiHyttyseen
);
AddCollisionHandler
(
pelaaja
,
"ampiainen"
,
PelaajaTormasiAmpiaiseen
);
}
private
BoundingRectangle
[]
LuoKentta
()
{
// Jos halutaan seinien kimpoilut, vaihdetaan seinät Jypelin ohjeisiin
MasterVolume
=
0.05
;
SetWindowSize
(
1920
,
1080
,
true
);
Level
.
Background
.
Image
=
taustaKuva
;
BoundingRectangle
alaosa
=
new
BoundingRectangle
(
new
Vector
(
Level
.
Left
,
0
),
Level
.
BoundingRect
.
BottomRight
);
BoundingRectangle
ylaosa
=
new
BoundingRectangle
(
Level
.
BoundingRect
.
TopLeft
,
new
Vector
(
Level
.
Right
,
0
));
Level
.
CreateBorders
();
BoundingRectangle
[]
reunat
=
new
[]
{
ylaosa
,
alaosa
};
return
reunat
;
}
private
void
HyttynenTormasiSeinaan
(
PhysicsObject
reuna
,
PhysicsObject
hyttynen
)
{
}
/// <summary>
/// Metodi johon tullaan kun pelaaja ja hyttynen törmäävät.
/// Luodaan hyttysen kohdalla räjähdys ja poistetaan hyttynen pelistä
...
...
@@ -120,10 +135,12 @@ public class HyttysPeli : PhysicsGame
double
korkeus
=
50
;
PhysicsObject
hyttynen
=
new
PhysicsObject
(
leveys
,
korkeus
,
Shape
.
Rectangle
);
hyttynen
.
Position
=
RandomGen
.
NextVector
(
rect
);
Vector
suunta
=
RandomGen
.
NextVector
(
0
,
vauhti
);
Vector
suunta
=
RandomGen
.
NextVector
(
0
,
vauhti
+
100
);
hyttynen
.
Hit
(
suunta
);
// hyttynen.Velocity = suunta;
hyttynen
.
Tag
=
tunniste
;
hyttynen
.
Image
=
LoadImage
(
"hyttynen (2)"
);
// AddCollisionHandler(hyttynen, "alaosa", HyttynenTormasiSeinaan);
peli
.
Add
(
hyttynen
);
return
hyttynen
;
}
...
...
@@ -146,7 +163,7 @@ public class HyttysPeli : PhysicsGame
Vector
suunta
=
RandomGen
.
NextVector
(
0
,
vauhti
);
ampiainen
.
Hit
(
suunta
);
ampiainen
.
Tag
=
tunniste
;
ampiainen
.
Image
=
LoadImage
(
"a
mpiainen
"
)
;
ampiainen
.
Image
=
kuvaA
mpiainen
;
peli
.
Add
(
ampiainen
);
return
ampiainen
;
}
...
...
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