source: 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs @ 6548

Revision 6548, 3.8 KB checked in by sieerinn, 4 years ago (diff)

Miekan (tai toistaiseksi pistoolin) heiluttelu.

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