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

Revision 6550, 4.0 KB checked in by sieerinn, 5 years ago (diff)

Pistoolia aloiteltu.

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