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 Peli : PhysicsGame |
---|
10 | { |
---|
11 | Vector nopeusYlos = new Vector(0, 200); |
---|
12 | Vector nopeusAlas = new Vector(0, -200); |
---|
13 | Vector nopeusStop = new Vector(0, 0); |
---|
14 | Vector nopeusVasen = new Vector(-200, 0); |
---|
15 | Vector nopeusOikea = new Vector(200, 0); |
---|
16 | Vector viholinen = new Vector(); |
---|
17 | |
---|
18 | PhysicsObject Miner; |
---|
19 | Image olionKuva = LoadImage("player 1 standing"); |
---|
20 | Image[] KavelyKuvat = LoadImages("player 1" , "player 1 frame2"); |
---|
21 | |
---|
22 | Image[] zombiekavelykuvat = LoadImages("zombie animatio osa 1", "zombie animatio osa 2"); |
---|
23 | Image olionKuva1 = LoadImage("zombie seiso"); |
---|
24 | |
---|
25 | Image[] KavelyKuvatPeilattu; |
---|
26 | public override void Begin() |
---|
27 | { |
---|
28 | TileMap ruudut = TileMap.FromLevelAsset("kentaa"); |
---|
29 | //ruudut.SetTileMethod('=', ); |
---|
30 | ruudut.SetTileMethod('*', LouPuu); |
---|
31 | ruudut.Execute(); |
---|
32 | //Camera.ZoomToLevel(); |
---|
33 | //KavelyKuvatPeilattu = Image.Mirror(KavelyKuvat); |
---|
34 | |
---|
35 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
36 | Miner = new PhysicsObject(40.0, 40.0); |
---|
37 | Add(Miner); |
---|
38 | Miner.Shape = Shape.Rectangle; |
---|
39 | Miner.Color = Color.Black; |
---|
40 | Miner.Image = olionKuva; |
---|
41 | Miner.Animation = new Animation(KavelyKuvat); |
---|
42 | Miner.Animation.FPS = 2; |
---|
43 | Level.BackgroundColor = Color.ForestGreen; |
---|
44 | |
---|
45 | Camera.Follow(Miner); |
---|
46 | Camera.Zoom(4.0); |
---|
47 | |
---|
48 | AsetaOhjaimet(); |
---|
49 | Louzombie(); |
---|
50 | } |
---|
51 | void AsetaOhjaimet() |
---|
52 | { |
---|
53 | Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaaMinerYlos, "Pelaaja 1: Liikuta Miner ylös"); |
---|
54 | Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaMiner, null ); |
---|
55 | |
---|
56 | Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaaMinerAlas, "Pelaaja 1: Liikuta Miner Alas"); |
---|
57 | Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaMiner, null); |
---|
58 | |
---|
59 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaaMinerVasen, "Pelaaja 1: Liikuta Miner Vasemalle"); |
---|
60 | Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaMiner, null); |
---|
61 | |
---|
62 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaaMinerOikea, "Pelaaja 1: Liikuta Miner Oikealle"); |
---|
63 | Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaMiner, null); |
---|
64 | |
---|
65 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); |
---|
66 | } |
---|
67 | void PysaytaMiner() |
---|
68 | { |
---|
69 | Miner.Velocity = nopeusStop; |
---|
70 | Miner.Animation.Stop(); |
---|
71 | } |
---|
72 | void LiikutaaMinerYlos() |
---|
73 | { |
---|
74 | Miner.Velocity = nopeusYlos; |
---|
75 | Miner.Animation.Start(); |
---|
76 | } |
---|
77 | void LiikutaaMinerAlas() |
---|
78 | { |
---|
79 | Miner.Velocity = nopeusAlas; |
---|
80 | Miner.Animation.Start(); |
---|
81 | } |
---|
82 | void LiikutaaMinerVasen() |
---|
83 | { |
---|
84 | Miner.Velocity = nopeusVasen; |
---|
85 | Miner.Animation.Start(); |
---|
86 | } |
---|
87 | void LiikutaaMinerOikea() |
---|
88 | { |
---|
89 | Miner.Velocity = nopeusOikea; |
---|
90 | Miner.Animation.Start(); |
---|
91 | } |
---|
92 | void Louzombie() |
---|
93 | { |
---|
94 | PhysicsObject zombie = new PhysicsObject(40, 40); |
---|
95 | Add(zombie); |
---|
96 | zombie.Image = olionKuva1; |
---|
97 | zombie.X = RandomGen.NextDouble(Level.Left, Level.Right); |
---|
98 | } |
---|
99 | void LouPuu(Vector paikka, double leveys, double korkeus) |
---|
100 | { |
---|
101 | PhysicsObject Puu = PhysicsObject.CreateStaticObject( leveys, korkeus); |
---|
102 | Puu.Position = paikka; |
---|
103 | Puu.Shape = Shape.Circle; |
---|
104 | Puu.Color = Color.Green; |
---|
105 | Add(Puu); |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | } |
---|