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

Revision 6619, 4.3 KB checked in by sieerinn, 4 years ago (diff)

Aktiivisen kaman vaihto toimii.

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 = new DoubleMeter(2300, 0, 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.ShootAnimations[Direction.Left] = playerShootLeft;
54        player.ShootAnimations[Direction.Right] = playerShootRight;
55        player.ShootAnimations[Direction.Up] = playerShootUp;
56        player.ShootAnimations[Direction.Down] = playerShootDown;
57        player.Image = playerWalkDown.CurrentFrame;
58        Add(player, 1);
59
60        player.Sword = new Sword(player);
61        player.Inventory.Add(new Pistol(player));
62        player.Inventory.Add(new Monocle(player));
63
64        AddCollisionHandler(player, "exit", CollidesWithExit);
65    }
66
67    /// <summary>
68    /// Maassa oleva tiili.
69    /// </summary>
70    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
71    {
72        CreateBasicTile(position, width, height, image, -1, properties);
73    }
74
75    /// <summary>
76    /// Pohjan päällä, pelaajan alla näkyvä tiili.
77    /// </summary>
78    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
79    {
80        CreateBasicTile(position, width, height, image, 0, properties);
81    }
82
83        /// <summary>
84    /// Pelaajan päällä näkyvä tiili.
85    /// </summary>
86    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
87    {
88        CreateBasicTile(position, width, height, image, 2, properties);
89    }
90
91    /// <summary>
92    /// Luo tavallisen tiilen.
93    /// </summary>
94    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
95    {
96        var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height);
97        tile.Image = image;
98        tile.Position = position;
99        Add(tile, layer);
100    }
101
102    /// <summary>
103    /// Luo uloskäynnin, joka vie toiseen kenttään.
104    /// </summary>
105    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
106    {
107        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
108        var exit = new Exit(width, height);
109        exit.Position = position;
110        exit.TargetLevel = target[0];
111        exit.TargetExitName = target[1];
112        exit.Name = name;
113        Add(exit);
114        exits.Add(exit);
115    }
116}
Note: See TracBrowser for help on using the repository browser.