1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Effects; |
---|
4 | using Jypeli.Widgets; |
---|
5 | using Jypeli.Assets; |
---|
6 | |
---|
7 | public class Peli : PhysicsGame |
---|
8 | { |
---|
9 | const double nopeus = 200; |
---|
10 | const double hyppyVoima = 4000; |
---|
11 | PlatformCharacter katkis; |
---|
12 | PlatformCharacter rapu; |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | IntMeter pisteLaskuri; |
---|
17 | IntMeter katkisElamat, rapuElamat; |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | protected override void Begin() |
---|
22 | { |
---|
23 | AloitaPeli(); |
---|
24 | luoKentta(); |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | katkis = new PlatformCharacter(220.0, 220.0); |
---|
29 | Add(katkis); |
---|
30 | katkis.Mass = 3.0; |
---|
31 | katkis.X = 380.0; |
---|
32 | katkis.Y = -250.0; |
---|
33 | katkis.Image = LoadImage("katkis"); |
---|
34 | |
---|
35 | |
---|
36 | //pannu = new GameObject(500, 500); |
---|
37 | //pannu.Color = Color.Red; |
---|
38 | //pannu.Tag = "pannu"; |
---|
39 | //Add(pannu); |
---|
40 | //katkis.Add(pannu); |
---|
41 | |
---|
42 | rapu = new PlatformCharacter(300.0, 300.0); |
---|
43 | Add(rapu); |
---|
44 | rapu.Mass = 4.0; |
---|
45 | rapu.X = -380.0; |
---|
46 | rapu.Y = -200.0; |
---|
47 | rapu.Image = LoadImage("rapu"); |
---|
48 | |
---|
49 | //kukka = new GameObject(500, 500); |
---|
50 | //kukka.Color = Color.Red; |
---|
51 | //rapu.Add(kukka); |
---|
52 | |
---|
53 | |
---|
54 | AddCollisionHandler(katkis, katkisTormaa); |
---|
55 | AddCollisionHandler(rapu, rapuTormaa); |
---|
56 | |
---|
57 | Level.CreateBorders(false); |
---|
58 | Level.BackgroundColor = Color.Black; |
---|
59 | |
---|
60 | Camera.ZoomToLevel(); |
---|
61 | |
---|
62 | Gravity = new Vector(0.0, -800.0); |
---|
63 | lisaaNappaimet(); |
---|
64 | LuoLaskuri(); |
---|
65 | } |
---|
66 | |
---|
67 | void lisaaNappaimet() |
---|
68 | { |
---|
69 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
70 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
71 | |
---|
72 | Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", katkis, -100.0); |
---|
73 | Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", katkis, 100.0); |
---|
74 | Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", katkis, hyppyVoima); |
---|
75 | Keyboard.Listen(Key.M, ButtonState.Pressed, katkisiskee, "Paistinpannu"); |
---|
76 | |
---|
77 | Keyboard.Listen(Key.A, ButtonState.Down, liikuta, "Liikkuu vasemmalle", rapu, -100.0); |
---|
78 | Keyboard.Listen(Key.D, ButtonState.Down, liikuta, "Liikkuu oikealle", rapu, 100.0); |
---|
79 | Keyboard.Listen(Key.W, ButtonState.Pressed, hyppaa, "Hyppää", rapu, hyppyVoima); |
---|
80 | Keyboard.Listen(Key.Q, ButtonState.Pressed, rapuiskee, "Kukka"); |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | void katkisiskee() |
---|
89 | { |
---|
90 | Image[] katkisKuvat = LoadImages("katkis", "katkisiskee", "katkisiskee", "katkisiskee"); |
---|
91 | katkis.Animation = new Animation(katkisKuvat); |
---|
92 | katkis.Animation.Start(1); |
---|
93 | Vector etaisyys = new Vector(katkis.X - rapu.X, katkis.Y - rapu.Y); |
---|
94 | if(etaisyys.Magnitude < 300) |
---|
95 | { |
---|
96 | rapuElamat.Value -=5; |
---|
97 | ExplosionSystem rajahdys = new ExplosionSystem(LoadImage("bang"), 1); |
---|
98 | Add(rajahdys); |
---|
99 | rajahdys.AddEffect(0, 0, 1); |
---|
100 | } |
---|
101 | |
---|
102 | if (rapuElamat.Value <= 0) |
---|
103 | { |
---|
104 | LopetusRuutu(); |
---|
105 | MessageDisplay.Add("KATKIS VOITTI"); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | void rapuiskee() |
---|
110 | { |
---|
111 | Image[] rapuKuvat = LoadImages("rapu", "rapuiskee", "rapuiskee", "rapuiskee"); |
---|
112 | rapu.Animation = new Animation(rapuKuvat); |
---|
113 | rapu.Animation.Start(1); |
---|
114 | Vector etaisyys = new Vector(katkis.X - rapu.X, katkis.Y - rapu.Y); |
---|
115 | if (etaisyys.Magnitude < 300) |
---|
116 | |
---|
117 | { |
---|
118 | katkisElamat.Value -=5; |
---|
119 | |
---|
120 | ExplosionSystem rajahdys = new ExplosionSystem(LoadImage("loyh"), 1); |
---|
121 | Add(rajahdys); |
---|
122 | rajahdys.AddEffect(0, 0, 1); |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | if (katkisElamat.Value <= 0) |
---|
129 | { |
---|
130 | LopetusRuutu(); |
---|
131 | MessageDisplay.Add("RAPU VOITTI"); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | void liikuta(PlatformCharacter hahmo, double nopeus) |
---|
139 | { |
---|
140 | hahmo.Walk(nopeus); |
---|
141 | } |
---|
142 | |
---|
143 | void hyppaa(PlatformCharacter hahmo, double voima) |
---|
144 | { |
---|
145 | hahmo.Jump(voima); |
---|
146 | } |
---|
147 | |
---|
148 | void luoKentta() |
---|
149 | { |
---|
150 | Level.CreateBorders(); |
---|
151 | Level.Background.Image = LoadImage("paistinpannukuumana2"); |
---|
152 | } |
---|
153 | |
---|
154 | void katkisTormaa(PhysicsObject katkis, PhysicsObject kohde) |
---|
155 | { |
---|
156 | //if (kohde.Tag.ToString() == "pannu") |
---|
157 | //{ |
---|
158 | // MessageDisplay.Add("katkikseen osui"); |
---|
159 | //} |
---|
160 | } |
---|
161 | |
---|
162 | void rapuTormaa(PhysicsObject rapu, PhysicsObject kohde) |
---|
163 | { |
---|
164 | |
---|
165 | } |
---|
166 | void LuoLaskuri() |
---|
167 | { |
---|
168 | pisteLaskuri = new IntMeter(100); |
---|
169 | |
---|
170 | katkisElamat = new IntMeter(100); |
---|
171 | rapuElamat = new IntMeter(100); |
---|
172 | |
---|
173 | Label katkisNaytto = new Label(100.0, 60.0); |
---|
174 | katkisNaytto.X = Screen.Right - 100; |
---|
175 | katkisNaytto.Y = Screen.Top - 50; |
---|
176 | katkisNaytto.TextColor = Color.White; |
---|
177 | katkisNaytto.Color = Color.Black; |
---|
178 | |
---|
179 | katkisNaytto.BindTo(katkisElamat); |
---|
180 | Add(katkisNaytto); |
---|
181 | |
---|
182 | Label rapuNaytto = new Label(100.0, 60.0); |
---|
183 | rapuNaytto.X = Screen.Left + 100; |
---|
184 | rapuNaytto.Y = Screen.Top - 50; |
---|
185 | rapuNaytto.TextColor = Color.White; |
---|
186 | rapuNaytto.Color = Color.Black; |
---|
187 | |
---|
188 | rapuNaytto.BindTo(rapuElamat); |
---|
189 | Add(rapuNaytto); |
---|
190 | |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | void AloitaPeli() |
---|
196 | { } |
---|
197 | |
---|
198 | void LopetusRuutu() |
---|
199 | { |
---|
200 | ClearAll(); |
---|
201 | |
---|
202 | MessageDisplay.TextColor = Color.White; |
---|
203 | MessageDisplay.Position = new Vector(00, 00); |
---|
204 | |
---|
205 | Keyboard.Listen(Key.V,ButtonState.Pressed, Begin, null); |
---|
206 | |
---|
207 | |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | } |
---|