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 TILE_SIZE = 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 | CreateLevel(); |
---|
25 | AddControls(); |
---|
26 | } |
---|
27 | |
---|
28 | void CreateLevel() |
---|
29 | { |
---|
30 | Gravity = new Vector(0, -1000); |
---|
31 | |
---|
32 | IsFullScreen = true; |
---|
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, new Vector(-Screen.Width / 2 + 50, Screen.Height / 2 - 50)); }); |
---|
37 | map.SetTileMethod(Color.Red, delegate(Vector paikka, double leveys, double korkeus) { red = CreatePlayer(paikka, leveys, korkeus, redpic, Color.Red, new Vector(Screen.Width / 2 - 50, Screen.Height / 2 - 50)); }); |
---|
38 | map.Execute(TILE_SIZE, TILE_SIZE); |
---|
39 | |
---|
40 | Camera.ZoomToAllObjects(); |
---|
41 | |
---|
42 | Level.Background.Color = Color.Black; |
---|
43 | } |
---|
44 | |
---|
45 | void LisaaTaso(Vector paikka, double leveys, double korkeus) |
---|
46 | { |
---|
47 | PhysicsObject platform = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
48 | platform.Position = paikka; |
---|
49 | platform.Color = Color.Black; |
---|
50 | platform.Tag = "platform"; |
---|
51 | Add(platform); |
---|
52 | } |
---|
53 | |
---|
54 | Player CreatePlayer(Vector paikka, double leveys, double korkeus, Image playerspic, Color playersColor, Vector trackerPosition) |
---|
55 | { |
---|
56 | Player player = new Player(leveys, korkeus, playerspic, playersColor); |
---|
57 | player.Position = paikka; |
---|
58 | Add(player); |
---|
59 | |
---|
60 | Label percentageLabel = new Label() { TextColor = playersColor, DecimalPlaces = 1, Position = trackerPosition}; |
---|
61 | Add(percentageLabel); |
---|
62 | |
---|
63 | DoubleMeter percentageTracker = new DoubleMeter(0, 0, 100); |
---|
64 | percentageLabel.BindTo(percentageTracker); |
---|
65 | |
---|
66 | AddCollisionHandler(player, "platform", delegate(PhysicsObject a, PhysicsObject b) |
---|
67 | { |
---|
68 | ColorTile(a, b, percentageTracker); |
---|
69 | }); |
---|
70 | |
---|
71 | return player; |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | void ColorTile(PhysicsObject player, PhysicsObject platform, DoubleMeter tracker) |
---|
76 | { |
---|
77 | platform.Color = player.Color; |
---|
78 | |
---|
79 | tracker.Value = (double)GetObjects(o => o.Color == player.Color && (String)o.Tag == "platform").Count / GetObjectsWithTag("platform").Count * 100.0; |
---|
80 | } |
---|
81 | |
---|
82 | void AddControls() |
---|
83 | { |
---|
84 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
85 | |
---|
86 | ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", red); |
---|
87 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", red, JUMPSPEED); |
---|
88 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, "Tähtää", red); |
---|
89 | |
---|
90 | ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", blue); |
---|
91 | ControllerTwo.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", blue, JUMPSPEED); |
---|
92 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, null, blue); |
---|
93 | |
---|
94 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohjeet"); |
---|
95 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta"); |
---|
96 | } |
---|
97 | |
---|
98 | void Move(AnalogState stick, Player player) |
---|
99 | { |
---|
100 | //player.Walk(stick.StateVector.X * 500); |
---|
101 | |
---|
102 | if (stick.StateVector.Magnitude > 0.15) |
---|
103 | player.Walk(stick.StateVector.X > 0 ? Direction.Right : Direction.Left); |
---|
104 | } |
---|
105 | |
---|
106 | void Jump(Player player, double speed) |
---|
107 | { |
---|
108 | player.Jump(speed); |
---|
109 | } |
---|
110 | |
---|
111 | void Aim(AnalogState tatinTila, Player player) |
---|
112 | { |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | } |
---|