Skip to content
Snippets Groups Projects
Commit a5d3044c authored by Snellman Väinö Juhani's avatar Snellman Väinö Juhani
Browse files

paranneltiin pelihahmon liikkuvuutta

parent d339266a
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,18 @@ namespace Sammakkopeli
{
public class Sammakkopeli : PhysicsGame
{
Vector sammakkoVasen = new Vector(-500, -400);
Vector sammakkoOikea = new Vector(500, -400);
Vector sammakkoPainovoima = new Vector(0, -400);
Vector suunta;
PhysicsObject sammakko;
Timer hyppyLaskuri;
Timer tarkastaLiike;
int sammakkoTippuuKertoja = 8;
bool onkoHypannut = false;
double nopeusX = 0.0;
double nopeusY = -800.0;
public override void Begin()
{
......@@ -26,11 +32,25 @@ namespace Sammakkopeli
public void AsetaOhjaimet()
{
Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelihahmoa, null, sammakkoVasen);
Keyboard.Listen(Key.Left, ButtonState.Released, LiikutaPelihahmoa, null, sammakkoPainovoima);
Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, null, -1);
Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaSammakko, null);
Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelihahmoa, null, sammakkoOikea);
Keyboard.Listen(Key.Right, ButtonState.Released, LiikutaPelihahmoa, null, sammakkoPainovoima);
Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus, null, 1);
Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaSammakko, null);
Keyboard.Listen(Key.Space, ButtonState.Pressed, SammakkoHyppaa, null);
}
void AsetaNopeus(int suunta)
{
nopeusX = suunta * 600.0;
}
void PysaytaSammakko()
{
nopeusX = 0.0;
}
......@@ -40,26 +60,65 @@ namespace Sammakkopeli
LuoPelihahmo(0, 0);
Level.CreateBottomBorder(0.0, true);
hyppyLaskuri = new Timer();
hyppyLaskuri.Interval = 0.05;
hyppyLaskuri.Timeout += SammakkoTippuu;
tarkastaLiike = new Timer();
tarkastaLiike.Interval = 0.05;
tarkastaLiike.Timeout += LiikutaPelihahmoa;
tarkastaLiike.Start();
}
public void LuoPelihahmo(double x, double y)
{
sammakko = new PhysicsObject(40.0, 26.0);
//sammakko = LoadImage("VainSammakko");
sammakko.Shape = Shape.Rectangle;
sammakko.X = x;
sammakko.Y = y;
sammakko.Color = Color.Green;
sammakko.Velocity = sammakkoPainovoima;
Add(sammakko);
AddCollisionHandler(sammakko, KasitteleSammakonTormays);
}
public void LiikutaPelihahmoa(Vector suunta)
public void LiikutaPelihahmoa()
{
suunta = new Vector(nopeusX, nopeusY);
sammakko.Velocity = suunta;
}
public void SammakkoHyppaa()
{
if (onkoHypannut == false)
{
onkoHypannut = true;
hyppyLaskuri.Start(16);
}
}
void SammakkoTippuu()
{
sammakkoTippuuKertoja -= 1;
if (sammakkoTippuuKertoja < -7)
{
nopeusY = -800.0;
sammakkoTippuuKertoja = 8;
return;
}
nopeusY = sammakkoTippuuKertoja * 100;
}
void KasitteleSammakonTormays(PhysicsObject tormaaja, PhysicsObject kohde)
{
onkoHypannut = false;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment