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 Punasininen : PhysicsGame |
---|
10 | { |
---|
11 | private const double SPEED = 450; |
---|
12 | private const double JUMPSPEED = 1250; |
---|
13 | private const int RUUDUN_KOKO = 40; |
---|
14 | |
---|
15 | private Player blue; |
---|
16 | private Player red; |
---|
17 | |
---|
18 | private Image bluepic; |
---|
19 | private Image redpic; |
---|
20 | |
---|
21 | public override void Begin() |
---|
22 | { |
---|
23 | //Gravity = new Vector(0, -1000); |
---|
24 | |
---|
25 | CreateLevel(); |
---|
26 | AddControls(); |
---|
27 | |
---|
28 | } |
---|
29 | |
---|
30 | void CreateLevel() |
---|
31 | { |
---|
32 | Gravity = new Vector(0, -1000); |
---|
33 | |
---|
34 | ColorTileMap map = ColorTileMap.FromLevelAsset("dungeon1"); |
---|
35 | map.SetTileMethod(Color.Black, LisaaTaso); |
---|
36 | map.SetTileMethod(Color.FromHexCode("#FF0026FF"), delegate(Vector paikka, double leveys, double korkeus) { blue = CreatePlayer(paikka, leveys, korkeus, bluepic, Color.Blue); }); |
---|
37 | map.SetTileMethod(Color.Red, delegate(Vector paikka, double leveys, double korkeus) { red = CreatePlayer(paikka, leveys, korkeus, redpic, Color.Red); }); |
---|
38 | map.Execute(RUUDUN_KOKO, RUUDUN_KOKO); |
---|
39 | |
---|
40 | Camera.ZoomToAllObjects(); |
---|
41 | |
---|
42 | Level.Background.Color = Color.Black; |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | void LisaaTaso(Vector paikka, double leveys, double korkeus) |
---|
47 | { |
---|
48 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
49 | taso.Position = paikka; |
---|
50 | taso.Color = Color.Black; |
---|
51 | AddCollisionHandler(taso, "player", Varjaa); |
---|
52 | Add(taso); |
---|
53 | } |
---|
54 | |
---|
55 | Player CreatePlayer(Vector paikka, double leveys, double korkeus, Image playerspic, Color playersColor) |
---|
56 | { |
---|
57 | Player player = new Player(leveys, korkeus, playerspic, playersColor); |
---|
58 | player.Position = paikka; |
---|
59 | Add(player); |
---|
60 | return player; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | void Varjaa(PhysicsObject platform, PhysicsObject player) |
---|
65 | { |
---|
66 | platform.Color = player.Color; |
---|
67 | } |
---|
68 | |
---|
69 | void AddControls() |
---|
70 | { |
---|
71 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
72 | |
---|
73 | ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", red); |
---|
74 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", red, JUMPSPEED); |
---|
75 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, "Tähtää", red); |
---|
76 | |
---|
77 | ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", blue); |
---|
78 | ControllerTwo.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", blue, JUMPSPEED); |
---|
79 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, null, blue); |
---|
80 | |
---|
81 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohjeet"); |
---|
82 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta"); |
---|
83 | } |
---|
84 | |
---|
85 | void Move(AnalogState stick, Player player) |
---|
86 | { |
---|
87 | /*Vector state = stick.StateVector; |
---|
88 | player.Walk(state.X * 500);*/ |
---|
89 | |
---|
90 | if (stick.StateVector.Magnitude > 0.15) |
---|
91 | player.Walk(stick.StateVector.X > 0 ? Direction.Right : Direction.Left); |
---|
92 | } |
---|
93 | |
---|
94 | void Jump(Player player, double speed) |
---|
95 | { |
---|
96 | player.Jump(speed); |
---|
97 | } |
---|
98 | |
---|
99 | void Aim(AnalogState tatinTila, Player player) |
---|
100 | { |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | } |
---|