1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public class Peli : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject alus; |
---|
12 | //LaserGun laser; |
---|
13 | PhysicsObject vihu1; |
---|
14 | PhysicsObject vihu2; |
---|
15 | PhysicsObject vihu3; |
---|
16 | PhysicsObject vihu4; |
---|
17 | Image aluskuva = LoadImage("alus"); |
---|
18 | Shape alusmuoto; |
---|
19 | |
---|
20 | Image vihukuva1 = LoadImage("vihu1"); |
---|
21 | Shape vihumuoto1; |
---|
22 | |
---|
23 | Image vihukuva2 = LoadImage("vihu2"); |
---|
24 | //Shape vihumuoto2; |
---|
25 | |
---|
26 | Image vihukuva3 = LoadImage("vihu3"); |
---|
27 | Shape vihumuoto3; |
---|
28 | |
---|
29 | Image vihukuva4 = LoadImage("vihu4"); |
---|
30 | Shape vihumuoto4; |
---|
31 | |
---|
32 | public override void Begin() |
---|
33 | { |
---|
34 | |
---|
35 | alusmuoto = Shape.FromImage(aluskuva); |
---|
36 | |
---|
37 | vihumuoto1 = Shape.FromImage(vihukuva1); |
---|
38 | |
---|
39 | //vihumuoto2 = Shape.FromImage(vihukuva2); |
---|
40 | |
---|
41 | vihumuoto3 = Shape.FromImage(vihukuva3); |
---|
42 | |
---|
43 | vihumuoto4 = Shape.FromImage(vihukuva4); |
---|
44 | |
---|
45 | luokentta(); |
---|
46 | asetaohjaimet(); |
---|
47 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "poistu"); |
---|
48 | luovihu1(); |
---|
49 | luovihu2(); |
---|
50 | luovihu3(); |
---|
51 | luovihu4(); |
---|
52 | |
---|
53 | } |
---|
54 | void luokentta() |
---|
55 | { |
---|
56 | this.Level.Height = 3000; |
---|
57 | this.Level.Width = 3500; |
---|
58 | Level.CreateBorders(true); |
---|
59 | //Gravity = new Vector(0, -600); |
---|
60 | Level.CreateGround(10, 30, 100, Color.Brown); |
---|
61 | |
---|
62 | MediaPlayer.Play("Terra"); |
---|
63 | |
---|
64 | tausta(); |
---|
65 | Level.BackgroundColor = Color.Black; |
---|
66 | |
---|
67 | alus = new PhysicsObject(40, 50); |
---|
68 | Add(alus); |
---|
69 | alus.Restitution = 0; |
---|
70 | alus.LinearDamping = 0.95; |
---|
71 | alus.AngularDamping = 0.75; |
---|
72 | Camera.Follow(alus); |
---|
73 | Camera.StayInLevel = true; |
---|
74 | alus.Shape = alusmuoto; |
---|
75 | alus.Y = -1350; |
---|
76 | alus.X = 0; |
---|
77 | LaserGun laser = new LaserGun(10, 10); |
---|
78 | alus.Add(laser); |
---|
79 | alus.Image = aluskuva; |
---|
80 | |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | void luovihu1() |
---|
85 | { |
---|
86 | vihu1 = new PhysicsObject(30, 50); |
---|
87 | Add(vihu1); |
---|
88 | vihu1.Color = Color.Red; |
---|
89 | vihu1.Restitution = 0; |
---|
90 | vihu1.LinearDamping = 0.95; |
---|
91 | vihu1.AngularDamping = 0.75; |
---|
92 | vihu1.Image = vihukuva1; |
---|
93 | vihu1.Shape = vihumuoto1; |
---|
94 | vihu1.Y = 1350; |
---|
95 | vihu1.X = 0; |
---|
96 | FollowerBrain aivo1 = new FollowerBrain(); |
---|
97 | aivo1.Active = true; |
---|
98 | aivo1.Target = alus; |
---|
99 | aivo1.Speed = 400; |
---|
100 | aivo1.TargetFollowDistance = 15000; |
---|
101 | //aivo1.TargetCloseDistance = 10; |
---|
102 | //aivo1.StopWhenTargetClose = true; |
---|
103 | vihu1.Brain = aivo1; |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | void luovihu2() |
---|
108 | { |
---|
109 | vihu2 = new PhysicsObject(50, 50); |
---|
110 | Add(vihu2); |
---|
111 | vihu2.Shape = Shape.Circle; |
---|
112 | vihu2.Restitution = 0; |
---|
113 | vihu2.LinearDamping = 0.95; |
---|
114 | vihu2.AngularDamping = 0.75; |
---|
115 | vihu2.Image = vihukuva2; |
---|
116 | //vihu2.Shape = vihumuoto2; |
---|
117 | vihu2.Y = 1000; |
---|
118 | vihu2.X = 0; |
---|
119 | FollowerBrain aivo1 = new FollowerBrain(); |
---|
120 | aivo1.Active = true; |
---|
121 | aivo1.Target = alus; |
---|
122 | aivo1.Speed = 400; |
---|
123 | aivo1.TargetFollowDistance = 15000; |
---|
124 | //aivo1.TargetCloseDistance = 500; |
---|
125 | //aivo1.StopWhenTargetClose = true; |
---|
126 | vihu2.Brain = aivo1; |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | void luovihu3() |
---|
132 | { |
---|
133 | vihu3 = new PhysicsObject(30, 50); |
---|
134 | Add(vihu3); |
---|
135 | //vihu3.Shape = Shape.Circle; |
---|
136 | vihu3.Restitution = 0; |
---|
137 | vihu3.LinearDamping = 0.95; |
---|
138 | vihu3.AngularDamping = 0.75; |
---|
139 | vihu3.Image = vihukuva3; |
---|
140 | vihu3.Shape = vihumuoto3; |
---|
141 | vihu3.Y = 1200; |
---|
142 | vihu3.X = 0; |
---|
143 | FollowerBrain aivo1 = new FollowerBrain(); |
---|
144 | aivo1.Active = true; |
---|
145 | aivo1.Target = alus; |
---|
146 | aivo1.Speed = 400; |
---|
147 | aivo1.TargetFollowDistance = 15000; |
---|
148 | //aivo1.TargetCloseDistance = 10; |
---|
149 | //aivo1.StopWhenTargetClose = true; |
---|
150 | vihu3.Brain = aivo1; |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | void luovihu4() |
---|
155 | { |
---|
156 | vihu4 = new PhysicsObject(250, 600); |
---|
157 | Add(vihu4); |
---|
158 | vihu4.Color = Color.Red; |
---|
159 | vihu4.Restitution = 0; |
---|
160 | vihu4.LinearDamping = 0.55; |
---|
161 | vihu4.AngularDamping = 0.75; |
---|
162 | vihu4.Image = vihukuva4; |
---|
163 | vihu4.Shape = vihumuoto4; |
---|
164 | vihu4.Mass = 2000; |
---|
165 | vihu4.Y = 1000; |
---|
166 | vihu4.X = 1000; |
---|
167 | RandomMoverBrain randomaivo = new RandomMoverBrain(); |
---|
168 | randomaivo.Active = true; |
---|
169 | randomaivo.ChangeMovementSeconds = 10; |
---|
170 | randomaivo.Speed = 15000; |
---|
171 | vihu4.Brain = randomaivo; |
---|
172 | |
---|
173 | |
---|
174 | } |
---|
175 | |
---|
176 | void tausta() |
---|
177 | { |
---|
178 | |
---|
179 | for (int i = 0; i < 1100; i++) |
---|
180 | { |
---|
181 | GameObject tahti = new GameObject(3, 3); |
---|
182 | tahti.Shape = Shape.Star; |
---|
183 | Add(tahti, -3); |
---|
184 | tahti.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); |
---|
185 | tahti.X = RandomGen.NextDouble(Level.Left, Level.Right); |
---|
186 | GetLayer(-3).RelativeTransition = new Vector(0.5, 0.5); |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | } |
---|
191 | |
---|
192 | void kaasu() |
---|
193 | { |
---|
194 | Vector voima = new Vector(); |
---|
195 | voima = Vector.FromLengthAndAngle(2200, alus.Angle - Angle.FromDegrees(-90)); |
---|
196 | alus.Push(voima); |
---|
197 | |
---|
198 | } |
---|
199 | void pyoroik() |
---|
200 | { |
---|
201 | alus.AngularVelocity = -4; |
---|
202 | } |
---|
203 | |
---|
204 | void pyorvas() |
---|
205 | { |
---|
206 | alus.AngularVelocity = 4; |
---|
207 | } |
---|
208 | |
---|
209 | void asetaohjaimet() |
---|
210 | { |
---|
211 | Keyboard.Listen(Key.Up, ButtonState.Down, kaasu, null); |
---|
212 | Keyboard.Listen(Key.W, ButtonState.Down, kaasu, null); |
---|
213 | Keyboard.Listen(Key.Right, ButtonState.Down, pyoroik, null); |
---|
214 | Keyboard.Listen(Key.D, ButtonState.Down, pyoroik, null); |
---|
215 | Keyboard.Listen(Key.Left, ButtonState.Down, pyorvas, null); |
---|
216 | Keyboard.Listen(Key.A, ButtonState.Down, pyorvas, null); |
---|
217 | |
---|
218 | |
---|
219 | } |
---|
220 | |
---|
221 | protected override void Update(Time time) |
---|
222 | { |
---|
223 | vihu1.Angle = vihu1.Velocity.Angle + Angle.FromDegrees(-90); |
---|
224 | vihu2.Angle = vihu2.Velocity.Angle + Angle.FromDegrees(-90); |
---|
225 | vihu3.Angle = vihu3.Velocity.Angle + Angle.FromDegrees(-90); |
---|
226 | vihu4.Angle = vihu4.Velocity.Angle + Angle.FromDegrees(-90); |
---|
227 | |
---|
228 | base.Update(time); |
---|
229 | } |
---|
230 | |
---|
231 | } |
---|