1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | using Jypeli.Assets; |
---|
7 | |
---|
8 | /* |
---|
9 | *Klassisia muistutuksia |
---|
10 | * 3 |
---|
11 | * 2 Pelaajan päällä näkyvät elementit |
---|
12 | * 1 Pelaaja, kojootit |
---|
13 | * 0 Lisäkoriste |
---|
14 | * -1 Perustiili |
---|
15 | * -2 |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | public partial class TheLegendOfGabriel : PhysicsGame |
---|
20 | { |
---|
21 | /// <summary> |
---|
22 | /// Luo kentän .tmx tiedostosta. |
---|
23 | /// </summary> |
---|
24 | void CreateLevel(string levelName) |
---|
25 | { |
---|
26 | bossSpawnPositions.Clear(); |
---|
27 | Level.CreateVerticalBorders(1.0, false, Color.Yellow); |
---|
28 | PhysicsObject leftBorder = Level.CreateLeftBorder(0.0, false); |
---|
29 | PhysicsObject rightBorder = Level.CreateRightBorder(0.0, false); |
---|
30 | leftBorder.X += Level.Width * 0.25; |
---|
31 | rightBorder.X -= Level.Width * 0.25; |
---|
32 | |
---|
33 | var level = TiledTileMap.FromLevelAsset(levelName); |
---|
34 | level.SetTileMethod("base", CreateBaseTile); |
---|
35 | level.SetTileMethod("foreground", CreateForegroundTile); |
---|
36 | level.SetObjectMethod("exit", CreateExit); |
---|
37 | level.SetTileMethod("decoration", CreateDecoration); |
---|
38 | level.SetTileMethod("cover", CreateCover); |
---|
39 | //level.SetObjectMethod("player", CreatePlayer); |
---|
40 | level.SetObjectMethod("blockade", CreateBlock); |
---|
41 | level.SetObjectMethod("coyote", CreateCoyote); |
---|
42 | level.SetObjectMethod("boss", CreateBoss); |
---|
43 | level.SetObjectMethod("bossspawn", CreateBossSpawn); |
---|
44 | level.Execute(); |
---|
45 | |
---|
46 | Level.Background.Color = Color.Black; |
---|
47 | } |
---|
48 | |
---|
49 | void CreateBossSpawn(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
50 | { |
---|
51 | bossSpawnPositions.Add(position); |
---|
52 | } |
---|
53 | |
---|
54 | void CreateBoss(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
55 | { |
---|
56 | var bossHealth = new IntMeter(10); |
---|
57 | |
---|
58 | var bossTimer = new Timer(); |
---|
59 | bossTimer.Interval = 4; |
---|
60 | bossTimer.Timeout += delegate |
---|
61 | { |
---|
62 | Vector pos = RandomGen.SelectOne<Vector>(bossSpawnPositions); |
---|
63 | //CreateBossTrainPart(pos, ); |
---|
64 | }; |
---|
65 | bossTimer.Start(); |
---|
66 | } |
---|
67 | |
---|
68 | void CreateBossTrainPart(Vector position, Animation anim) |
---|
69 | { |
---|
70 | var part = PhysicsObject.CreateStaticObject(150, 70); |
---|
71 | part.Position = position; |
---|
72 | part.Animation = anim; |
---|
73 | part.Animation.Start(); |
---|
74 | part.Velocity = new Vector(-50, 0); |
---|
75 | Add(part); |
---|
76 | } |
---|
77 | |
---|
78 | /// <summary> |
---|
79 | /// Näkymättömiä esteitä. |
---|
80 | /// </summary> |
---|
81 | void CreateBlock(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
82 | { |
---|
83 | PhysicsObject block = PhysicsObject.CreateStaticObject(width, height); |
---|
84 | block.Position = position; |
---|
85 | block.IsVisible = false; |
---|
86 | Add(block); |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | void CreateCoyote(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
91 | { |
---|
92 | var enemy = new Creature(width, height, 1); |
---|
93 | enemy.MoveAnimations = DirectionalAnimations(coyoteLeft, coyoteRight, coyoteUp, coyoteDown); |
---|
94 | enemy.Position = position; |
---|
95 | enemy.Tag = "enemy"; |
---|
96 | enemy.Brain = new FollowerBrain(player) { Speed = 50 }; |
---|
97 | Add(enemy, 1); |
---|
98 | enemies.Add(enemy); |
---|
99 | |
---|
100 | AddCollisionHandler(enemy, "playerattack", delegate(PhysicsObject e, PhysicsObject a) |
---|
101 | { |
---|
102 | enemy.Health.Value--; |
---|
103 | }); |
---|
104 | |
---|
105 | enemy.Health.LowerLimit += enemy.Destroy; |
---|
106 | } |
---|
107 | |
---|
108 | /// <summary> |
---|
109 | /// Maassa oleva tiili. |
---|
110 | /// </summary> |
---|
111 | void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
112 | { |
---|
113 | CreateBasicTile(position, width, height, image, -1, properties); |
---|
114 | } |
---|
115 | |
---|
116 | /// <summary> |
---|
117 | /// Pohjan päällä, pelaajan alla näkyvä tiili. |
---|
118 | /// </summary> |
---|
119 | void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
120 | { |
---|
121 | CreateBasicTile(position, width, height, image, 0, properties); |
---|
122 | } |
---|
123 | |
---|
124 | /// <summary> |
---|
125 | /// Pelaajan päällä näkyvä tiili. |
---|
126 | /// </summary> |
---|
127 | void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
128 | { |
---|
129 | CreateBasicTile(position, width, height, image, 2, properties); |
---|
130 | } |
---|
131 | |
---|
132 | void CreateCover(Vector position, double width, double height, Image image, string layername, Dictionary<string, string> properties) |
---|
133 | { |
---|
134 | var tile = new GameObject(width, height); |
---|
135 | tile.Tag = "cover"; |
---|
136 | tile.Image = image; |
---|
137 | tile.Position = position; |
---|
138 | Add(tile, 3); |
---|
139 | } |
---|
140 | |
---|
141 | /// <summary> |
---|
142 | /// Luo tavallisen tiilen. |
---|
143 | /// </summary> |
---|
144 | GameObject CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties) |
---|
145 | { |
---|
146 | var tile = properties.ContainsKey("collide") ? new PhysicsObject(width, height) : new GameObject(width, height); |
---|
147 | tile.Image = image; |
---|
148 | tile.Position = position; |
---|
149 | Add(tile, layer); |
---|
150 | return tile; |
---|
151 | } |
---|
152 | |
---|
153 | /// <summary> |
---|
154 | /// Luo uloskäynnin, joka vie toiseen kenttään. |
---|
155 | /// </summary> |
---|
156 | void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
157 | { |
---|
158 | var target = properties["goto"] == "disabled"? null : properties["goto"].Split('@'); // Jos peli kaatuu tälle riville niin joltain exitiltä puuttuu goto-property. |
---|
159 | var exit = new Exit(width, height); |
---|
160 | exit.Position = position; |
---|
161 | if (target != null) |
---|
162 | { |
---|
163 | exit.TargetLevel = target[0]; |
---|
164 | exit.TargetExitName = target[1]; |
---|
165 | } |
---|
166 | exit.Name = name; |
---|
167 | Add(exit); |
---|
168 | exits.Add(exit); |
---|
169 | } |
---|
170 | } |
---|