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