1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | |
---|
7 | class Tasohyppely : PhysicsGame |
---|
8 | { |
---|
9 | |
---|
10 | |
---|
11 | const double nopeus = 200; |
---|
12 | const double hyppyVoima =3000; |
---|
13 | |
---|
14 | PlatformCharacter Seppo; |
---|
15 | PlatformCharacter norsu; |
---|
16 | PlatformCharacter tahti; |
---|
17 | PlatformCharacter maali; |
---|
18 | PlatformCharacter AntiSeppo; |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | protected override void Begin() |
---|
25 | |
---|
26 | { |
---|
27 | Gravity = new Vector(0, -1000); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | luoKentta(); |
---|
32 | lisaaNappaimet(); |
---|
33 | |
---|
34 | Camera.Follow(Seppo); |
---|
35 | |
---|
36 | Camera.StayInLevel = true; |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | void luoKentta() |
---|
41 | { |
---|
42 | Level.Background.CreateGradient(Color.White, Color.SkyBlue); |
---|
43 | PhysicsObject vasenReuna = Level.CreateLeftBorder(); |
---|
44 | vasenReuna.StaticFriction = 0; |
---|
45 | PhysicsObject OikeaReuna = Level.CreateRightBorder(); |
---|
46 | OikeaReuna.StaticFriction = 0; |
---|
47 | PhysicsObject Pohja = Level.CreateBottomBorder(); |
---|
48 | Pohja.StaticFriction = 0; |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | lisaaTaso(-200, -200); |
---|
54 | lisaaTaso(100, -200); |
---|
55 | lisaaTaso(100, 200); |
---|
56 | lisaaTaso(-200, 200); |
---|
57 | lisaaTaso(-50, 0); |
---|
58 | |
---|
59 | |
---|
60 | lisaaPelaajat(); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void lisaaTaso(double x, double y) |
---|
66 | { |
---|
67 | PhysicsObject taso = PhysicsObject.CreateStaticObject(100, 30); |
---|
68 | taso.Color = Color.Green; |
---|
69 | taso.X = x; |
---|
70 | taso.Y = y; |
---|
71 | Add(taso); |
---|
72 | } |
---|
73 | |
---|
74 | void lisaaPelaajat() |
---|
75 | { |
---|
76 | Seppo = new PlatformCharacter(30,60); |
---|
77 | Seppo.Mass = 4.0; |
---|
78 | Seppo.Image = LoadImage("Seppo"); |
---|
79 | Seppo.X = -200; |
---|
80 | Seppo.Y = 120; |
---|
81 | |
---|
82 | Add(Seppo); |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | AntiSeppo = new PlatformCharacter(30,60); |
---|
87 | AntiSeppo.Mass = 4.0; |
---|
88 | AntiSeppo.Image = LoadImage("Seppo 2"); |
---|
89 | AntiSeppo.X = 100; |
---|
90 | AntiSeppo.Y = 120; |
---|
91 | |
---|
92 | Add(AntiSeppo); |
---|
93 | |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | void lisaaNappaimet() |
---|
101 | { |
---|
102 | Keyboard.Listen(Key.CapsLock, ButtonState.Pressed, Begin, ""); |
---|
103 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
104 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
105 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", Seppo, -nopeus); |
---|
106 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", Seppo, nopeus); |
---|
107 | ControllerOne.Listen(Button.A, ButtonState.Down, rajahdys3, ""); |
---|
108 | ControllerOne.Listen(Button.DPadUp, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", Seppo, hyppyVoima); |
---|
109 | ControllerOne.Listen(Button.X, ButtonState.Pressed, rajahdys, ""); |
---|
110 | |
---|
111 | ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
112 | ControllerTwo.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", AntiSeppo, -nopeus); |
---|
113 | ControllerTwo.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", AntiSeppo, nopeus); |
---|
114 | ControllerTwo.Listen(Button.A, ButtonState.Down, rajahdys4, ""); |
---|
115 | ControllerTwo.Listen(Button.DPadUp, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", AntiSeppo, hyppyVoima); |
---|
116 | ControllerTwo.Listen(Button.X, ButtonState.Pressed, rajahdys2, ""); |
---|
117 | |
---|
118 | |
---|
119 | ControllerOne.Listen(Button.Start, ButtonState.Pressed, restartti, "Aloita peli uudelleen"); |
---|
120 | ControllerTwo.Listen(Button.Start, ButtonState.Pressed, restartti, "Aloita peli uudelleen"); |
---|
121 | |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | void liikuta(PlatformCharacter hahmo, double nopeus) |
---|
126 | { |
---|
127 | hahmo.Walk(nopeus); |
---|
128 | } |
---|
129 | |
---|
130 | void hyppaa(PlatformCharacter hahmo, double voima) |
---|
131 | { |
---|
132 | hahmo.Jump(voima ); |
---|
133 | } |
---|
134 | |
---|
135 | void rajahdys() |
---|
136 | { |
---|
137 | Explosion rajahdys = new Explosion(500.00); |
---|
138 | rajahdys.Position = Seppo.Position; |
---|
139 | Add(rajahdys); |
---|
140 | rajahdys.Speed = 500.0; |
---|
141 | rajahdys.Force = 1000; |
---|
142 | ControllerOne.Vibrate(99, 99, 99, 99, 0.1); |
---|
143 | |
---|
144 | |
---|
145 | } |
---|
146 | void rajahdys2() |
---|
147 | { |
---|
148 | Explosion rajahdys = new Explosion(500.00); |
---|
149 | rajahdys.Position = AntiSeppo.Position; |
---|
150 | Add(rajahdys); |
---|
151 | rajahdys.Speed = 500.0; |
---|
152 | rajahdys.Force = 1000; |
---|
153 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | void rajahdys3() |
---|
158 | { |
---|
159 | Explosion rajahdys = new Explosion(500.00); |
---|
160 | rajahdys.Position = Seppo.Position; |
---|
161 | Add(rajahdys); |
---|
162 | rajahdys.Speed = 500.0; |
---|
163 | rajahdys.Force = 200; |
---|
164 | ControllerOne.Vibrate(99, 99, 99, 99, 0.1); |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | void rajahdys4() |
---|
171 | { |
---|
172 | Explosion rajahdys = new Explosion(500.00); |
---|
173 | rajahdys.Position = AntiSeppo.Position; |
---|
174 | Add(rajahdys); |
---|
175 | rajahdys.Speed = 500.0; |
---|
176 | rajahdys.Force = 200; |
---|
177 | ControllerTwo.Vibrate(99, 99, 99, 99, 0.1); |
---|
178 | } |
---|
179 | |
---|
180 | void restartti() |
---|
181 | { |
---|
182 | |
---|
183 | Seppo.X = -200; |
---|
184 | Seppo.Y = 120; |
---|
185 | |
---|
186 | AntiSeppo.X = 100; |
---|
187 | AntiSeppo.Y = 120; |
---|
188 | |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|