diff --git a/HT/HT/HT.cs b/HT/HT/HT.cs index 90b8860a0ec820c9a47342c22634a389b4761d70..d780f1fda727b4f9ee6d4d124a69e5aa513e543b 100644 --- a/HT/HT/HT.cs +++ b/HT/HT/HT.cs @@ -1,19 +1,55 @@ using System; using System.Collections.Generic; +using System.Drawing; using Jypeli; using Jypeli.Assets; using Jypeli.Controls; using Jypeli.Widgets; +using Color = Jypeli.Color; namespace HT; -public class HT : PhysicsGame +public class Ht : PhysicsGame { + PhysicsObject broidi; public override void Begin() { // Kirjoita ohjelmakoodisi tähän + LuoKentta(); + AsetaOhjaimet(); + + + void LuoKentta() + { + broidi = new PhysicsObject(50, 50); + broidi.Shape = Shape.Rectangle; + broidi.Color = Color.Red; + Add(broidi); + + } + void AsetaOhjaimet() + { + Keyboard.Listen(Key.W, ButtonState.Down, Liikuttaa, "Pelaaja 1: Liikuta Broidia ylös", new Vector (0.0, 300.0)); + Keyboard.Listen(Key.W, ButtonState.Released, Liikuttaa, null, Vector.Zero); + Keyboard.Listen(Key.S, ButtonState.Down, Liikuttaa, "Pelaaja 1: Liikuta Broidia alas", new Vector (0.0, -300.0)); + Keyboard.Listen(Key.S, ButtonState.Released, Liikuttaa, null, Vector.Zero); + Keyboard.Listen(Key.D, ButtonState.Down, Liikuttaa, "pelaaja 2: Liikuta Broidia ylös", new Vector(300.0, 0.0)); + Keyboard.Listen(Key.D, ButtonState.Released, Liikuttaa, null, Vector.Zero); + Keyboard.Listen(Key.A, ButtonState.Down, Liikuttaa, "Pelaaja 2: Liikuta Broidia alas", new Vector(-300, 0.0)); + Keyboard.Listen(Key.A, ButtonState.Released, Liikuttaa, null, Vector.Zero); + } + + void Liikuttaa(Vector nopeus) + { + broidi.Velocity = nopeus; + } + + Level.Background.Color = new Color(189, 183, 107); PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); + + } + } \ No newline at end of file diff --git a/HT/HT/Ohjelma.cs b/HT/HT/Ohjelma.cs index f794f43245082955578c89437cd72a3df2003897..14ef970b12159da1222fe5f8d82bf6b9c8ea8e78 100644 --- a/HT/HT/Ohjelma.cs +++ b/HT/HT/Ohjelma.cs @@ -19,7 +19,7 @@ namespace HT [STAThread] static void Main() { - using var game = new HT(); + using var game = new Ht(); game.Run(); } }