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

Revision 6631, 4.4 KB checked in by sieerinn, 4 years ago (diff)

Miekan ääntä säädetty hiljaisemmaksi. Kranaatteja voi heitellä.

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.SetObjectMethod("blockade", CreateBlock);
32        // level.SetObjectMethod("coyote", CreateEnemy);
33        level.Execute();
34
35        Level.Background.Color = Color.Black;
36    }
37
38    /// <summary>
39    /// Näkymättömiä esteitä.
40    /// </summary>
41    void CreateBlock(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
42    {
43        PhysicsObject block = PhysicsObject.CreateStaticObject(width, height);
44        block.Position = position;
45        block.IsVisible = false;
46        Add(block);
47
48    }
49
50    /// <summary>
51    /// Luo pelaajan.
52    /// </summary>
53    void CreatePlayer(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
54    {
55        player = new Player();
56        player.CanRotate = false;
57        player.MovementSpeed = new DoubleMeter(2300, 0, 2300);
58        player.Position = position;
59        player.MoveAnimations = DirectionalAnimations(playerWalkLeft, playerWalkRight, playerWalkUp, playerWalkDown);
60        player.SwingAnimations = DirectionalAnimations(playerSwingLeft, playerSwingRight, playerSwingUp, playerSwingDown);
61        player.ShootAnimations = DirectionalAnimations(playerShootLeft, playerShootRight, playerShootUp, playerShootDown);
62        player.Image = playerWalkDown.CurrentFrame;
63        Add(player, 1);
64
65        player.Sword = new Sword(player);
66        player.Inventory.Add(new Pistol(player));
67        player.Inventory.Add(new Monocle(player));
68        player.Inventory.Add(new Grenade(player));
69
70        AddCollisionHandler(player, "exit", CollidesWithExit);
71    }
72
73    /// <summary>
74    /// Maassa oleva tiili.
75    /// </summary>
76    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
77    {
78        CreateBasicTile(position, width, height, image, -1, properties);
79    }
80
81    /// <summary>
82    /// Pohjan päällä, pelaajan alla näkyvä tiili.
83    /// </summary>
84    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
85    {
86        CreateBasicTile(position, width, height, image, 0, properties);
87    }
88
89    /// <summary>
90    /// Pelaajan päällä näkyvä tiili.
91    /// </summary>
92    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
93    {
94        CreateBasicTile(position, width, height, image, 2, properties);
95    }
96
97    /// <summary>
98    /// Luo tavallisen tiilen.
99    /// </summary>
100    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
101    {
102        var tile = properties.ContainsKey("collide") ? new PhysicsObject(width, height) : new GameObject(width, height);
103        tile.Image = image;
104        tile.Position = position;
105        Add(tile, layer);
106    }
107
108    /// <summary>
109    /// Luo uloskäynnin, joka vie toiseen kenttään.
110    /// </summary>
111    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
112    {
113        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
114        var exit = new Exit(width, height);
115        exit.Position = position;
116        exit.TargetLevel = target[0];
117        exit.TargetExitName = target[1];
118        exit.Name = name;
119        Add(exit);
120        exits.Add(exit);
121    }
122}
Note: See TracBrowser for help on using the repository browser.