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