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 | DoubleMeter percentageTracker; |
---|
22 | |
---|
23 | public override void Begin() |
---|
24 | { |
---|
25 | //Gravity = new Vector(0, -1000); |
---|
26 | CreateLevel(); |
---|
27 | AddControls(); |
---|
28 | } |
---|
29 | |
---|
30 | void CreateLevel() |
---|
31 | { |
---|
32 | Gravity = new Vector(0, -1000); |
---|
33 | |
---|
34 | IsFullScreen = true; |
---|
35 | |
---|
36 | ColorTileMap map = ColorTileMap.FromLevelAsset("dungeon1"); |
---|
37 | map.SetTileMethod(Color.Black, LisaaTaso); |
---|
38 | 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)); }); |
---|
39 | map.SetTileMethod(Color.FromHexCode("FFD800"), CreateWeaponCrate); |
---|
40 | 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)); }); |
---|
41 | map.Execute(TILE_SIZE, TILE_SIZE); |
---|
42 | |
---|
43 | Camera.ZoomToAllObjects(); |
---|
44 | |
---|
45 | Level.Background.Color = Color.Black; |
---|
46 | |
---|
47 | percentageTracker = new DoubleMeter(0, 0, 100); |
---|
48 | |
---|
49 | ProgressBar percentageBar = new ProgressBar(Level.Width / 2, 20) { Y = Screen.Top - 20, BarColor = red.Color, Color = blue.Color }; |
---|
50 | percentageBar.Y = Screen.Top - 20; |
---|
51 | percentageBar.BindTo(percentageTracker); |
---|
52 | Add(percentageBar); |
---|
53 | } |
---|
54 | |
---|
55 | void CreateWeaponCrate(Vector place, double width, double height) |
---|
56 | { |
---|
57 | PhysicsObject crate = PhysicsObject.CreateStaticObject(width, height); |
---|
58 | crate.Position = place; |
---|
59 | Add(crate); |
---|
60 | } |
---|
61 | |
---|
62 | void LisaaTaso(Vector paikka, double leveys, double korkeus) |
---|
63 | { |
---|
64 | PhysicsObject platform = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
65 | platform.Position = paikka; |
---|
66 | platform.Color = Color.Black; |
---|
67 | platform.Tag = "platform"; |
---|
68 | Add(platform); |
---|
69 | } |
---|
70 | |
---|
71 | Player CreatePlayer(Vector paikka, double leveys, double korkeus, Image playerspic, Color playersColor, Vector trackerPosition) |
---|
72 | { |
---|
73 | Player player = new Player(leveys, korkeus, playerspic, playersColor); |
---|
74 | player.Position = paikka; |
---|
75 | Add(player); |
---|
76 | |
---|
77 | AddCollisionHandler(player, "platform", delegate(PhysicsObject a, PhysicsObject b) |
---|
78 | { |
---|
79 | ColorTile(a, b, percentageTracker); |
---|
80 | }); |
---|
81 | |
---|
82 | /* Label percentageLabel = new Label() { TextColor = playersColor, DoubleFormatString = "{0:0.0}%", Position = trackerPosition}; |
---|
83 | Add(percentageLabel); |
---|
84 | |
---|
85 | DoubleMeter percentageTracker = new DoubleMeter(0, 0, 100); |
---|
86 | percentageLabel.BindTo(percentageTracker); |
---|
87 | |
---|
88 | percentageTracker.AddTrigger(30, TriggerDirection.Up, delegate() { Win(player); }); |
---|
89 | |
---|
90 | AddCollisionHandler(player, "platform", delegate(PhysicsObject a, PhysicsObject b) |
---|
91 | { |
---|
92 | ColorTile(a, b, percentageTracker); |
---|
93 | }); |
---|
94 | * */ |
---|
95 | |
---|
96 | return player; |
---|
97 | } |
---|
98 | |
---|
99 | void Win(Player player) |
---|
100 | { |
---|
101 | Pause(); |
---|
102 | //Haluaisin tehdä tähän jonkinlaisen hauskan ponnahdusefektin jossain vaiheessa. Sellaisen napakan zoomin ja sitten boing. Hurdur. |
---|
103 | Camera.ZoomTo(player.Left, player.Bottom, player.Right, player.Top + 100); |
---|
104 | |
---|
105 | Label announcement = new Label("Kiva homma hei") |
---|
106 | { |
---|
107 | TextColor = player.Color, |
---|
108 | Position = Camera.WorldToScreen(player.Position + new Vector(0, 40)), |
---|
109 | TextScale = new Vector(2, 2) |
---|
110 | }; |
---|
111 | Add(announcement); |
---|
112 | |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | void ColorTile(PhysicsObject player, PhysicsObject platform, DoubleMeter tracker) |
---|
117 | { |
---|
118 | platform.Color = player.Color; |
---|
119 | |
---|
120 | List<GameObject> colored = GetObjects(o => (o.Color == red.Color || o.Color == blue.Color) && (String)o.Tag == "platform"); |
---|
121 | tracker.Value = (double)colored.FindAll(o => o.Color == red.Color).Count/colored.Count * 100; |
---|
122 | |
---|
123 | //tracker.Value = (double)GetObjects(o => o.Color == player.Color && (String)o.Tag == "platform").Count / GetObjects(o => o.Color == player.Color || o.Color == blue.Color && (String)o.Tag == "platform").Count * 100.0; |
---|
124 | //tracker.Value = (double)GetObjects(o => o.Color == player.Color && (String)o.Tag == "colored").Count / GetObjectsWithTag("platform").Count * 100.0; |
---|
125 | } |
---|
126 | |
---|
127 | void AddControls() |
---|
128 | { |
---|
129 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
130 | |
---|
131 | ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", red); |
---|
132 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", red, JUMPSPEED); |
---|
133 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, "Tähtää", red); |
---|
134 | |
---|
135 | ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", blue); |
---|
136 | ControllerTwo.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", blue, JUMPSPEED); |
---|
137 | ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, null, blue); |
---|
138 | |
---|
139 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohjeet"); |
---|
140 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta"); |
---|
141 | } |
---|
142 | |
---|
143 | void Move(AnalogState stick, Player player) |
---|
144 | { |
---|
145 | //player.Walk(stick.StateVector.X * 500); |
---|
146 | |
---|
147 | if (stick.StateVector.Magnitude > 0.15) |
---|
148 | player.Walk(stick.StateVector.X > 0 ? Direction.Right : Direction.Left); |
---|
149 | } |
---|
150 | |
---|
151 | void Jump(Player player, double speed) |
---|
152 | { |
---|
153 | player.Jump(speed); |
---|
154 | } |
---|
155 | |
---|
156 | void Aim(AnalogState tatinTila, Player player) |
---|
157 | { |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | } |
---|