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 FysiikkaPeli3 : PhysicsGame |
---|
10 | { |
---|
11 | PlatformCharacter pelaaja1; |
---|
12 | Image[] ssprites = LoadImages("run 1", "run 2", "run 3"); |
---|
13 | Image[] pictures = LoadImages("ff", "stand 2", "stand 3", "stand 4"); |
---|
14 | Image[] kävelyVasemmalle; |
---|
15 | Image[] vasemmallePaikallaan; |
---|
16 | Image[] vasemmalleTippuminen; |
---|
17 | Image[] tippumisAnimaatio = LoadImages("fall 1","fall 2"); |
---|
18 | IntMeter HPlaskuri; |
---|
19 | public override void Begin() |
---|
20 | { |
---|
21 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
22 | kävelyVasemmalle = Image.Mirror(ssprites); |
---|
23 | vasemmallePaikallaan = Image.Mirror(pictures); |
---|
24 | vasemmalleTippuminen = Image.Mirror(tippumisAnimaatio); |
---|
25 | LuoPelaaja(); |
---|
26 | Gravity = new Vector(0, -500); |
---|
27 | Luokentta(); |
---|
28 | Level.CreateBorders(); |
---|
29 | keyboard(); |
---|
30 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
31 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
32 | LuoHPmittari(); |
---|
33 | Camera.ZoomToLevel(); |
---|
34 | } |
---|
35 | void Luokentta() |
---|
36 | { |
---|
37 | TileMap ruudut = TileMap.FromLevelAsset("kenttä 1"); |
---|
38 | ruudut.SetTileMethod('-', Luotaso); |
---|
39 | ruudut.SetTileMethod('v', Lasertykki); |
---|
40 | ruudut.Execute(13, 13); |
---|
41 | } |
---|
42 | void Luotaso(Vector paikka, double leveys, double korkeus) |
---|
43 | { |
---|
44 | PhysicsObject taso = PhysicsObject.CreateStaticObject(13, 13); |
---|
45 | taso.Position = paikka; |
---|
46 | Add(taso); |
---|
47 | } |
---|
48 | void LuoPelaaja() |
---|
49 | { |
---|
50 | pelaaja1 = new PlatformCharacter(14.0, 15.0); |
---|
51 | Add(pelaaja1); |
---|
52 | pelaaja1.RightIdleAnimation = new Animation(pictures); |
---|
53 | pelaaja1.RightIdleAnimation.FPS = 7; |
---|
54 | pelaaja1.LeftIdleAnimation = new Animation(vasemmallePaikallaan); |
---|
55 | pelaaja1.LeftIdleAnimation.FPS = 7; |
---|
56 | pelaaja1.RightWalkingAnimation = new Animation(ssprites); |
---|
57 | pelaaja1.RightWalkingAnimation.FPS = 18; |
---|
58 | pelaaja1.LeftWalkingAnimation = new Animation(kävelyVasemmalle); |
---|
59 | pelaaja1.LeftWalkingAnimation.FPS = 18; |
---|
60 | AddCollisionHandler(pelaaja1,palautaAnimation); |
---|
61 | } |
---|
62 | void palautaAnimation(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
63 | { |
---|
64 | pelaaja1.RightIdleAnimation = new Animation(pictures); |
---|
65 | pelaaja1.RightIdleAnimation.FPS = 7; |
---|
66 | pelaaja1.LeftIdleAnimation = new Animation(vasemmallePaikallaan); |
---|
67 | pelaaja1.LeftIdleAnimation.FPS = 7; |
---|
68 | pelaaja1.RightWalkingAnimation = new Animation(ssprites); |
---|
69 | pelaaja1.RightWalkingAnimation.FPS = 18; |
---|
70 | pelaaja1.LeftWalkingAnimation = new Animation(kävelyVasemmalle); |
---|
71 | pelaaja1.LeftWalkingAnimation.FPS = 18; |
---|
72 | } |
---|
73 | |
---|
74 | void keyboard() |
---|
75 | { |
---|
76 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, pelaaja1, -50.0); |
---|
77 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, pelaaja1,50.0 ); |
---|
78 | Keyboard.Listen(Key.Up, ButtonState.Down, hyppaa, null, pelaaja1); |
---|
79 | } |
---|
80 | void LiikutaPelaajaa(PlatformCharacter pelaaja,double Nopeus ) |
---|
81 | |
---|
82 | { |
---|
83 | pelaaja.Walk(Nopeus); |
---|
84 | } |
---|
85 | void hyppaa(PlatformCharacter pelaaja) |
---|
86 | { |
---|
87 | pelaaja.Jump(200.0); |
---|
88 | pelaaja.RightWalkingAnimation = pelaaja.RightIdleAnimation = new Animation(tippumisAnimaatio); |
---|
89 | pelaaja.RightWalkingAnimation.FPS = 4; |
---|
90 | pelaaja.RightIdleAnimation.FPS = 4; |
---|
91 | pelaaja.LeftWalkingAnimation = pelaaja.LeftIdleAnimation = new Animation(vasemmalleTippuminen); |
---|
92 | pelaaja.LeftWalkingAnimation.FPS = 4; |
---|
93 | pelaaja.LeftIdleAnimation.FPS = 4; |
---|
94 | } |
---|
95 | void LuoHPmittari() |
---|
96 | { |
---|
97 | HPlaskuri = new IntMeter(100); |
---|
98 | Label HPnaytto = new Label(); |
---|
99 | HPnaytto.X = Screen.Left + 100; |
---|
100 | HPnaytto.Y = Screen.Top - 100; |
---|
101 | HPnaytto.TextColor = Color.Black; |
---|
102 | HPnaytto.Color = Color.Blue; |
---|
103 | |
---|
104 | HPnaytto.BindTo(HPlaskuri); |
---|
105 | Add(HPnaytto); |
---|
106 | } |
---|
107 | void Lasertykki(Vector paikka, double leveys, double korkeus) |
---|
108 | { |
---|
109 | PhysicsObject Lasertykki = PhysicsObject.CreateStaticObject(20, 10); |
---|
110 | Lasertykki.Position = paikka; |
---|
111 | Lasertykki.Shape = Shape.Rectangle; |
---|
112 | |
---|
113 | Add(Lasertykki); |
---|
114 | Timer ajastin = new Timer(); |
---|
115 | ajastin.Interval = 1; |
---|
116 | ajastin.Timeout += delegate { ammu(Lasertykki.Position - new Vector(Lasertykki.Width / 2, 0)); }; |
---|
117 | ajastin.Start(); |
---|
118 | } |
---|
119 | void ammu(Vector paikka) |
---|
120 | { |
---|
121 | PhysicsObject ammus = new PhysicsObject(13, 14); |
---|
122 | ammus.Position = paikka; |
---|
123 | ammus.Shape = Shape.Circle; |
---|
124 | Add(ammus); |
---|
125 | ammus.Hit(new Vector(-600, 0)); |
---|
126 | ammus.MaximumLifetime = TimeSpan.FromSeconds(1.0); |
---|
127 | } |
---|
128 | } |
---|