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 | class mob : PhysicsObject |
---|
10 | { |
---|
11 | private IntMeter elamaLaskuri = new IntMeter(3, 0, 3); |
---|
12 | public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } |
---|
13 | |
---|
14 | public mob(double leveys, double korkeus) |
---|
15 | : base(leveys, korkeus) |
---|
16 | { |
---|
17 | elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; |
---|
18 | } |
---|
19 | public int Elamat { get; set; } |
---|
20 | public int Kilpi { get; set; } |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | public class DungeonClasher : PhysicsGame |
---|
27 | { |
---|
28 | |
---|
29 | mob pelaaja; |
---|
30 | |
---|
31 | DoubleMeter elamaLaskuri; |
---|
32 | |
---|
33 | public override void Begin() |
---|
34 | { |
---|
35 | |
---|
36 | asetaNappaimet(); |
---|
37 | LuoKentta(); |
---|
38 | |
---|
39 | |
---|
40 | Mouse.IsCursorVisible = true; |
---|
41 | |
---|
42 | Camera.ZoomToLevel(); |
---|
43 | |
---|
44 | } |
---|
45 | void LuoKentta() |
---|
46 | { |
---|
47 | TileMap ruudut = TileMap.FromLevelAsset("kentta1"); |
---|
48 | ruudut.SetTileMethod('=', LuoHirvio); |
---|
49 | ruudut.SetTileMethod('*', LisaaLattia); |
---|
50 | ruudut.SetTileMethod('P', LuoPelaaja); |
---|
51 | ruudut.Execute(40, 40); |
---|
52 | |
---|
53 | Level.CreateBorders(); |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | void asetaNappaimet() |
---|
58 | { |
---|
59 | |
---|
60 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
61 | Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, null, new Vector(-500, 0)); |
---|
62 | Keyboard.Listen(Key.Left, ButtonState.Released, PysaytaPelaaja, null, new Vector()); |
---|
63 | Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, new Vector(500, 0)); |
---|
64 | Keyboard.Listen(Key.Right, ButtonState.Released, PysaytaPelaaja, null, new Vector()); |
---|
65 | |
---|
66 | |
---|
67 | } |
---|
68 | void LiikutaPelaajaa(Vector vektori) |
---|
69 | { |
---|
70 | pelaaja.Push(vektori); |
---|
71 | } |
---|
72 | void PysaytaPelaaja(Vector vektori) |
---|
73 | { |
---|
74 | pelaaja.Velocity = new Vector(0, 0); |
---|
75 | } |
---|
76 | |
---|
77 | void LuoHirvio(Vector paikka, double leveys, double korkeus) |
---|
78 | { |
---|
79 | //mob Hirvio = RandomGen.SelectOne(orc, darkKnight, giant); |
---|
80 | mob Hirvio = new mob(20, 20); |
---|
81 | int arvonta = RandomGen.NextInt(3); |
---|
82 | |
---|
83 | if (arvonta == 1) |
---|
84 | { |
---|
85 | //orc |
---|
86 | Hirvio = new mob(40.0, 40.0); |
---|
87 | |
---|
88 | Hirvio.Elamat = 3; |
---|
89 | Hirvio.Shape = Shape.Rectangle; |
---|
90 | Hirvio.Color = Color.Yellow; |
---|
91 | Hirvio.CollisionIgnoreGroup = 1; |
---|
92 | Hirvio.Tag = "Enimy"; |
---|
93 | |
---|
94 | |
---|
95 | } |
---|
96 | else if (arvonta == 2) |
---|
97 | { |
---|
98 | //darkKnight |
---|
99 | Hirvio = new mob(20, 60); |
---|
100 | Hirvio.Elamat = 3; |
---|
101 | Hirvio.Shape = Shape.Rectangle; |
---|
102 | Hirvio.Color = Color.Black; |
---|
103 | Hirvio.CollisionIgnoreGroup = 1; |
---|
104 | Hirvio.Tag = "Enimy"; |
---|
105 | } |
---|
106 | else |
---|
107 | { |
---|
108 | //giant |
---|
109 | Hirvio = new mob(75, 100); |
---|
110 | Hirvio.Elamat = 3; |
---|
111 | Hirvio.Shape = Shape.Rectangle; |
---|
112 | Hirvio.Color = Color.Blue; |
---|
113 | Hirvio.CollisionIgnoreGroup = 1; |
---|
114 | Hirvio.Tag = "Enimy"; |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | Hirvio.Position = paikka; |
---|
119 | Hirvio.Y -= 20 - Hirvio.Height * 0.5; |
---|
120 | Add(Hirvio); |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | } |
---|
125 | void LisaaLattia(Vector paikka, Double leveys, Double korkeus) |
---|
126 | { |
---|
127 | PhysicsObject lattia = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
128 | lattia.Position = paikka; |
---|
129 | lattia.Color = Color.Brown; |
---|
130 | Add(lattia); |
---|
131 | |
---|
132 | |
---|
133 | } |
---|
134 | void LuoPelaaja(Vector paikka, Double leveys, Double korkeus) |
---|
135 | { |
---|
136 | pelaaja = new mob(40.40, 40.0); |
---|
137 | pelaaja.Elamat = 3; |
---|
138 | Add(pelaaja); |
---|
139 | |
---|
140 | pelaaja.MaxAngularVelocity = 0; |
---|
141 | pelaaja.MaxVelocity = 500; |
---|
142 | pelaaja.Mass = 2.5; |
---|
143 | |
---|
144 | pelaaja.CollisionIgnoreGroup = 1; |
---|
145 | |
---|
146 | pelaaja.Color = Color.Black; |
---|
147 | pelaaja.Position = paikka; |
---|
148 | |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | |
---|