1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | |
---|
7 | public partial class TheLegendOfGabriel : PhysicsGame |
---|
8 | { |
---|
9 | /// <summary> |
---|
10 | /// Luo kentän .tmx tiedostosta. |
---|
11 | /// </summary> |
---|
12 | void CreateLevel(string levelName) |
---|
13 | { |
---|
14 | var level = TiledTileMap.FromLevelAsset(levelName); |
---|
15 | level.SetTileMethod("base", CreateBaseTile); |
---|
16 | level.SetTileMethod("foreground", CreateForegroundTile); |
---|
17 | level.SetObjectMethod("exit", CreateExit); |
---|
18 | level.SetTileMethod("decoration", CreateDecoration); |
---|
19 | level.SetObjectMethod("player", CreatePlayer); |
---|
20 | level.Execute(); |
---|
21 | |
---|
22 | Level.Background.Color = Color.Black; |
---|
23 | } |
---|
24 | |
---|
25 | /// <summary> |
---|
26 | /// Luo pelaajan. |
---|
27 | /// </summary> |
---|
28 | void CreatePlayer(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
29 | { |
---|
30 | player = new Creature(TILE_SIZE, TILE_SIZE); |
---|
31 | player.MovementSpeed = 2300; |
---|
32 | player.Position = position; |
---|
33 | player.MoveAnimations[Direction.Left] = playerWalkLeft; |
---|
34 | player.MoveAnimations[Direction.Right] = playerWalkRight; |
---|
35 | player.MoveAnimations[Direction.Up] = playerWalkUp; |
---|
36 | player.MoveAnimations[Direction.Down] = playerWalkDown; |
---|
37 | player.Image = playerWalkDown.CurrentFrame; |
---|
38 | Add(player, 1); |
---|
39 | |
---|
40 | AddCollisionHandler(player, "exit", CollidesWithExit); |
---|
41 | } |
---|
42 | |
---|
43 | /// <summary> |
---|
44 | /// Maassa oleva tiili. |
---|
45 | /// </summary> |
---|
46 | void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
47 | { |
---|
48 | CreateBasicTile(position, width, height, image, -1, properties); |
---|
49 | } |
---|
50 | |
---|
51 | /// <summary> |
---|
52 | /// Pohjan päällä, pelaajan alla näkyvä tiili. |
---|
53 | /// </summary> |
---|
54 | void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
55 | { |
---|
56 | CreateBasicTile(position, width, height, image, 0, properties); |
---|
57 | } |
---|
58 | |
---|
59 | /// <summary> |
---|
60 | /// Pelaajan päällä näkyvä tiili. |
---|
61 | /// </summary> |
---|
62 | void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) |
---|
63 | { |
---|
64 | CreateBasicTile(position, width, height, image, 2, properties); |
---|
65 | } |
---|
66 | |
---|
67 | /// <summary> |
---|
68 | /// Luo tavallisen tiilen. |
---|
69 | /// </summary> |
---|
70 | void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties) |
---|
71 | { |
---|
72 | var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height); |
---|
73 | tile.Image = image; |
---|
74 | tile.Position = position; |
---|
75 | Add(tile, layer); |
---|
76 | } |
---|
77 | |
---|
78 | /// <summary> |
---|
79 | /// Luo uloskäynnin, joka vie toiseen kenttään. |
---|
80 | /// </summary> |
---|
81 | void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties) |
---|
82 | { |
---|
83 | var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property. |
---|
84 | var exit = new Exit(width, height); |
---|
85 | exit.Position = position; |
---|
86 | exit.TargetLevel = target[0]; |
---|
87 | exit.TargetExitName = target[1]; |
---|
88 | exit.Name = name; |
---|
89 | Add(exit); |
---|
90 | exits.Add(exit); |
---|
91 | } |
---|
92 | } |
---|