Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
esimerkit
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
tie
ohj1
2023s
esimerkit
Commits
a46c1104
Commit
a46c1104
authored
1 year ago
by
Vesa Lappalainen
Browse files
Options
Downloads
Patches
Plain Diff
pong private
parent
9b4a6a61
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
luennot/luento09/Pong/Pong.cs
+26
-21
26 additions, 21 deletions
luennot/luento09/Pong/Pong.cs
with
26 additions
and
21 deletions
luennot/luento09/Pong/Pong.cs
+
26
−
21
View file @
a46c1104
using
System
;
using
System.Collections.Generic
;
using
Jypeli
;
using
Jypeli.Assets
;
using
Jypeli.Controls
;
using
Jypeli.Widgets
;
namespace
Pong
;
public
class
Pong
:
PhysicsGame
{
Vector
nopeusYlos
=
new
Vector
(
0
,
200
);
Vector
nopeusAlas
=
new
Vector
(
0
,
-
200
);
private
readonly
Vector
nopeusYlos
=
new
Vector
(
0
,
200
);
private
readonly
Vector
nopeusAlas
=
new
Vector
(
0
,
-
200
);
PhysicsObject
pallo
;
PhysicsObject
maila1
;
PhysicsObject
maila2
;
private
PhysicsObject
pallo
;
private
PhysicsObject
maila1
;
private
PhysicsObject
maila2
;
PhysicsObject
vasenReuna
;
PhysicsObject
oikeaReuna
;
private
PhysicsObject
vasenReuna
;
private
PhysicsObject
oikeaReuna
;
IntMeter
pelaajan1Pisteet
;
IntMeter
pelaajan2Pisteet
;
private
IntMeter
pelaajan1Pisteet
;
private
IntMeter
pelaajan2Pisteet
;
public
override
void
Begin
()
{
LuoKentta
();
...
...
@@ -30,7 +27,8 @@ public class Pong : PhysicsGame
AloitaPeli
();
}
void
LuoKentta
()
private
void
LuoKentta
()
{
pallo
=
new
PhysicsObject
(
40.0
,
40.0
);
pallo
.
Shape
=
Shape
.
Circle
;
...
...
@@ -70,7 +68,8 @@ public class Pong : PhysicsGame
Camera
.
ZoomToLevel
();
}
PhysicsObject
LuoMaila
(
double
x
,
double
y
)
private
PhysicsObject
LuoMaila
(
double
x
,
double
y
)
{
PhysicsObject
maila
=
PhysicsObject
.
CreateStaticObject
(
20.0
,
100.0
);
maila
.
Shape
=
Shape
.
Rectangle
;
...
...
@@ -82,13 +81,15 @@ public class Pong : PhysicsGame
return
maila
;
}
void
LisaaLaskurit
()
private
void
LisaaLaskurit
()
{
pelaajan1Pisteet
=
LuoPisteLaskuri
(
Screen
.
Left
+
100.0
,
Screen
.
Top
-
100.0
);
pelaajan2Pisteet
=
LuoPisteLaskuri
(
Screen
.
Right
-
100.0
,
Screen
.
Top
-
100.0
);
}
IntMeter
LuoPisteLaskuri
(
double
x
,
double
y
)
private
IntMeter
LuoPisteLaskuri
(
double
x
,
double
y
)
{
IntMeter
laskuri
=
new
IntMeter
(
0
);
laskuri
.
MaxValue
=
10
;
...
...
@@ -105,7 +106,8 @@ public class Pong : PhysicsGame
return
laskuri
;
}
void
KasittelePallonTormays
(
PhysicsObject
pallo
,
PhysicsObject
kohde
)
private
void
KasittelePallonTormays
(
PhysicsObject
p
,
PhysicsObject
kohde
)
{
if
(
kohde
==
oikeaReuna
)
{
...
...
@@ -117,13 +119,15 @@ public class Pong : PhysicsGame
}
}
void
AloitaPeli
()
private
void
AloitaPeli
()
{
Vector
impulssi
=
new
Vector
(
500.0
,
0.0
);
pallo
.
Hit
(
impulssi
*
pallo
.
Mass
);
}
void
AsetaOhjaimet
()
private
void
AsetaOhjaimet
()
{
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Down
,
AsetaNopeus
,
"Pelaaja 1: Liikuta mailaa ylös"
,
maila1
,
nopeusYlos
);
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Released
,
AsetaNopeus
,
null
,
maila1
,
Vector
.
Zero
);
...
...
@@ -152,7 +156,8 @@ public class Pong : PhysicsGame
ControllerTwo
.
Listen
(
Button
.
Back
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
}
void
AsetaNopeus
(
PhysicsObject
maila
,
Vector
nopeus
)
private
void
AsetaNopeus
(
PhysicsObject
maila
,
Vector
nopeus
)
{
if
((
nopeus
.
Y
<
0
)
&&
(
maila
.
Bottom
<
Level
.
Bottom
))
{
...
...
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