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 Water_wey : PhysicsGame |
---|
10 | { |
---|
11 | //------------------------------------------------------------- PhysicsObject |
---|
12 | PhysicsObject vesi; |
---|
13 | PhysicsObject pelaaja; |
---|
14 | PhysicsObject pelaaja2; |
---|
15 | double voima = 1000000; |
---|
16 | PhysicsObject kala; |
---|
17 | |
---|
18 | public override void Begin() |
---|
19 | { |
---|
20 | //PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
21 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli");//Confirm |
---|
22 | // Keyboard.Listen(Key.Right, ButtonState.Pressed, Gravity, new Vector(-100, 0); |
---|
23 | luopelaaja2(); |
---|
24 | luopelaaja(); |
---|
25 | loukala(); |
---|
26 | loukala(); |
---|
27 | lisaaohjaimet(); |
---|
28 | |
---|
29 | // Gravity = new Vector(0, -500); |
---|
30 | Level.CreateBorders(); |
---|
31 | IsFullScreen = true; |
---|
32 | Level.Background.Image = LoadImage("underwater"); |
---|
33 | Level.Background.FitToLevel(); |
---|
34 | Camera.ZoomToLevel(); |
---|
35 | |
---|
36 | int Laskuri = 0; |
---|
37 | |
---|
38 | while (Laskuri < 1000) |
---|
39 | { |
---|
40 | vesi = new PhysicsObject(25, 25); |
---|
41 | vesi.Shape = Shape.Circle; |
---|
42 | |
---|
43 | vesi.Color = new Color(0, 0, 100, 5); |
---|
44 | vesi.Mass = 0.5; |
---|
45 | vesi.X = RandomGen.NextDouble(Level.Left, Level.Right); |
---|
46 | vesi.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); |
---|
47 | Add(vesi); |
---|
48 | Laskuri++; |
---|
49 | } |
---|
50 | } |
---|
51 | //-----------------------------------------------------------------------Aliohjelmat |
---|
52 | void luopelaaja()//Vector paikka, double leveys, double korkeus |
---|
53 | { |
---|
54 | pelaaja = new PhysicsObject(100, 50); |
---|
55 | pelaaja.Shape = Shape.FromImage(LoadImage("KALA2")); |
---|
56 | pelaaja.Position = new Vector(-100, -100); |
---|
57 | pelaaja.Mass = 100; |
---|
58 | pelaaja.Image = LoadImage("KALA2"); |
---|
59 | //(pelaaja.Tag = "";) |
---|
60 | Add(pelaaja); |
---|
61 | |
---|
62 | |
---|
63 | // AddCollisionHandler(pelaaja, "palikka", PysaytaPelaaja); |
---|
64 | } |
---|
65 | void luopelaaja2()//Vector paikka, double leveys, double korkeus |
---|
66 | { |
---|
67 | pelaaja2 = new PhysicsObject(100, 50); |
---|
68 | pelaaja2.Shape = Shape.FromImage(LoadImage("KALA2")); |
---|
69 | pelaaja2.Position = new Vector(-100, 100); |
---|
70 | pelaaja2.Mass = 100; |
---|
71 | pelaaja2.Image = LoadImage("KALA2"); |
---|
72 | //(pelaaja.Tag = "";) |
---|
73 | Add(pelaaja2); |
---|
74 | |
---|
75 | |
---|
76 | // AddCollisionHandler(pelaaja, "palikka", PysaytaPelaaja); |
---|
77 | } |
---|
78 | void loukala() |
---|
79 | { |
---|
80 | double x = RandomGen.NextDouble(0.0, 500.0); |
---|
81 | double y = RandomGen.NextDouble(0.0, 300.0); |
---|
82 | |
---|
83 | kala = new PhysicsObject(100, 50); |
---|
84 | FollowerBrain seuraajanAivot = new FollowerBrain(pelaaja, pelaaja2); |
---|
85 | seuraajanAivot.TurnWhileMoving = true; |
---|
86 | kala.Brain = seuraajanAivot; |
---|
87 | seuraajanAivot.Speed = 200; |
---|
88 | kala.Mass = 50; |
---|
89 | kala.X = x; |
---|
90 | kala.Y = y; |
---|
91 | kala.Shape = Shape.FromImage(LoadImage("kala")); |
---|
92 | kala.Image = LoadImage("kala"); |
---|
93 | Add(kala); |
---|
94 | } |
---|
95 | |
---|
96 | //---------------------------------------------------------------Ohjaimet |
---|
97 | |
---|
98 | void lisaaohjaimet() |
---|
99 | { |
---|
100 | //-------------------------------------------------------------------------------------1 |
---|
101 | Keyboard.Listen(Key.Left, ButtonState.Down, kaannaPelaajaa, null, 4.0); |
---|
102 | Keyboard.Listen(Key.Left, ButtonState.Released, kaannaPelaajaa, null, 0.0); |
---|
103 | Keyboard.Listen(Key.Right, ButtonState.Down, kaannaPelaajaa, null, -4.0); |
---|
104 | Keyboard.Listen(Key.Right, ButtonState.Released, kaannaPelaajaa, null, -0.0); |
---|
105 | Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null ); |
---|
106 | //---------------------------------------------------------------------------------2 |
---|
107 | Keyboard.Listen(Key.A, ButtonState.Down, kaannaPelaajaa2, null, 4.0); |
---|
108 | Keyboard.Listen(Key.A, ButtonState.Released, kaannaPelaajaa2, null, 0.0); |
---|
109 | Keyboard.Listen(Key.D, ButtonState.Down, kaannaPelaajaa2, null, -4.0); |
---|
110 | Keyboard.Listen(Key.D, ButtonState.Released, kaannaPelaajaa2, null, -0.0); |
---|
111 | Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaajaa2, null); |
---|
112 | //Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaPelaajaa, null, new Vector(0, -voima)); |
---|
113 | |
---|
114 | //Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelaajaX, null); |
---|
115 | //Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelaajaX, null); |
---|
116 | //Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaPelaajaY, null); |
---|
117 | //Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaPelaajaY, null); |
---|
118 | } |
---|
119 | void kaannaPelaajaa(double nopeus) |
---|
120 | { |
---|
121 | pelaaja.AngularVelocity = nopeus; |
---|
122 | } |
---|
123 | void LiikutaPelaajaa() |
---|
124 | { |
---|
125 | Vector pelaajanSuunta = Vector.FromLengthAndAngle(50000.0, pelaaja.Angle); |
---|
126 | pelaaja.Push(pelaajanSuunta); |
---|
127 | } |
---|
128 | |
---|
129 | void kaannaPelaajaa2(double nopeus) |
---|
130 | { |
---|
131 | pelaaja2.AngularVelocity = nopeus; |
---|
132 | } |
---|
133 | void LiikutaPelaajaa2() |
---|
134 | { |
---|
135 | Vector pelaajanSuunta2 = Vector.FromLengthAndAngle(50000.0, pelaaja2.Angle); |
---|
136 | pelaaja2.Push(pelaajanSuunta2); |
---|
137 | } |
---|
138 | //------------------------------------------------------------- |
---|
139 | |
---|
140 | |
---|
141 | } |
---|