[7252] | 1 | using System; |
---|
| 2 | using System.Collections.Generic; |
---|
| 3 | using Jypeli; |
---|
| 4 | using Jypeli.Assets; |
---|
| 5 | using Jypeli.Controls; |
---|
| 6 | using Jypeli.Effects; |
---|
| 7 | using Jypeli.Widgets; |
---|
| 8 | |
---|
| 9 | public class Test : PhysicsGame |
---|
| 10 | { |
---|
| 11 | public override void Begin() |
---|
| 12 | { |
---|
| 13 | LuoKenttä(); |
---|
| 14 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
| 15 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
| 16 | |
---|
| 17 | //Camera.Follow(); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | void LuoKenttä() |
---|
| 21 | { |
---|
| 22 | |
---|
| 23 | ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Kenttä"); |
---|
| 24 | ruudut.SetTileMethod(Color.Red, LuoPelaaja); |
---|
| 25 | ruudut.SetTileMethod(Color.Black, LuoTaso); |
---|
| 26 | ruudut.Execute(40, 40); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void LuoPelaaja(Vector paikka, double leveys, double korkeus) |
---|
| 30 | { |
---|
| 31 | |
---|
| 32 | PhysicsObject Pelaaja1 = new PhysicsObject(leveys, korkeus); |
---|
| 33 | |
---|
| 34 | Pelaaja1.Position = paikka; |
---|
| 35 | |
---|
| 36 | Add(Pelaaja1); |
---|
| 37 | Pelaaja1.Shape = Shape.Circle; |
---|
| 38 | Image olionKuva = LoadImage("Abina"); |
---|
| 39 | Pelaaja1.Image = olionKuva; |
---|
| 40 | |
---|
| 41 | PhysicsObject Pelaaja2 = new PhysicsObject(leveys, korkeus); |
---|
| 42 | Add(Pelaaja2); |
---|
| 43 | Pelaaja2.Position = paikka; |
---|
| 44 | Pelaaja2.Shape = Shape.Circle; |
---|
| 45 | Pelaaja2.Image = LoadImage("pelaaja2"); |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, |
---|
| 49 | LiikutaPelaajaa, null, new Vector(-1000, 0), Pelaaja1); |
---|
| 50 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, |
---|
| 51 | LiikutaPelaajaa, null, new Vector(1000, 0), Pelaaja1); |
---|
| 52 | ControllerOne.Listen(Button.DPadUp, ButtonState.Down, |
---|
| 53 | LiikutaPelaajaa, null, new Vector(0, 1000), Pelaaja1); |
---|
| 54 | ControllerOne.Listen(Button.DPadDown, ButtonState.Down, |
---|
| 55 | LiikutaPelaajaa, null, new Vector(0, -1000), Pelaaja1); |
---|
| 56 | |
---|
| 57 | ControllerTwo.Listen(Button.DPadLeft, ButtonState.Down, |
---|
| 58 | LiikutaPelaajaa, null, new Vector(-1000, 0), Pelaaja2); |
---|
| 59 | ControllerTwo.Listen(Button.DPadRight, ButtonState.Down, |
---|
| 60 | LiikutaPelaajaa, null, new Vector(1000, 0), Pelaaja2); |
---|
| 61 | ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, |
---|
| 62 | LiikutaPelaajaa, null, new Vector(0, 1000), Pelaaja2); |
---|
| 63 | ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, |
---|
| 64 | LiikutaPelaajaa, null, new Vector(0, -1000), Pelaaja2); |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | //camera |
---|
| 68 | Camera.Follow(Pelaaja1, Pelaaja2); |
---|
| 69 | |
---|
| 70 | Camera.StayInLevel = true; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void LuoTaso(Vector paikka, double leveys, double korkeus) |
---|
| 74 | { |
---|
| 75 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
| 76 | taso.Position = paikka; |
---|
| 77 | taso.CollisionIgnoreGroup = 1; |
---|
| 78 | Add(taso); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | void LiikutaPelaajaa(Vector vektori, PhysicsObject pelaaja) |
---|
| 83 | { |
---|
| 84 | pelaaja.Push(vektori); |
---|
| 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|