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 NinjaInTheDarkLight : PhysicsGame |
---|
10 | { |
---|
11 | Image ninjankuva = LoadImage("ninja"); |
---|
12 | Image ninjahyppykuva = LoadImage("ninjahyppy"); |
---|
13 | |
---|
14 | Vector nopeusOikealle = new Vector(1000, 0); |
---|
15 | Vector nopeusVasemmalle = new Vector(-1000, 0); |
---|
16 | |
---|
17 | PhysicsObject demoni; |
---|
18 | PlatformCharacter ninja; |
---|
19 | PhysicsObject lattia; |
---|
20 | PhysicsObject tappolattia; |
---|
21 | |
---|
22 | |
---|
23 | public override void Begin() |
---|
24 | { |
---|
25 | LuoNinja(); |
---|
26 | LuoDemoni(); |
---|
27 | LuoKentta(); |
---|
28 | AsetaOhjaimet(); |
---|
29 | |
---|
30 | Gravity = new Vector(0.0, -800.0); |
---|
31 | |
---|
32 | MultiSelectWindow valikko = new MultiSelectWindow("Ninja In The Dark Light", "Aloita peli", "Laulu 1", "Laulu 2", "Laulu 3", "Laulu 4", "Laulu 5", "Laulu 6", "Lopeta"); |
---|
33 | valikko.ItemSelected += PainettiinValikonNappia; |
---|
34 | valikko.Color = Color.Purple; |
---|
35 | Add(valikko); |
---|
36 | |
---|
37 | } |
---|
38 | void LuoNinja() |
---|
39 | { |
---|
40 | ninja = new PlatformCharacter(30, 50, Shape.Rectangle); |
---|
41 | ninja.Color = Color.Black; |
---|
42 | Add(ninja); |
---|
43 | ninja.X = Level.Left + 10.0; |
---|
44 | ninja.Y = Level.Bottom + 100.0; |
---|
45 | ninja.Restitution = 0.0; |
---|
46 | ninja.CanRotate = false; |
---|
47 | ninja.Tag = "pelaaja"; |
---|
48 | ninja.Image = ninjankuva; |
---|
49 | AddCollisionHandler(ninja, "vihu", PelaajaTormaa); |
---|
50 | AddCollisionHandler(ninja, "tappolattia", PelaajaTormaa); |
---|
51 | |
---|
52 | } |
---|
53 | void LuoDemoni() |
---|
54 | { |
---|
55 | demoni = new PhysicsObject(70, 70, Shape.Circle); |
---|
56 | demoni.Color = Color.BloodRed; |
---|
57 | Add(demoni); |
---|
58 | demoni.X = Level.Right + 5.0; |
---|
59 | demoni.Y = 0; |
---|
60 | Vector impulssi = new Vector(-350.0, 0.0); |
---|
61 | demoni.Hit(impulssi); |
---|
62 | demoni.Restitution = 100.0; |
---|
63 | demoni.IgnoresGravity = true; |
---|
64 | RandomMoverBrain satunnaisAivot = new RandomMoverBrain(350); |
---|
65 | satunnaisAivot.ChangeMovementSeconds = 1; |
---|
66 | demoni.Brain = satunnaisAivot; |
---|
67 | demoni.Tag = "vihu"; |
---|
68 | |
---|
69 | } |
---|
70 | void LuoKentta() |
---|
71 | { |
---|
72 | Level.CreateLeftBorder(0.0, true); |
---|
73 | Level.CreateRightBorder(0.0, true); |
---|
74 | Level.CreateTopBorder(0.0, true); |
---|
75 | tappolattia = Level.CreateBottomBorder(0.0, true); |
---|
76 | tappolattia.Tag = "tappolattia"; |
---|
77 | tappolattia.Color = Color.Red; |
---|
78 | tappolattia.Y = Level.Bottom - 25; |
---|
79 | lattia = LuoLattia(); |
---|
80 | Level.Background.Color = Color.SkyBlue; |
---|
81 | } |
---|
82 | void AsetaOhjaimet() |
---|
83 | { |
---|
84 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
85 | Keyboard.Listen(Key.D, ButtonState.Down, AsetaNopeus, "Liiku oikealle", ninja, nopeusOikealle); |
---|
86 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Liiku oikealle", ninja, nopeusVasemmalle); |
---|
87 | Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pysäytä peli"); |
---|
88 | Keyboard.Listen(Key.Space, ButtonState.Pressed, Hyppy, "Hyppää", ninja, 550.0); |
---|
89 | Keyboard.Listen(Key.L, ButtonState.Down, SyoksyS, "Syöksy sivulle", ninja, 2000.0); |
---|
90 | Keyboard.Listen(Key.S, ButtonState.Down, SyoksyA, "Syöksy alas", ninja, 750.0); |
---|
91 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
92 | } |
---|
93 | void AsetaNopeus(PlatformCharacter ninja, Vector nopeus) |
---|
94 | { |
---|
95 | ninja.Walk(nopeus.X); |
---|
96 | } |
---|
97 | void PelaajaTormaa(PhysicsObject pelaaja, PhysicsObject pahis) |
---|
98 | { |
---|
99 | pelaaja.Destroy(); |
---|
100 | MessageDisplay.Add("SINÄ KUOLIT"); |
---|
101 | MediaPlayer.Play("Determination"); |
---|
102 | } |
---|
103 | void Hyppy(PlatformCharacter ninja, Double nopeus) |
---|
104 | { |
---|
105 | ninja.ForceJump(nopeus); |
---|
106 | if (lattia != null) |
---|
107 | { |
---|
108 | lattia.Destroy(); |
---|
109 | } |
---|
110 | //Hyppy.Image = ninjahyppykuva; |
---|
111 | } |
---|
112 | void PainettiinValikonNappia(int valinta) |
---|
113 | { |
---|
114 | switch (valinta) |
---|
115 | { |
---|
116 | case 0: |
---|
117 | //AloitaPeli |
---|
118 | break; |
---|
119 | case 1: |
---|
120 | //Laulu 1 |
---|
121 | MediaPlayer.Play("Core"); |
---|
122 | MediaPlayer.IsRepeating = true; |
---|
123 | break; |
---|
124 | case 2: |
---|
125 | //Laulu 2 |
---|
126 | MediaPlayer.Play("DatingF"); |
---|
127 | MediaPlayer.IsRepeating = true; |
---|
128 | break; |
---|
129 | case 3: |
---|
130 | //Laulu 3 |
---|
131 | MediaPlayer.Play("Dummy"); |
---|
132 | MediaPlayer.IsRepeating = true; |
---|
133 | break; |
---|
134 | case 4: |
---|
135 | //Laulu 4 |
---|
136 | MediaPlayer.Play("EnemyA"); |
---|
137 | MediaPlayer.IsRepeating = true; |
---|
138 | break; |
---|
139 | case 5: |
---|
140 | //Laulu5 |
---|
141 | MediaPlayer.Play("Neo"); |
---|
142 | MediaPlayer.IsRepeating = true; |
---|
143 | break; |
---|
144 | case 6: |
---|
145 | //laulu6 |
---|
146 | MediaPlayer.Play("Stronger"); |
---|
147 | MediaPlayer.IsRepeating = true; |
---|
148 | break; |
---|
149 | case 7: |
---|
150 | Exit(); |
---|
151 | break; |
---|
152 | } |
---|
153 | } |
---|
154 | void SyoksyS(PlatformCharacter ninja, double nopeus) |
---|
155 | { |
---|
156 | ninja.Walk(ninja.FacingDirection.GetVector().Normalize().X * nopeus); |
---|
157 | } |
---|
158 | void SyoksyA(PlatformCharacter ninja, double nopeus) |
---|
159 | { |
---|
160 | Vector impullsi = new Vector(0.0, -nopeus); |
---|
161 | ninja.Hit(impullsi); |
---|
162 | } |
---|
163 | PhysicsObject LuoLattia() |
---|
164 | { |
---|
165 | PhysicsObject lattia = PhysicsObject.CreateStaticObject(Level.Width, 50.0); |
---|
166 | lattia.Y = Level.Bottom + 5.0; |
---|
167 | Add(lattia); |
---|
168 | return lattia; |
---|
169 | } |
---|
170 | } |
---|