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 FysiikkaPeli1 : PhysicsGame |
---|
10 | { |
---|
11 | Image kenttaKuva = LoadImage("Kentta"); |
---|
12 | Image Pahankuva = LoadImage("Pahis"); |
---|
13 | Pelaaja OlioH; |
---|
14 | SoundEffect NamAani = LoadSoundEffect("BOING1"); |
---|
15 | IntMeter PisteLaskuri; |
---|
16 | Image taustakuva = LoadImage("Voittokuva"); |
---|
17 | |
---|
18 | public override void Begin() |
---|
19 | { |
---|
20 | Luokenttä(); |
---|
21 | SmoothTextures = false; |
---|
22 | Mouse.IsCursorVisible = true; |
---|
23 | LuoOhjaimet(); |
---|
24 | |
---|
25 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
26 | Camera.ZoomToLevel(); |
---|
27 | |
---|
28 | } |
---|
29 | void Luokenttä() |
---|
30 | { |
---|
31 | ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Kentta"); |
---|
32 | |
---|
33 | ruudut.SetTileMethod(Color.Gold, LuoOlioH); |
---|
34 | ruudut.SetTileMethod(Color.Black, LuoTaso); |
---|
35 | ruudut.SetTileMethod(Color.Red, LuoOlioP); |
---|
36 | ruudut.SetTileMethod(Color.Rose, LuoHerkut); |
---|
37 | |
---|
38 | ruudut.Execute(50, 50); |
---|
39 | |
---|
40 | Level.Background.Color = Color.White; |
---|
41 | |
---|
42 | Label pisteNaytto = new Label(); |
---|
43 | pisteNaytto.X = Screen.Left + 100; |
---|
44 | pisteNaytto.Y = Screen.Top - 100; |
---|
45 | pisteNaytto.TextColor = Color.Black; |
---|
46 | pisteNaytto.Color = Color.White; |
---|
47 | |
---|
48 | pisteNaytto.BindTo(OlioH.ElamaLaskuri); |
---|
49 | Add(pisteNaytto); |
---|
50 | |
---|
51 | PisteLaskuri = new IntMeter(0); |
---|
52 | |
---|
53 | Label pisteNaytto2 = new Label(); |
---|
54 | pisteNaytto2.X = Screen.Right - 100; |
---|
55 | pisteNaytto2.Y = Screen.Top - 100; |
---|
56 | pisteNaytto2.TextColor = Color.Black; |
---|
57 | pisteNaytto2.Color = Color.White; |
---|
58 | |
---|
59 | pisteNaytto2.BindTo(PisteLaskuri); |
---|
60 | Add(pisteNaytto2); |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | } |
---|
65 | void LuoOlioH(Vector paikka, double leveys, double korkeus) |
---|
66 | { |
---|
67 | OlioH = new Pelaaja(leveys, korkeus); |
---|
68 | OlioH.Position = paikka; |
---|
69 | AddCollisionHandler(OlioH, "Pahis", TormaaVihuun); |
---|
70 | Add(OlioH); |
---|
71 | OlioH.Color = Color.Gold; |
---|
72 | OlioH.Shape = Shape.Circle; |
---|
73 | |
---|
74 | AddCollisionHandler(OlioH, "Herkku", OlioSyo); |
---|
75 | } |
---|
76 | void TormaaVihuun(PhysicsObject Tormaaja,PhysicsObject KukaTormaa) |
---|
77 | { |
---|
78 | Pelaaja P = (Pelaaja)Tormaaja; |
---|
79 | P.ElamaLaskuri.AddValue(-1); |
---|
80 | MessageDisplay.Add ("Auts!!!"); |
---|
81 | } |
---|
82 | void LuoTaso(Vector paikka, double leveys, double korkeus) |
---|
83 | { |
---|
84 | PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
85 | seina.Position = paikka; |
---|
86 | seina.Color = Color.Black; |
---|
87 | seina.CollisionIgnoreGroup = 1; |
---|
88 | Add(seina); |
---|
89 | seina.Tag = "Seina"; |
---|
90 | } |
---|
91 | void LuoHerkut(Vector paikka, double leveys, double korkeus) |
---|
92 | { |
---|
93 | PhysicsObject Herkku = new PhysicsObject(20.0, 20.0); |
---|
94 | Add(Herkku); |
---|
95 | Herkku.Shape = Shape.Circle; |
---|
96 | Herkku.Color = Color.LimeGreen; |
---|
97 | Herkku.Position = paikka; |
---|
98 | Herkku.Tag = "Herkku"; |
---|
99 | } |
---|
100 | void OlioSyo(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
101 | { |
---|
102 | //NamAani.Play(); |
---|
103 | kohde.Destroy(); |
---|
104 | PisteLaskuri.AddValue(1); |
---|
105 | if (PisteLaskuri.Value == 28) |
---|
106 | { |
---|
107 | MessageDisplay.Add("Jeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee Voitit :3"); |
---|
108 | //Level.Background.Image = taustakuva; |
---|
109 | |
---|
110 | //Level.Background.ScaleToLevelByHeight(); |
---|
111 | //IsPaused |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | } |
---|
116 | void LuoOlioP(Vector paikka, double leveys, double korkeus) |
---|
117 | { |
---|
118 | PhysicsObject OlioP = new PhysicsObject(leveys, korkeus); |
---|
119 | OlioP.IgnoresCollisionResponse = true; |
---|
120 | OlioP.Position = paikka; |
---|
121 | OlioP.Tag = "Pahis"; |
---|
122 | Add(OlioP, 1); |
---|
123 | OlioP.Color = Color.Red; |
---|
124 | OlioP.Shape = Shape.Circle; |
---|
125 | |
---|
126 | LabyrinthWandererBrain tekoaivot = new LabyrinthWandererBrain(50.0, 150.0, "Seina"); |
---|
127 | OlioP.Brain = tekoaivot; |
---|
128 | tekoaivot.Active = true; |
---|
129 | |
---|
130 | //PathFollowerBrain polkuAivot = new PathFollowerBrain(100); |
---|
131 | |
---|
132 | // OlioP.Brain = polkuAivot; |
---|
133 | |
---|
134 | // polkuAivot.Active = true; |
---|
135 | // polkuAivot.TurnWhileMoving = true; |
---|
136 | // polkuAivot.Speed = 150; |
---|
137 | |
---|
138 | //List<Vector> polku = new List<Vector>(); |
---|
139 | |
---|
140 | //polku.Add(new Vector(0.0, 0.0)); |
---|
141 | //polku.Add(new Vector(-300, 0.0)); |
---|
142 | //polku.Add(new Vector(-300, 350)); |
---|
143 | //polku.Add(new Vector(50, 350)); |
---|
144 | //polku.Add(new Vector(50, -10)); |
---|
145 | //polku.Add(new Vector(-30, 0.0)); |
---|
146 | //polku.Add(new Vector(-30, -150)); |
---|
147 | //polku.Add(new Vector(215, -150)); |
---|
148 | //polku.Add(new Vector(215, 500)); |
---|
149 | //polku.Add(new Vector(-450, 500)); |
---|
150 | //polku.Add(new Vector(-450, 70)); |
---|
151 | //polku.Add(new Vector(-280, 70)); |
---|
152 | //polku.Add(new Vector(-280, 350)); |
---|
153 | //polku.Add(new Vector(35, 350)); |
---|
154 | //polku.Add(new Vector(35, 270)); |
---|
155 | //polku.Add(new Vector(200, 270)); |
---|
156 | //polku.Add(new Vector(200, -150)); |
---|
157 | //polku.Add(new Vector(-450, -150)); |
---|
158 | //polku.Add(new Vector(-450, 500)); |
---|
159 | //polku.Add(new Vector(-215, 500)); |
---|
160 | //polku.Add(new Vector(-215, 350)); |
---|
161 | //polku.Add(new Vector(-120, 350)); |
---|
162 | //polku.Add(new Vector(-120, 0.0)); |
---|
163 | |
---|
164 | //polkuAivot.Path = polku; |
---|
165 | //polkuAivot.Loop = true; |
---|
166 | |
---|
167 | } |
---|
168 | void LuoOhjaimet() |
---|
169 | { |
---|
170 | Keyboard.Listen(Key.Left, ButtonState.Down, |
---|
171 | LiikutaPelaajaa, null, new Vector(-29000, 0)); |
---|
172 | Keyboard.Listen(Key.Right, ButtonState.Down, |
---|
173 | LiikutaPelaajaa, null, new Vector(29000, 0)); |
---|
174 | Keyboard.Listen(Key.Up, ButtonState.Down, |
---|
175 | LiikutaPelaajaa, null, new Vector(0, 2000)); |
---|
176 | Keyboard.Listen(Key.Down, ButtonState.Down, |
---|
177 | LiikutaPelaajaa, null, new Vector(0, -2000)); |
---|
178 | |
---|
179 | } |
---|
180 | void LiikutaPelaajaa(Vector vektori) |
---|
181 | { |
---|
182 | OlioH.Push(vektori); |
---|
183 | } |
---|
184 | |
---|
185 | } |
---|
186 | class Pelaaja : PlatformCharacter |
---|
187 | { |
---|
188 | |
---|
189 | public int Elamat { get; set; } |
---|
190 | |
---|
191 | private IntMeter elamaLaskuri = new IntMeter(3, 0, 3); |
---|
192 | public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } |
---|
193 | |
---|
194 | public Pelaaja(double leveys, double korkeus) |
---|
195 | : base(leveys, korkeus) |
---|
196 | { |
---|
197 | elamaLaskuri.LowerLimit += delegate |
---|
198 | { |
---|
199 | this.Destroy(); }; |
---|
200 | } |
---|
201 | } |
---|