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 Test : PhysicsGame |
---|
10 | { |
---|
11 | PlatformCharacter Pelaaja1; |
---|
12 | PlatformCharacter Pelaaja2; |
---|
13 | |
---|
14 | private Image[] Animaatio = LoadImages("Abina", "Abinaa"); |
---|
15 | private Image[] Animaatio2 = LoadImages("Pelaaja2", "Pelaaja2a"); |
---|
16 | |
---|
17 | public override void Begin() |
---|
18 | { |
---|
19 | LuoKenttä(); |
---|
20 | |
---|
21 | Gravity = new Vector(0, -500); |
---|
22 | |
---|
23 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, Pelaaja1, -100.0); |
---|
24 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, Pelaaja1, 100.0); |
---|
25 | Keyboard.Listen(Key.Up, ButtonState.Down, Hyppää, null, Pelaaja1, 250.0); |
---|
26 | |
---|
27 | Keyboard.Listen(Key.A, ButtonState.Down, LiikutaPelaajaa, null, Pelaaja2, -100.0); |
---|
28 | Keyboard.Listen(Key.D, ButtonState.Down, LiikutaPelaajaa, null, Pelaaja2, 100.0); |
---|
29 | Keyboard.Listen(Key.W, ButtonState.Down, Hyppää, null, Pelaaja2, 250.0); |
---|
30 | |
---|
31 | Level.CreateBorders(); |
---|
32 | SmoothTextures = true; |
---|
33 | |
---|
34 | Pelaaja1.Restitution = 1.0; |
---|
35 | Pelaaja1.Restitution = 1.0; |
---|
36 | |
---|
37 | GameObject tausta = new GameObject(Level.Width, Level.Height); |
---|
38 | tausta.Image = LoadImage("Tausta"); |
---|
39 | Add(tausta, -3); |
---|
40 | |
---|
41 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
42 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
43 | |
---|
44 | Camera.Follow(Pelaaja1, Pelaaja2); |
---|
45 | Camera.StayInLevel = true; |
---|
46 | Camera.FollowXMargin = 600; |
---|
47 | Camera.FollowYMargin = 200; |
---|
48 | } |
---|
49 | |
---|
50 | void LuoKenttä() |
---|
51 | { |
---|
52 | ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Kenttä"); |
---|
53 | ruudut.SetTileMethod(Color.Red, LuoPelaaja); |
---|
54 | ruudut.SetTileMethod(Color.Black, LuoTaso); |
---|
55 | ruudut.SetTileMethod(Color.Blue, LuoLiekki); |
---|
56 | ruudut.SetTileMethod(Color.White, LuoValo); |
---|
57 | ruudut.Execute(40, 40); |
---|
58 | } |
---|
59 | |
---|
60 | void LuoPelaaja(Vector paikka, double leveys, double korkeus) |
---|
61 | { |
---|
62 | Pelaaja1 = new PlatformCharacter(leveys * 0.9, korkeus * 0.9); |
---|
63 | |
---|
64 | Pelaaja1.Position = paikka; |
---|
65 | |
---|
66 | Add(Pelaaja1); |
---|
67 | Pelaaja1.Shape = Shape.Circle; |
---|
68 | Image olionKuva = LoadImage("Abina"); |
---|
69 | Pelaaja1.Image = olionKuva; |
---|
70 | |
---|
71 | Pelaaja2 = new PlatformCharacter(leveys * 0.9, korkeus * 0.9); |
---|
72 | Add(Pelaaja2); |
---|
73 | Pelaaja2.Position = paikka; |
---|
74 | Pelaaja2.Shape = Shape.Circle; |
---|
75 | Pelaaja2.Image = LoadImage("pelaaja2"); |
---|
76 | |
---|
77 | Pelaaja1.AnimWalk = new Animation(Animaatio); |
---|
78 | Pelaaja1.AnimIdle = new Animation(Animaatio[0]); |
---|
79 | |
---|
80 | Pelaaja2.AnimWalk = new Animation(Animaatio2) { FPS = 5 }; |
---|
81 | Pelaaja2.AnimIdle = new Animation(Animaatio2[0]); |
---|
82 | |
---|
83 | Pelaaja1.Animation = new Animation(Animaatio); |
---|
84 | Pelaaja2.Animation = new Animation(Animaatio2); |
---|
85 | |
---|
86 | Pelaaja1.CollisionIgnoreGroup = 100; |
---|
87 | Pelaaja2.CollisionIgnoreGroup = 100; |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | void LuoTaso(Vector paikka, double leveys, double korkeus) |
---|
94 | { |
---|
95 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
96 | taso.Position = paikka; |
---|
97 | taso.CollisionIgnoreGroup = 1; |
---|
98 | taso.Image = LoadImage("Maa"); |
---|
99 | Add(taso); |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | void LiikutaPelaajaa(PlatformCharacter pelaaja, double nopeus) |
---|
105 | { |
---|
106 | pelaaja.Walk(nopeus); |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | void Hyppää(PlatformCharacter pelaaja, double nopeus) |
---|
111 | { |
---|
112 | pelaaja.Jump(nopeus); |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | void LuoLiekki(Vector paikka, double leveys, double korkeus) |
---|
118 | { |
---|
119 | Flame liekki = new Flame(LoadImage("Flame")); |
---|
120 | liekki.Position = paikka; |
---|
121 | liekki.MaxLifetime = 3; |
---|
122 | liekki.MaxScale = 100; |
---|
123 | Add(liekki); |
---|
124 | |
---|
125 | //int pMaxMaara = 50; |
---|
126 | |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | void LuoValo(Vector paikka, double leveys, double korkeus) |
---|
131 | { |
---|
132 | |
---|
133 | Level.AmbientLight = 0.8; |
---|
134 | |
---|
135 | // Light valo = new Light(); |
---|
136 | // valo.Intensity = 0.8; |
---|
137 | // valo.Distance = 150; |
---|
138 | // valo.Position = paikka; |
---|
139 | // Add(valo); |
---|
140 | } |
---|
141 | |
---|
142 | void TaustaMusiikki() |
---|
143 | { |
---|
144 | MediaPlayer.PlayFromURL("https://www.youtube.com/watch?v=_rJMbTvUt6w"); |
---|
145 | MediaPlayer.IsRepeating = true; |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|