source: 2017/24/IlariI/piXgel GAmE/piXgel GAmE/piXgel_GAmE/piXgel_GAmE.cs @ 8769

Revision 8769, 8.4 KB checked in by npo17_10, 6 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class piXgel_GAmE : PhysicsGame
10{
11    AssaultRifle hahmonase;
12
13    Image hahmonkuva = LoadImage("hahmo");
14    Image hahmonkuvavasemmalle = LoadImage("hahmovasemmalle");
15    Image hahmonkuvatakaa = LoadImage("hahmotakaa");
16    Image hahmonkuvaoikealle = LoadImage("hahmooikealle");
17    Image vihollinenkuva = LoadImage("vihollinen");
18
19    Image[] hahmonKavely = LoadImages("hahmo", "hahmo2");
20    Image[] hahmo2Kavely = LoadImages("hahmovasemmalle", "hahmovasemmalle2");
21    Image[] hahmo3kavely = LoadImages("hahmooikealle", "hahmooikealle2");
22    Image[] hahmo4kavely = LoadImages("hahmotakaa", "hahmotakaa2");
23
24    //Image[] hahmonKavely = LoadImages("hahmo", "hahmo2");
25    //Image[] hahmo2Kavely = LoadImages("hahmovasemmalle", "hahmovasemmalle2");
26    //Image[] hahmo3kavely = LoadImages("hahmooikealle", "hahmooikealle2");
27    //Image[] hahmo4kavely = LoadImages("hahmotakaa", "hahmotakaa2");
28
29
30
31
32
33    IntMeter pisteLaskuri;
34    PhysicsObject vihollinen;
35
36    PhysicsObject hahmo;
37    Vector nopeusVasemmalle = new Vector(-100.0, 0.0);
38    Vector nopeusOikealle = new Vector(100.0, 0.0);
39    Vector nopeusYlos = new Vector(0.0, 100.0);
40    Vector nopeusAlas = new Vector(0.0, -100.0);
41
42    Vector pysahtuuVasemmalle = new Vector(0.0, 0.0);
43    Vector pysahtuuOikealle = new Vector(0.0, 0.0);
44    Vector pysahtuuYlos = new Vector(0.0, 0.0);
45    Vector pysahtuuAlas = new Vector(0.0, 0.0);
46
47    public override void Begin()
48    {
49        hahmo = new PhysicsObject(30, 30);
50        hahmo.CanRotate = false;
51        hahmo.Restitution = 0.0;
52        hahmo.Image = hahmonkuva; 
53        hahmonase = new AssaultRifle(30, 10);
54        hahmonase.Image = null; 
55        SmoothTextures = false;
56        hahmonase.Color = Color.Transparent;
57        //hahmo.Animation = new Animation(hahmonKavely);
58        //hahmo.Animation.Start();
59        //hahmo.Animation.FPS = 10;
60       
61
62        hahmonase.ProjectileCollision = Ammusosui;
63        hahmo.Add(hahmonase);
64
65        Keyboard.Listen(Key.Space, ButtonState.Down, Ammuaseella, "Ammu", hahmonase);
66
67        LuoVihu();
68
69       
70
71
72
73
74        Luopistelaskuri();
75
76        Add(hahmo);
77
78        Timer vihollispawner = new Timer();
79        vihollispawner.Interval = 3.0;
80        vihollispawner.Timeout += LuoVihu;
81        vihollispawner.Start();
82
83       //Timer animoija = new Timer();
84       //animoija.Interval = 0.5;
85       //animoija.Timeout += Liikkuja;
86       //animoija.Start();
87
88
89        LuoKentta();
90        // TODO: Kirjoita ohjelmakoodisi tähän();
91
92        Keyboard.Listen(Key.Left, ButtonState.Down, KavelytaPelaajaa, null, nopeusVasemmalle);
93        Keyboard.Listen(Key.Right, ButtonState.Down, KavelytaPelaajaa, null, nopeusOikealle);
94        Keyboard.Listen(Key.Up, ButtonState.Down, KavelytaPelaajaa, null, nopeusYlos);
95        Keyboard.Listen(Key.Down, ButtonState.Down, KavelytaPelaajaa, null, nopeusAlas);
96
97        Keyboard.Listen(Key.Left, ButtonState.Released, KavelytaPelaajaa, null, pysahtuuVasemmalle);
98        Keyboard.Listen(Key.Right, ButtonState.Released, KavelytaPelaajaa, null, pysahtuuOikealle);
99        Keyboard.Listen(Key.Up, ButtonState.Released, KavelytaPelaajaa, null, pysahtuuYlos);
100        Keyboard.Listen(Key.Down, ButtonState.Released, KavelytaPelaajaa, null, pysahtuuAlas);
101
102
103        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
104        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
105
106
107    }
108
109   
110   
111     
112   
113    void Ajastin()
114    {
115        Timer aikaLaskuri = new Timer();
116        aikaLaskuri.Start();
117
118        Label aikaNaytto = new Label();
119        aikaNaytto.TextColor = Color.White;
120        aikaNaytto.DecimalPlaces = 1;
121        aikaNaytto.BindTo(aikaLaskuri.SecondCounter);
122        Add(aikaNaytto);
123
124    }
125
126    void Liikkuja()
127    {
128       
129    }
130
131    void LuoVihu()
132    {
133        PhysicsObject vihollinen = new PhysicsObject(40, 40);
134        vihollinen.CanRotate = false;
135        vihollinen.X = -300;
136        vihollinen.Y = -200;
137        vihollinen.Tag = "vihu";
138        vihollinen.Image = vihollinenkuva;
139        FollowerBrain seuraajanAivot = new FollowerBrain(hahmo);
140
141
142        vihollinen.Brain = seuraajanAivot;
143
144        seuraajanAivot.Speed = 80;
145        seuraajanAivot.DistanceFar = 6000;
146        seuraajanAivot.DistanceClose = 40;
147        seuraajanAivot.StopWhenTargetClose = true;
148
149
150        seuraajanAivot.TargetClose += KunPaaseeLahelle;
151
152        Add(vihollinen);
153     // .................................................................
154        PhysicsObject vihollinen2 = new PhysicsObject(40, 40);
155        vihollinen2.CanRotate = false;
156        vihollinen2.X = -0;
157        vihollinen2.Y =  300;
158        vihollinen2.Tag = "vihu";
159        vihollinen2.Image = vihollinenkuva;
160        FollowerBrain seuraajanAivot2 = new FollowerBrain(hahmo);
161
162
163        vihollinen2.Brain = seuraajanAivot2;
164
165        seuraajanAivot2.Speed = 80;
166        seuraajanAivot2.DistanceFar = 6000;
167        seuraajanAivot2.DistanceClose = 40;
168        seuraajanAivot2.StopWhenTargetClose = true;
169
170
171        seuraajanAivot2.TargetClose += KunPaaseeLahelle;
172
173        Add(vihollinen2);
174     //..........................................................................
175        PhysicsObject vihollinen3 = new PhysicsObject(40, 40);
176        vihollinen3.CanRotate = false;
177        vihollinen3.X = 300;
178        vihollinen3.Y = -200;
179        vihollinen3.Tag = "vihu";
180        vihollinen3.Image = vihollinenkuva;
181        FollowerBrain seuraajanAivot3 = new FollowerBrain(hahmo);
182
183
184        vihollinen3.Brain = seuraajanAivot3;
185
186        seuraajanAivot3.Speed = 80;
187        seuraajanAivot3.DistanceFar = 6000;
188        seuraajanAivot3.DistanceClose = 40;
189        seuraajanAivot3.StopWhenTargetClose = true;
190
191
192        seuraajanAivot3.TargetClose += KunPaaseeLahelle;
193
194        Add(vihollinen3);
195
196    }
197    void Luopistelaskuri()
198    {
199       pisteLaskuri = new IntMeter(0);
200     
201       Label pisteNaytto = new Label();
202       pisteNaytto.X = Screen.Left + 100;
203       pisteNaytto.Y = Screen.Top - 100;
204       pisteNaytto.TextColor = Color.White;
205       pisteNaytto.Color = Color.Black;
206     
207       pisteNaytto.BindTo(pisteLaskuri);
208       Add(pisteNaytto);
209     
210       if (Equals("vihu")) 
211       {
212           pisteLaskuri.Value += 1;
213       }
214       
215    }
216
217    void LuoKentta()
218    {
219
220
221        PhysicsObject ylareuna = Level.CreateTopBorder(0.0, true);
222        PhysicsObject alareuna = Level.CreateBottomBorder(0.0, true);
223        PhysicsObject vasenreuna = Level.CreateLeftBorder(0.0, true);
224        PhysicsObject oikeareuna = Level.CreateRightBorder(0.0, true);
225        //Level.CreateBorders(1.0, true);
226
227        Level.Background.Color = Color.Aqua;
228        Camera.Follow(hahmo);
229        Camera.Zoom(2.0);
230
231
232    }
233   
234    void Ammusosui(PhysicsObject ammus, PhysicsObject kohde)
235    {
236        ammus.Destroy();
237        if (kohde.Tag.Equals("vihu"))
238        {
239            kohde.Destroy();
240        }
241       
242    }
243
244    void Ammuaseella(AssaultRifle ase)
245    {
246        PhysicsObject ammus = ase.Shoot();
247
248        if (ammus != null)
249        {
250            ammus.Size *= 0.5;
251
252            ammus.MaximumLifetime = TimeSpan.FromSeconds(2.0);
253        }
254    }
255    void KunPaaseeLahelle()
256    {
257        hahmo.Destroy();
258       
259    }
260    void KavelytaPelaajaa(Vector suunta)
261    {
262        hahmo.Velocity = suunta;
263        if (suunta.X < 0)
264        {
265            hahmonase.Angle = Angle.FromDegrees(180.0);
266            hahmo.Image = hahmonkuvavasemmalle; hahmo.Animation = new Animation(hahmo2Kavely);
267        }
268        if (suunta.X > 0)
269        {
270            hahmonase.Angle = Angle.FromDegrees(0.0);
271            hahmo.Image = hahmonkuvaoikealle; hahmo.Animation = new Animation(hahmo3kavely);
272
273        }
274        if (suunta.Y > 0)
275        {
276            hahmonase.Angle = Angle.FromDegrees(90.0);
277            hahmo.Image = hahmonkuvatakaa; hahmo.Animation = new Animation(hahmo4kavely);
278
279        }
280        if (suunta.Y < 0)
281        {
282            hahmonase.Angle = Angle.FromDegrees(270.0);
283            hahmo.Image = hahmonkuva; hahmo.Animation = new Animation(hahmonKavely);
284        }
285
286       
287       
288           
289       
290
291    }
292}
Note: See TracBrowser for help on using the repository browser.