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
mattarma
ohj1ht
Commits
6115efd3
Commit
6115efd3
authored
1 year ago
by
Mattila Arttu Matias
Browse files
Options
Downloads
Patches
Plain Diff
koodin lisätty tippuvat meteoridit
parent
d73aa052
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
suunnitelma/Asteroid Blaster/AsteroidBlaster/AsteroidBlaster.cs
+87
-54
87 additions, 54 deletions
...telma/Asteroid Blaster/AsteroidBlaster/AsteroidBlaster.cs
with
87 additions
and
54 deletions
suunnitelma/Asteroid Blaster/AsteroidBlaster/AsteroidBlaster.cs
+
87
−
54
View file @
6115efd3
...
...
@@ -14,71 +14,104 @@ namespace Asteroid_Blaster;
/// Asteroid Blaster -peli
/// </summary>
public
class
Asteroid_Blaster
:
PhysicsGame
{
private
Vector
nopeusVasen
=
new
Vector
(-
400
,
0
);
private
Vector
nopeusOikea
=
new
Vector
(
400
,
0
);
private
PhysicsObject
sotilas
;
private
Animation
sotilasAnimaatio
;
private
Image
sotilasPaikallaan
;
private
Image
[]
meteoriditTippuu
=
LoadImages
(
"meteoridi1"
,
"meteoridi2"
,
"meteoridi3"
);
public
override
void
Begin
()
{
Level
.
CreateLeftBorder
(
0
,
false
);
// Luodaan kentälle rajat. Ylös ei luoda koska meterotien pitää tulla sieltä
Level
.
CreateBottomBorder
(
0
,
false
);
Level
.
CreateRightBorder
(
0
,
false
);
Camera
.
ZoomToLevel
();
sotilas
=
LuoSotilas
(
Level
.
Width
/
2
,
Level
.
Bottom
+
75
);
AsetaOhjaimet
();
// pääohjelma näppäimille
PhoneBackButton
.
Listen
(
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
}
private
Vector
_nopeusVasen
=
new
Vector
(-
600
,
0
);
private
Vector
_nopeusOikea
=
new
Vector
(
600
,
0
);
PhysicsObject
LuoSotilas
(
double
x
,
double
y
)
{
PhysicsObject
sotilas
=
new
PhysicsObject
(
170
,
150
);
sotilas
.
Position
=
new
Vector
(
x
,
y
);
// private Image taustakuva = LoadImage("pelinTausta");
private
PhysicsObject
_sotilas
;
private
Animation
_sotilasAnimaatio
;
private
Image
_sotilasPaikallaan
;
private
Image
[]
_meteoriditTippuu
=
LoadImages
(
"meteoridi1"
,
"meteoridi2"
,
"meteoridi3"
);
Image
[]
sotilasLiikkuu
=
LoadImages
(
"sotilasliike"
,
"sotilasjuoksee"
)
;
sotilasPaikallaan
=
LoadImage
(
"sotilasPaikallaan"
)
;
private
int
_meteoridiMaara
=
1
;
private
double
_meteoridiPerusNopeus
=
-
70
;
sotilasAnimaatio
=
new
Animation
(
sotilasLiikkuu
);
sotilas
.
Image
=
sotilasPaikallaan
;
public
override
void
Begin
()
{
Level
.
CreateLeftBorder
(
0
,
false
);
Level
.
CreateBottomBorder
(
0
,
false
);
Level
.
CreateRightBorder
(
0
,
false
);
Camera
.
ZoomToLevel
();
// Level.Background.Image = taustakuva;
_sotilas
=
LuoSotilas
(
Level
.
Width
/
2
,
Level
.
Bottom
+
75
);
AsetaOhjaimet
();
Add
(
sotilas
);
Timer
.
SingleShot
(
1
,
LuoMeteoridi
);
Timer
.
SingleShot
(
10
,
()
=>
_meteoridiMaara
=
2
);
Timer
.
SingleShot
(
20
,
()
=>
_meteoridiMaara
=
3
);
Timer
ajastin
=
new
Timer
();
ajastin
.
Interval
=
8
;
ajastin
.
Timeout
+=
KasvataMeteoridienNopeutta
;
ajastin
.
Start
();
return
sotilas
;
}
LuoMeteoridi
();
void
AsetaOhjaimet
()
{
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Down
,
AsetaNopeusJaAnimaatio
,
"Liiku vasemmalle"
,
sotilas
,
nopeusVasen
);
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Down
,
AsetaNopeusJaAnimaatio
,
"Liiku oikealle"
,
sotilas
,
nopeusOikea
);
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Released
,
PysaytaLiikeJaAnimaatio
,
"Pysäytä vasen liike"
,
sotilas
);
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Released
,
PysaytaLiikeJaAnimaatio
,
"Pysäytä oikea liike"
,
sotilas
);
}
PhoneBackButton
.
Listen
(
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
}
void
AsetaNopeusJaAnimaatio
(
PhysicsObject
sotilas
,
Vector
nopeus
)
{
sotilas
.
Velocity
=
nopeus
;
sotilas
.
Animation
=
sotilasAnimaatio
;
PhysicsObject
LuoSotilas
(
double
x
,
double
y
)
{
var
localSotilas
=
new
PhysicsObject
(
170
,
150
);
localSotilas
.
Position
=
new
Vector
(
x
,
y
);
Image
[]
sotilasLiikkuu
=
LoadImages
(
"sotilasliike"
,
"sotilasjuoksee"
);
_sotilasPaikallaan
=
LoadImage
(
"sotilasPaikallaan"
);
_sotilasAnimaatio
=
new
Animation
(
sotilasLiikkuu
);
localSotilas
.
Image
=
_sotilasPaikallaan
;
Add
(
localSotilas
);
return
localSotilas
;
}
if
(
nopeus
.
X
<
0
)
// Liikkuu vasemmalle
void
AsetaOhjaimet
()
{
sotilas
.
Animation
=
Animation
.
Mirror
(
sotilasAnimaatio
);
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Down
,
AsetaNopeusJaAnimaatio
,
"Liiku vasemmalle"
,
_sotilas
,
_nopeusVasen
);
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Down
,
AsetaNopeusJaAnimaatio
,
"Liiku oikealle"
,
_sotilas
,
_nopeusOikea
);
Keyboard
.
Listen
(
Key
.
Left
,
ButtonState
.
Released
,
PysaytaLiikeJaAnimaatio
,
"Pysäytä vasen liike"
,
_sotilas
);
Keyboard
.
Listen
(
Key
.
Right
,
ButtonState
.
Released
,
PysaytaLiikeJaAnimaatio
,
"Pysäytä oikea liike"
,
_sotilas
);
}
sotilas
.
Animation
.
Start
();
}
void
AsetaNopeusJaAnimaatio
(
PhysicsObject
juoksevaSotilas
,
Vector
nopeus
)
{
juoksevaSotilas
.
Velocity
=
nopeus
;
juoksevaSotilas
.
Animation
=
_sotilasAnimaatio
;
void
PysaytaLiikeJaAnimaatio
(
PhysicsObject
sotilas
)
{
sotilas
.
Velocity
=
Vector
.
Zero
;
sotilas
.
Animation
.
Stop
();
sotilas
.
Image
=
sotilasPaikallaan
;
if
(
nopeus
.
X
<
0
)
{
juoksevaSotilas
.
Animation
=
Animation
.
Mirror
(
_sotilasAnimaatio
);
}
juoksevaSotilas
.
Animation
.
Start
();
}
void
PysaytaLiikeJaAnimaatio
(
PhysicsObject
juoksevaSotilas
)
{
juoksevaSotilas
.
Velocity
=
Vector
.
Zero
;
juoksevaSotilas
.
Animation
.
Stop
();
juoksevaSotilas
.
Image
=
_sotilasPaikallaan
;
}
private
void
LuoMeteoridi
()
{
for
(
int
i
=
0
;
i
<
_meteoridiMaara
;
i
++)
{
PhysicsObject
meteoridi
=
new
PhysicsObject
(
150
,
150
);
meteoridi
.
Image
=
_meteoriditTippuu
[
RandomGen
.
NextInt
(
_meteoriditTippuu
.
Length
)];
meteoridi
.
Shape
=
Shape
.
FromImage
(
meteoridi
.
Image
);
meteoridi
.
Position
=
new
Vector
(
RandomGen
.
NextDouble
(
Level
.
Left
,
Level
.
Right
),
Level
.
Top
+
meteoridi
.
Width
);
meteoridi
.
Velocity
=
new
Vector
(
RandomGen
.
NextDouble
(-
80
,
80
),
_meteoridiPerusNopeus
+
RandomGen
.
NextDouble
(
0
,
-
40
));
meteoridi
.
IgnoresGravity
=
true
;
Add
(
meteoridi
,
1
);
}
double
seuraavaAika
=
RandomGen
.
NextDouble
(
1.0
,
5.0
);
Timer
.
SingleShot
(
seuraavaAika
,
LuoMeteoridi
);
}
void
KasvataMeteoridienNopeutta
()
{
_meteoridiPerusNopeus
-=
15
;
}
}
}
\ 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