1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.ScreenObjects; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | namespace Get_the_money |
---|
7 | { |
---|
8 | public class Peli : TopDownPhysicsGame |
---|
9 | |
---|
10 | { |
---|
11 | Automobile auto; |
---|
12 | PhysicsObject vasenseina; |
---|
13 | PhysicsObject oikeaseina; |
---|
14 | IntMeter pistelaskuri; |
---|
15 | PhysicsObject raha; |
---|
16 | |
---|
17 | protected override void Begin() |
---|
18 | { |
---|
19 | |
---|
20 | SetWindowSize(true); |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | luokentta(); |
---|
25 | luoauto(); |
---|
26 | Asetaohjaimet(); |
---|
27 | luopistelaskuri(); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | IntMeter laskuri = new IntMeter(0); |
---|
32 | laskuri.MaxValue = 10000; |
---|
33 | laskuri.UpperLimit += Laskurinylaraja; |
---|
34 | |
---|
35 | |
---|
36 | Level.Background.CreateGradient(Color.Turquoise, Color.SkyBlue); |
---|
37 | |
---|
38 | KineticFriction = 1.0; // Asetetaan kitka |
---|
39 | |
---|
40 | } |
---|
41 | |
---|
42 | void luopistelaskuri() |
---|
43 | { |
---|
44 | |
---|
45 | pistelaskuri = new IntMeter(0); |
---|
46 | ValueDisplay pistenaytto = new ValueDisplay(); |
---|
47 | |
---|
48 | pistenaytto.Text = "rahasi "; |
---|
49 | |
---|
50 | pistenaytto.X = Screen.Left + 500; |
---|
51 | pistenaytto.Y = Screen.Top - 100; |
---|
52 | |
---|
53 | pistenaytto.ValueColor = Color.Black; |
---|
54 | pistenaytto.TextColor = Color.White; |
---|
55 | |
---|
56 | pistenaytto.BindTo(pistelaskuri); |
---|
57 | |
---|
58 | Add(pistenaytto); |
---|
59 | //tässä lisätään pistä näytö |
---|
60 | } |
---|
61 | void Asetaohjaimet() |
---|
62 | { |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | Keyboard.Listen(Key.Enter, ButtonState.Pressed, aloitaalusta, "aloitaalusta");// jatka!!!... |
---|
67 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
68 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
69 | |
---|
70 | Keyboard.Listen(Key.Up, ButtonState.Down, kiihdyta, "Kiihdytä", auto); |
---|
71 | Keyboard.Listen(Key.Down, ButtonState.Down, jarruta, "Jarruta", auto); |
---|
72 | Keyboard.Listen(Key.Left, ButtonState.Down, kaanny, "Käänny vasemmalle", auto, Angle.Degrees(90)); |
---|
73 | Keyboard.Listen(Key.Right, ButtonState.Down, kaanny, "Käänny oikealle", auto, Angle.Degrees(-90)); |
---|
74 | |
---|
75 | ControllerOne.Listen(Button.LeftTrigger, ButtonState.Down,kiihdyta,"kiihdutää!",auto); |
---|
76 | ControllerOne.Listen(Button.RightTrigger,ButtonState.Down,jarruta,"jarrutaa",auto); |
---|
77 | ControllerOne.Listen(Button.LeftShoulder,ButtonState.Down,kaanny,"käänny", auto,Angle.Degrees(10)); |
---|
78 | ControllerOne.Listen(Button.RightShoulder,ButtonState.Down,kaanny,"käänny", auto,Angle.Degrees(-10)); |
---|
79 | |
---|
80 | ControllerOne.Listen(Button.B, ButtonState.Pressed, ShowControlHelp, "näytäohjeet"); |
---|
81 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "poistu"); |
---|
82 | ControllerOne.Listen(Button.X, ButtonState.Pressed, aloitaalusta, "Aloitaa alusta pelin"); |
---|
83 | |
---|
84 | ShowControlHelp(); |
---|
85 | } |
---|
86 | |
---|
87 | void luoauto() |
---|
88 | { |
---|
89 | auto = new Automobile(40, 30); |
---|
90 | auto.Mass = 140.0; |
---|
91 | Add(auto); |
---|
92 | auto.X = 0; |
---|
93 | auto.Y = -140; |
---|
94 | auto.AngularDamping = 0.95;// tämä estää pyörimisen |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | private void luokivi() |
---|
99 | { |
---|
100 | throw new NotImplementedException(); |
---|
101 | } |
---|
102 | |
---|
103 | void kiihdyta(Automobile auto) |
---|
104 | { |
---|
105 | auto.Accelerate(Time.SinceLastUpdate.TotalSeconds); |
---|
106 | } |
---|
107 | |
---|
108 | void jarruta(Automobile auto) |
---|
109 | { |
---|
110 | auto.Brake(Time.SinceLastUpdate.TotalSeconds); |
---|
111 | } |
---|
112 | |
---|
113 | void kaanny(Automobile auto, Angle kaannos) |
---|
114 | { |
---|
115 | auto.Turn(kaannos, Time.SinceLastUpdate.TotalSeconds); |
---|
116 | } |
---|
117 | |
---|
118 | void luokentta() |
---|
119 | { |
---|
120 | |
---|
121 | |
---|
122 | Timer ajastin = new Timer(); |
---|
123 | ajastin.Interval = 2; |
---|
124 | ajastin.Trigger += lisaakivia; |
---|
125 | Add(ajastin); |
---|
126 | ajastin.Start(); |
---|
127 | |
---|
128 | Timer Ajastin = new Timer(); |
---|
129 | Ajastin.Interval = 10; |
---|
130 | Ajastin.Trigger += lisaaraha; |
---|
131 | Add(Ajastin); |
---|
132 | Ajastin.Start(); |
---|
133 | |
---|
134 | |
---|
135 | Camera.ZoomToLevel(); |
---|
136 | |
---|
137 | vasenseina = Level.CreateLeftBorder(); |
---|
138 | vasenseina.Restitution = 1.0; |
---|
139 | vasenseina.IsVisible = false; |
---|
140 | oikeaseina = Level.CreateRightBorder(); |
---|
141 | oikeaseina.Restitution = 1.0; |
---|
142 | oikeaseina.IsVisible = false; |
---|
143 | PhysicsObject alaseina = Level.CreateBottomBorder(); |
---|
144 | alaseina.Restitution = 1.0; |
---|
145 | alaseina.IsVisible = false; |
---|
146 | PhysicsObject ylaseina = Level.CreateTopBorder(); |
---|
147 | ylaseina.Restitution = 1.0; |
---|
148 | ylaseina.IsVisible = false; |
---|
149 | |
---|
150 | //kivi(); |
---|
151 | } |
---|
152 | |
---|
153 | void kassitelekiventormays(PhysicsObject kivi, PhysicsObject kohde) |
---|
154 | { |
---|
155 | if (kohde == oikeaseina) |
---|
156 | { |
---|
157 | kivi.Destroy(); |
---|
158 | } |
---|
159 | else if (kohde == auto) |
---|
160 | { |
---|
161 | auto.Destroy(); |
---|
162 | MessageDisplay.Add("Game Over"); |
---|
163 | pistelaskuri.Reset(); |
---|
164 | ControllerOne.Vibrate(1, 1, 3, 3,3); |
---|
165 | } |
---|
166 | else if (kohde == raha) |
---|
167 | { |
---|
168 | raha.Destroy(); |
---|
169 | MessageDisplay.Add("haahaa raha tuhoutui"); |
---|
170 | } |
---|
171 | else if (kohde == vasenseina) |
---|
172 | { |
---|
173 | kivi.Destroy(); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | void kivi() |
---|
178 | { |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | void lisaakivia(Timer sender) |
---|
183 | { |
---|
184 | PhysicsObject kivi = new PhysicsObject(23, 23); |
---|
185 | kivi.Shape = Shapes.Circle; |
---|
186 | kivi.X = -450; |
---|
187 | kivi.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); |
---|
188 | kivi.Restitution = 1.0; |
---|
189 | AddCollisionHandler(kivi, kassitelekiventormays); |
---|
190 | |
---|
191 | Add(kivi); |
---|
192 | Vector impulssi = new Vector(400.0, 0.0); |
---|
193 | kivi.Hit(impulssi); |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | void kassitelerahantormays ( PhysicsObject raha, PhysicsObject kohde) |
---|
198 | { |
---|
199 | |
---|
200 | if (kohde == auto) |
---|
201 | { |
---|
202 | pistelaskuri.Value += 250; |
---|
203 | MessageDisplay.Add("Sait Rahaa!"); |
---|
204 | raha.Destroy(); |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | } |
---|
209 | |
---|
210 | void lisaaraha(Timer sender) |
---|
211 | { |
---|
212 | PhysicsObject raha = new PhysicsObject(23, 23); |
---|
213 | raha.Shape = Shapes.Circle; |
---|
214 | raha.X = RandomGen.NextDouble(Level.Left, Level.Right); |
---|
215 | raha.Y = RandomGen.NextDouble(Level.Top, Level.Bottom); |
---|
216 | raha.Color = Color.ForestGreen; |
---|
217 | AddCollisionHandler(raha, kassitelerahantormays); |
---|
218 | |
---|
219 | raha.MaximumLifetime = new TimeSpan(0,0,15); |
---|
220 | |
---|
221 | Add(raha); |
---|
222 | |
---|
223 | } |
---|
224 | |
---|
225 | void Laskurinylaraja(int arvo) |
---|
226 | { |
---|
227 | MessageDisplay.TextColor = Color.White; |
---|
228 | MessageDisplay.Add("Olet hyvä pelaaja!"); |
---|
229 | } |
---|
230 | |
---|
231 | void aloitaalusta() |
---|
232 | { |
---|
233 | ClearAll(); |
---|
234 | luokentta(); |
---|
235 | luoauto(); |
---|
236 | luopistelaskuri(); |
---|
237 | Asetaohjaimet(); |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | } |
---|
242 | } |
---|