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 RPG : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject pelaaja; |
---|
12 | Vector NopeusYlos = new Vector(0, 200); |
---|
13 | Vector NopeusAlas = new Vector(0, -200); |
---|
14 | Vector NopeusVasemmalle = new Vector(-200, 0); |
---|
15 | Vector NopeusOikealle = new Vector(200, 0); |
---|
16 | |
---|
17 | int tapahtumat; |
---|
18 | public override void Begin() |
---|
19 | { |
---|
20 | LuoHahmot(); |
---|
21 | LisaaOhjaimet(); |
---|
22 | LuoKentta(); |
---|
23 | |
---|
24 | } |
---|
25 | |
---|
26 | void LuoKentta() |
---|
27 | { |
---|
28 | Level.Background.Image = LoadImage("tausta"); |
---|
29 | |
---|
30 | |
---|
31 | // |
---|
32 | |
---|
33 | Level.Width = Window.Width; |
---|
34 | Level.Height = Window.Height; |
---|
35 | Level.Background.Size = Level.Size; |
---|
36 | |
---|
37 | //tekee rannasta luoksepääsemättömän |
---|
38 | PhysicsObject ranta = PhysicsObject.CreateStaticObject(Level.Width, Level.Height); |
---|
39 | ranta.Shape = Shape.FromImage(LoadImage("taustahitbox")); |
---|
40 | Add(ranta); |
---|
41 | |
---|
42 | LuoSeinat(); |
---|
43 | |
---|
44 | PhysicsObject seina2 = PhysicsObject.CreateStaticObject(Level.Width, Level.Height); |
---|
45 | seina2.Shape = Shape.FromImage(LoadImage("taustahitbox2")); |
---|
46 | Add(seina2); |
---|
47 | |
---|
48 | PhysicsObject poyta = new PhysicsObject(155,169); |
---|
49 | poyta.Shape = Shape.Circle; |
---|
50 | poyta.MakeStatic(); |
---|
51 | poyta.IsVisible = false; |
---|
52 | poyta.X = -556; |
---|
53 | poyta.Y = -178; |
---|
54 | Add(poyta); |
---|
55 | |
---|
56 | //PhysicsObject kuusi = new PhysicsObject(100,300); |
---|
57 | //Add(kuusi); |
---|
58 | |
---|
59 | |
---|
60 | Level.CreateBorders(1.0, false); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | void LuoSeinat() |
---|
65 | { |
---|
66 | LuoSeina(-214, 195, 10, 424); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | void LuoSeina(double x, double y, double leveys, double korkeus) |
---|
71 | { |
---|
72 | PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
73 | seina.X = x; |
---|
74 | seina.Y = y; |
---|
75 | seina.IsVisible = false; |
---|
76 | Add(seina); |
---|
77 | } |
---|
78 | void LuoHahmot () |
---|
79 | { |
---|
80 | //luo pelaajan |
---|
81 | pelaaja = new PhysicsObject(40, 60); |
---|
82 | pelaaja.Image = LoadImage("hemmo"); |
---|
83 | pelaaja.Shape = Shape.Circle; |
---|
84 | pelaaja.CanRotate = false; |
---|
85 | pelaaja.Restitution = 0; |
---|
86 | Add(pelaaja); |
---|
87 | |
---|
88 | //luo merenneidon |
---|
89 | PhysicsObject merenneito = new PhysicsObject(90, 50); |
---|
90 | merenneito.Image = LoadImage("mermaid"); |
---|
91 | merenneito.MakeStatic(); |
---|
92 | merenneito.Restitution = 0; |
---|
93 | merenneito.X = 750; |
---|
94 | merenneito.Y = -150; |
---|
95 | Add(merenneito); |
---|
96 | |
---|
97 | //luo kerjalaisen |
---|
98 | PhysicsObject kerjalainen = new PhysicsObject(40, 60); |
---|
99 | kerjalainen.Image = LoadImage("kerjalainen"); |
---|
100 | kerjalainen.MakeStatic(); |
---|
101 | kerjalainen.Restitution = 0; |
---|
102 | kerjalainen.X = 350; |
---|
103 | kerjalainen.Y = -50; |
---|
104 | Add(kerjalainen); |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | void LisaaOhjaimet() |
---|
110 | { |
---|
111 | //liikuttaa pelaajaa |
---|
112 | Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "liikuta pelaajaa ylös", pelaaja, NopeusYlos); |
---|
113 | Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
114 | |
---|
115 | Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "liikuta pelaajaa alas", pelaaja, NopeusAlas); |
---|
116 | Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
117 | |
---|
118 | Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, "liikuta pelaajaa vasemmalle", pelaaja, NopeusVasemmalle); |
---|
119 | Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
120 | |
---|
121 | Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus, "liikuta pelaajaa oikealle", pelaaja, NopeusOikealle); |
---|
122 | Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, pelaaja, Vector.Zero); |
---|
123 | |
---|
124 | //exit |
---|
125 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
126 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
127 | |
---|
128 | } |
---|
129 | void AsetaNopeus(PhysicsObject pelaaja, Vector nopeus) |
---|
130 | { |
---|
131 | pelaaja.Velocity = nopeus; |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | } |
---|