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
sjuskivs
ohj1ht
Commits
f8bf7d0f
Commit
f8bf7d0f
authored
1 year ago
by
Uski Samu Joonatan
Browse files
Options
Downloads
Patches
Plain Diff
vimmeistely alkanut
parent
f6b6317e
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
TurboMasters/TurboMasters/TurboMasters.cs
+81
-49
81 additions, 49 deletions
TurboMasters/TurboMasters/TurboMasters.cs
with
81 additions
and
49 deletions
TurboMasters/TurboMasters/TurboMasters.cs
+
81
−
49
View file @
f8bf7d0f
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Net.Mime
;
using
Jypeli
;
using
Jypeli.Assets
;
using
Jypeli.Controls
;
using
Jypeli.Widgets
;
using
Silk.NET.OpenGL
;
namespace
TurboMasters
;
/// @author Samu Uski
/// @version 30.10.2023
/// <summary>
///
///
Rallipeli, jossa normaali ja Drift -pelimuodot, tavoitteena mahdollisimman nopea kierrosaika
/// </summary>
public
class
TurboMasters
:
PhysicsGame
{
// pelaajan ohjaama auto
PhysicsObject
auto
;
//sektoriviivat joille annettu collisionhandler
PhysicsObject
sektori1
;
PhysicsObject
sektori2
;
PhysicsObject
sektori3
;
Label
sektori1Teksti
=
new
Label
();
Label
sektori2Teksti
=
new
Label
();
Label
sektori3Teksti
=
new
Label
();
//pelaajalle näytettävät teksit, jossai tämän hetkisen kierroksen sektoriajat
private
Label
sektori1Teksti
=
new
Label
();
private
Label
sektori2Teksti
=
new
Label
();
private
Label
sektori3Teksti
=
new
Label
();
Label
nopeinSektori1
=
new
Label
();
Label
nopeinSektori2
=
new
Label
();
Label
nopeinSektori3
=
new
Label
();
Label
nopeinKierros
=
new
Label
();
Label
pontentiaalinenNopein
=
new
Label
();
//pelaajalle näytettävät tekstit, joissa nopein kierros, sekä nopeimmat sektoriajat
private
Label
nopeinSektori1
=
new
Label
();
private
Label
nopeinSektori2
=
new
Label
();
private
Label
nopeinSektori3
=
new
Label
();
private
Label
nopeinKierros
=
new
Label
();
private
Label
pontentiaalinenNopein
=
new
Label
();
Double
[]
kierrosAjat
=
{
0
,
0
,
0
,
0
};
Double
[]
nopeimmatAjat
=
{
999
,
999
,
999
,
999
,
999
};
//talukot, joihin tallennetaan kierrosaikoja, sekä nopeimmat kierrosajat
private
Double
[]
kierrosAjat
=
{
0
,
0
,
0
,
0
};
private
Double
[]
nopeimmatAjat
=
{
int
.
MaxValue
,
int
.
MaxValue
,
int
.
MaxValue
,
int
.
MaxValue
,
int
.
MaxValue
};
//aikalaskuri, sekä teksi jossa se näytetään pelaajalle
private
Timer
aikalaskuri
;
private
Label
naytto
;
Timer
aikalaskuri
;
Label
naytto
;
//taustakuva ja auto-objektin grakiikka
private
Image
taustaKuva
=
LoadImage
(
"tausta"
);
private
Image
autoKuva
=
LoadImage
(
"auto"
);
Image
taustaKuva
=
LoadImage
(
"tausta"
);
Image
autoKuva
=
LoadImage
(
"auto"
);
//auton kiihtyvyys ja kääntyvyys -arvot
private
double
kiihtyvyys
=
1.8
;
//auton kiihtyvyyskerroin
private
double
kaantyvyys
=
4
;
//auton kääntyvyyskerroin
double
kiihtyvyys
=
1.8
;
//auton kiihtyvyyskerroin
double
kaantyvyys
=
4
;
//auton kääntyvyyskerroin
//alkuun suoritettava metodi, jossa kutsutaan peliin tarvittvat aliohjelmat
public
override
void
Begin
()
{
ClearAll
();
...
...
@@ -55,7 +59,9 @@ public class TurboMasters : PhysicsGame
Level
.
Background
.
Image
=
taustaKuva
;
}
void
LuoKentta
()
//aliohjelma, jossa luodaan radalle sivureunat
public
void
LuoKentta
()
{
LuoKaide
(
ulkoreuna
);
LuoKaide
(
sisareuna
);
...
...
@@ -69,8 +75,9 @@ public class TurboMasters : PhysicsGame
Camera
.
ZoomToLevel
();
}
void
EkaSuoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
public
void
EkaSuoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
{
Remove
(
sektori1Teksti
);
Remove
(
sektori2Teksti
);
...
...
@@ -84,7 +91,8 @@ public class TurboMasters : PhysicsGame
}
void
TokaSuoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
public
void
TokaSuoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
{
kierrosAjat
[
2
]
=
aikalaskuri
.
CurrentTime
;
sektori2Teksti
=
LuoTeksti
(
OtaAika
(
2
,
kierrosAjat
[
1
]),
60
,
-
200
);
...
...
@@ -94,7 +102,8 @@ public class TurboMasters : PhysicsGame
OnkoNopeampi
(
2
);
}
void
Suoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
public
void
Suoritettu
(
PhysicsObject
obj1
,
PhysicsObject
obj2
)
{
kierrosAjat
[
3
]
=
aikalaskuri
.
CurrentTime
;
kierrosAjat
[
0
]
=
kierrosAjat
[
3
];
...
...
@@ -110,8 +119,9 @@ public class TurboMasters : PhysicsGame
PaivitaNopeimmat
();
}
void
OnkoNopeampi
(
int
indeksi
)
public
void
OnkoNopeampi
(
int
indeksi
)
{
if
(
kierrosAjat
[
indeksi
]
<
nopeimmatAjat
[
indeksi
])
{
...
...
@@ -119,8 +129,9 @@ public class TurboMasters : PhysicsGame
}
}
void
PaivitaNopeimmat
()
public
void
PaivitaNopeimmat
()
{
nopeimmatAjat
[
4
]
=
0
;
for
(
int
i
=
1
;
i
<=
3
;
i
++)
...
...
@@ -139,15 +150,17 @@ public class TurboMasters : PhysicsGame
nopeinSektori3
=
LuoTeksti
(
nopeimmatAjat
[
3
].
ToString
(
"#.000"
),
-
400
,
-
300
);
pontentiaalinenNopein
=
LuoTeksti
(
nopeimmatAjat
[
4
].
ToString
(
"#.000"
),
-
400
,
-
375
);
}
string
OtaAika
(
int
sektori
,
double
edellisetSektorit
)
public
string
OtaAika
(
int
sektori
,
double
edellisetSektorit
)
{
kierrosAjat
[
sektori
]
-=
edellisetSektorit
;
string
aikaTeksti
=
kierrosAjat
[
sektori
].
ToString
(
"#.000"
);
return
aikaTeksti
;
}
void
Alkuvalikko
()
public
void
Alkuvalikko
()
{
MultiSelectWindow
alkuvalikko
=
new
MultiSelectWindow
(
"Alkuvalikko"
,
"Normaali"
,
"Drift"
,
"Lopeta"
);
alkuvalikko
.
AddItemHandler
(
0
,
NormalMode
);
...
...
@@ -156,20 +169,23 @@ public class TurboMasters : PhysicsGame
Add
(
alkuvalikko
);
}
void
NormalMode
()
public
void
NormalMode
()
{
Driftaa
(
false
);
AloitaPeli
();
}
void
DriftMode
()
public
void
DriftMode
()
{
auto
.
LinearDamping
=
1.5
;
Driftaa
(
true
);
AloitaPeli
();
}
void
AloitaPeli
()
public
void
AloitaPeli
()
{
naytto
=
LuoAikalaskuri
();
...
...
@@ -185,7 +201,8 @@ public class TurboMasters : PhysicsGame
LuoTeksti
(
"Potential Best Lap:"
,
-
400
,
-
350
);
}
Label
LuoAikalaskuri
()
public
Label
LuoAikalaskuri
()
{
aikalaskuri
=
new
Timer
();
aikalaskuri
.
Start
();
...
...
@@ -201,7 +218,8 @@ public class TurboMasters : PhysicsGame
return
aikanaytto
;
}
PhysicsObject
LuoSektori
(
Double
x
,
Double
y
,
Angle
kulma
)
public
PhysicsObject
LuoSektori
(
Double
x
,
Double
y
,
Angle
kulma
)
{
PhysicsObject
sektori
=
new
PhysicsObject
(
5
,
100
);
sektori
.
X
=
x
;
...
...
@@ -213,7 +231,8 @@ public class TurboMasters : PhysicsGame
return
sektori
;
}
Label
LuoTeksti
(
string
teksti
,
int
xArvo
,
int
yArvo
)
public
Label
LuoTeksti
(
string
teksti
,
int
xArvo
,
int
yArvo
)
{
Label
uusiTeksti
=
new
Label
();
uusiTeksti
.
TextColor
=
Color
.
Black
;
...
...
@@ -224,6 +243,7 @@ public class TurboMasters : PhysicsGame
return
uusiTeksti
;
}
private
Vector
[]
ulkoreuna
=
new
Vector
[]
{
new
Vector
(
350
,
-
350
),
...
...
@@ -251,6 +271,7 @@ public class TurboMasters : PhysicsGame
new
Vector
(
350
,
-
350
),
};
private
Vector
[]
sisareuna
=
new
Vector
[]
{
new
Vector
(
300
,
-
250
),
...
...
@@ -278,7 +299,8 @@ public class TurboMasters : PhysicsGame
new
Vector
(
300
,
-
250
),
};
void
LuoKaide
(
Vector
[]
reittipisteet
)
public
void
LuoKaide
(
Vector
[]
reittipisteet
)
{
RoadMap
kaide
=
new
RoadMap
(
reittipisteet
);
kaide
.
DefaultWidth
=
5.0
;
// Kaiteen leveys
...
...
@@ -286,7 +308,8 @@ public class TurboMasters : PhysicsGame
kaide
.
Insert
();
}
PhysicsObject
LuoKaiteenPatka
(
double
width
,
double
height
,
Shape
shape
)
public
PhysicsObject
LuoKaiteenPatka
(
double
width
,
double
height
,
Shape
shape
)
{
PhysicsObject
patka
=
PhysicsObject
.
CreateStaticObject
(
width
,
height
,
shape
);
patka
.
Color
=
Color
.
White
;
...
...
@@ -295,7 +318,8 @@ public class TurboMasters : PhysicsGame
return
patka
;
}
PhysicsObject
LuoAuto
(
Double
x
,
Double
y
)
public
PhysicsObject
LuoAuto
(
Double
x
,
Double
y
)
{
PhysicsObject
autoLuo
=
new
PhysicsObject
(
30.0
,
15.0
);
autoLuo
.
Shape
=
Shape
.
Rectangle
;
...
...
@@ -313,7 +337,8 @@ public class TurboMasters : PhysicsGame
return
autoLuo
;
}
void
AsetaOhjaimet
()
public
void
AsetaOhjaimet
()
{
Keyboard
.
Listen
(
Key
.
W
,
ButtonState
.
Down
,
Kiihdyta
,
"Aja eteenpäin"
,
auto
,
-
1
);
...
...
@@ -327,7 +352,8 @@ public class TurboMasters : PhysicsGame
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
Begin
,
"Valikko"
);
}
void
Driftaa
(
bool
driftataakno
)
public
void
Driftaa
(
bool
driftataakno
)
{
Keyboard
.
Listen
(
Key
.
W
,
ButtonState
.
Pressed
,
AsetaSuunta
,
null
,
driftataakno
);
Keyboard
.
Listen
(
Key
.
W
,
ButtonState
.
Released
,
AsetaSuunta
,
null
,
driftataakno
);
...
...
@@ -335,13 +361,15 @@ public class TurboMasters : PhysicsGame
Keyboard
.
Listen
(
Key
.
D
,
ButtonState
.
Down
,
AsetaSuunta
,
null
,
driftataakno
);
}
void
Kiihdyta
(
PhysicsObject
auto
,
int
suunta
)
public
void
Kiihdyta
(
PhysicsObject
auto
,
int
suunta
)
{
Vector
pelaajanSuunta
=
Vector
.
FromLengthAndAngle
(
kiihtyvyys
*
1000
*
suunta
,
auto
.
Angle
);
auto
.
Push
(
pelaajanSuunta
);
}
void
AsetaSuunta
(
bool
asetetaanko
)
public
void
AsetaSuunta
(
bool
asetetaanko
)
{
if
(
asetetaanko
==
false
)
{
...
...
@@ -350,19 +378,23 @@ public class TurboMasters : PhysicsGame
}
}
void
Kaanna
(
PhysicsObject
auto
,
int
suunta
)
public
void
Kaanna
(
PhysicsObject
auto
,
int
suunta
)
{
double
pituus
=
VektorinPituus
(
auto
.
Velocity
);
auto
.
ApplyTorque
(
kaantyvyys
*
suunta
*
pituus
);
}
Double
VektorinPituus
(
Vector
vektori
)
public
Double
VektorinPituus
(
Vector
vektori
)
{
double
pituus
=
double
.
Sqrt
((
vektori
.
X
*
vektori
.
X
)
+
(
vektori
.
Y
*
vektori
.
Y
));
return
pituus
;
}
Vector
Eteenpain
()
public
Vector
Eteenpain
()
{
double
liikkumisSuunta
=
VektorinPituus
(
auto
.
Velocity
);
Vector
eteenpainVektori
=
Vector
.
FromLengthAndAngle
(
liikkumisSuunta
,
auto
.
Angle
);
...
...
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