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

Revision 6632, 5.7 KB checked in by sieerinn, 4 years ago (diff)

Kojootteja vastaan voi taistella, pelaajalla elämät, kenttiä korjailtu, hoboluola tehty.

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6using Jypeli.Assets;
7
8/*
9 *Klassisia muistutuksia
10 * 3
11 * 2    Pelaajan päällä näkyvät elementit
12 * 1    Pelaaja
13 * 0    Lisäkoriste
14 * -1   Perustiili
15 * -2
16 */
17
18
19public partial class TheLegendOfGabriel : PhysicsGame
20{
21    /// <summary>
22    /// Luo kentän .tmx tiedostosta.
23    /// </summary>
24    void CreateLevel(string levelName)
25    {
26        var level = TiledTileMap.FromLevelAsset(levelName);
27        level.SetTileMethod("base", CreateBaseTile);
28        level.SetTileMethod("foreground", CreateForegroundTile);
29        level.SetObjectMethod("exit", CreateExit);
30        level.SetTileMethod("decoration", CreateDecoration);
31        //level.SetObjectMethod("player", CreatePlayer);
32        level.SetObjectMethod("blockade", CreateBlock);
33        level.SetObjectMethod("coyote", CreateCoyote);
34        level.Execute();
35
36        Level.Background.Color = Color.Black;
37    }
38
39    /// <summary>
40    /// Näkymättömiä esteitä.
41    /// </summary>
42    void CreateBlock(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
43    {
44        PhysicsObject block = PhysicsObject.CreateStaticObject(width, height);
45        block.Position = position;
46        block.IsVisible = false;
47        Add(block);
48
49    }
50
51    void CreateCoyote(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
52    {
53        var enemy = new Creature(width, height, 1);
54        enemy.MoveAnimations = DirectionalAnimations(coyoteLeft, coyoteRight, coyoteUp, coyoteDown);
55        enemy.Position = position;
56        enemy.Tag = "enemy";
57        enemy.Brain = new FollowerBrain(player) { Speed = 50 };
58        Add(enemy, 1);
59        enemies.Add(enemy);
60
61        AddCollisionHandler(enemy, "playerattack", delegate(PhysicsObject e, PhysicsObject a)
62        {
63            enemy.Health.Value--;
64        });
65
66        enemy.Health.LowerLimit += enemy.Destroy;
67
68        /*
69        Timer updateTimer = new Timer();
70        updateTimer.Interval = 0.02;
71        updateTimer.Timeout += delegate
72        {
73            if (!(enemy.Brain is FollowerBrain))
74            {
75               
76            }
77            enemy.UpdateCreature(Time);
78        };
79        updateTimer.Start();
80         */
81    }
82
83    /// <summary>
84    /// Luo pelaajan.
85    /// </summary>
86    void CreatePlayer(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
87    {
88        player = new Player();
89        player.CanRotate = false;
90        player.MovementSpeed = new DoubleMeter(2300, 0, 2300);
91        player.Position = position;
92        player.MoveAnimations = DirectionalAnimations(playerWalkLeft, playerWalkRight, playerWalkUp, playerWalkDown);
93        player.SwingAnimations = DirectionalAnimations(playerSwingLeft, playerSwingRight, playerSwingUp, playerSwingDown);
94        player.ShootAnimations = DirectionalAnimations(playerShootLeft, playerShootRight, playerShootUp, playerShootDown);
95        player.Image = playerWalkDown.CurrentFrame;
96        Add(player, 1);
97
98        player.Sword = new Sword(player);
99        player.Inventory.Add(new Pistol(player));
100        player.Inventory.Add(new Monocle(player));
101        player.Inventory.Add(new Grenade(player));
102
103        player.Health.Value = 3; // Alkuun vain kolme sydäntä.
104
105        AddCollisionHandler(player, "exit", CollidesWithExit);
106        AddCollisionHandler(player, "enemy", delegate(PhysicsObject p, PhysicsObject e)
107        {
108            player.Health.Value--;
109        });
110    }
111
112    /// <summary>
113    /// Maassa oleva tiili.
114    /// </summary>
115    void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
116    {
117        CreateBasicTile(position, width, height, image, -1, properties);
118    }
119
120    /// <summary>
121    /// Pohjan päällä, pelaajan alla näkyvä tiili.
122    /// </summary>
123    void CreateDecoration(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
124    {
125        CreateBasicTile(position, width, height, image, 0, properties);
126    }
127
128    /// <summary>
129    /// Pelaajan päällä näkyvä tiili.
130    /// </summary>
131    void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties)
132    {
133        CreateBasicTile(position, width, height, image, 2, properties);
134    }
135
136    /// <summary>
137    /// Luo tavallisen tiilen.
138    /// </summary>
139    void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties)
140    {
141        var tile = properties.ContainsKey("collide") ? new PhysicsObject(width, height) : new GameObject(width, height);
142        tile.Image = image;
143        tile.Position = position;
144        Add(tile, layer);
145    }
146
147    /// <summary>
148    /// Luo uloskäynnin, joka vie toiseen kenttään.
149    /// </summary>
150    void CreateExit(Vector position, double width, double height, Angle angle, Shape shape, string name, Dictionary<string, string> properties)
151    {
152        var target = properties["goto"].Split('@'); // Jos peli kaatuaa tälle riville niin joltain exitiltä puuttuu goto-property.
153        var exit = new Exit(width, height);
154        exit.Position = position;
155        exit.TargetLevel = target[0];
156        exit.TargetExitName = target[1];
157        exit.Name = name;
158        Add(exit);
159        exits.Add(exit);
160    }
161}
Note: See TracBrowser for help on using the repository browser.