Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ohj1htlokkihunter
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
sulasaal
ohj1htlokkihunter
Commits
306d147a
Commit
306d147a
authored
1 year ago
by
Sulasalmi Aleksi Sakari
Browse files
Options
Downloads
Patches
Plain Diff
lisää koodia
parent
bd7c5f28
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Harjoitustyö/Lokkihunter/Lokkihunter.cs
+94
-9
94 additions, 9 deletions
Harjoitustyö/Lokkihunter/Lokkihunter.cs
with
94 additions
and
9 deletions
Harjoitustyö/Lokkihunter/Lokkihunter.cs
+
94
−
9
View file @
306d147a
...
...
@@ -7,32 +7,116 @@ using Jypeli.Widgets;
namespace
Lokkihunter
;
/// @author
Omanimi
/// @author
sulasaal
/// @version 23.10.2023
/// <summary>
///
/// </summary>
public
class
Lokkihunter
:
PhysicsGame
{
Vector
nopeusVasen
=
new
Vector
(
200
,
0
);
Vector
nopeusOikea
=
new
Vector
(-
200
,
0
);
private
PhysicsObject
pekka
;
private
PhysicsObject
lokki
;
private
PhysicsObject
alaReuna
;
private
PhysicsObject
ylaReuna
;
private
PhysicsObject
oikeaReuna
;
private
PhysicsObject
vasenReuna
;
public
override
void
Begin
()
{
pekka
=
new
PhysicsObject
(
40.0
,
40.0
);
pekka
.
Shape
=
Shape
.
Circle
;
pekka
.
X
=
-
300
;
pekka
.
Y
=
-
200
;
pekka
.
Restitution
=
1.0
;
Add
(
pekka
);
LuoKentt
ä
();
AsetaOhjaimet
();
}
alaReuna
=
Level
.
CreateBottomBorder
(
1
,
true
);
void
LuoKentt
ä
()
{
pekka
=
LuoPekka
(
0
,-
350
);
LuoLokkiVasen
();
LuoLokkiOikea
();
alaReuna
=
Level
.
CreateBottomBorder
(
1
,
false
);
Add
(
alaReuna
);
ylaReuna
=
Level
.
CreateTopBorder
(
1
,
false
);
Add
(
ylaReuna
);
Camera
.
ZoomToLevel
();
oikeaReuna
=
Level
.
CreateRightBorder
(
1
,
false
);
Add
(
oikeaReuna
);
vasenReuna
=
Level
.
CreateLeftBorder
(
1
,
false
);
Add
(
vasenReuna
);
Camera
.
ZoomToLevel
();
}
void
AsetaOhjaimet
()
{
PhoneBackButton
.
Listen
(
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
D
,
ButtonState
.
Down
,
AsetaNopeusPekka
,
"Pekka: Liikkuu vasemmalle"
,
pekka
,
nopeusVasen
);
Keyboard
.
Listen
(
Key
.
D
,
ButtonState
.
Released
,
AsetaNopeusPekka
,
null
,
pekka
,
Vector
.
Zero
);
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Down
,
AsetaNopeusPekka
,
"Pekka: Liikkuu oikealle"
,
pekka
,
nopeusOikea
);
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Released
,
AsetaNopeusPekka
,
null
,
pekka
,
Vector
.
Zero
);
}
/// <summary>
/// Aliohjelma luo Pekan.
/// </summary>
/// <param name="x">X-koordinaatti</param>
/// <param name="y">Y-koordinaatti</param>
private
PhysicsObject
LuoPekka
(
double
x
,
double
y
)
{
pekka
=
new
PhysicsObject
(
40.0
,
40.0
);
pekka
.
Shape
=
Shape
.
Circle
;
pekka
.
Restitution
=
1.0
;
pekka
.
X
=
x
;
pekka
.
Y
=
y
;
Add
(
pekka
);
return
pekka
;
}
/// <summary>
/// asettaa pekalle nopuden.
/// </summary>
/// <param name="_pekka">mitä oliota liikutetaan</param>
/// <param name="nopeus">millä nopeudella</param>
void
AsetaNopeusPekka
(
PhysicsObject
_pekka
,
Vector
nopeus
)
{
pekka
.
Velocity
=
nopeus
;
}
private
void
LuoLokkiVasen
()
{
lokki
=
new
PhysicsObject
(
60.0
,
20.0
);
lokki
.
Shape
=
Shape
.
Rectangle
;
lokki
.
Hit
(
new
Vector
(
80
,
1
));
double
x
=
-
400
;
lokki
.
X
=
x
;
double
y
=
RandomGen
.
NextDouble
(
200
,
350
);
lokki
.
Y
=
y
;
Add
(
lokki
);
}
private
void
LuoLokkiOikea
()
{
lokki
=
new
PhysicsObject
(
60.0
,
20.0
);
lokki
.
Shape
=
Shape
.
Rectangle
;
lokki
.
Hit
(
new
Vector
(-
80
,
1
));
double
x
=
400
;
lokki
.
X
=
x
;
double
y
=
RandomGen
.
NextDouble
(
200
,
350
);
lokki
.
Y
=
y
;
Add
(
lokki
);
}
}
\ 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