- Timestamp:
- 2015-06-29 16:51:35 (6 years ago)
- Location:
- 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/LevelCreation.cs
r6536 r6538 7 7 public partial class TheLegendOfGabriel : PhysicsGame 8 8 { 9 /// <summary> 10 /// Luo pelaajan. 11 /// </summary> 12 void CreatePlayer(Vector position) 13 { 14 player = new Creature(TILE_SIZE, TILE_SIZE); 15 player.MovementSpeed = 2300; 16 player.Position = position; 17 Add(player); 18 } 19 9 20 /// <summary> 10 21 /// Luo kentän .tmx tiedostosta. … … 21 32 22 33 /// <summary> 23 /// Maassa oleva perus tiili , jonka läpi voi kävellä.34 /// Maassa oleva perus tiili. 24 35 /// </summary> 25 void CreateBaseTile(Vector position, double width, double height, Image image, string layerName )36 void CreateBaseTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) 26 37 { 27 CreateBasicTile(position, width, height, image, -1 );38 CreateBasicTile(position, width, height, image, -1, properties); 28 39 } 29 40 … … 31 42 /// Pelaajan päällä näkyvä perus tiili. 32 43 /// </summary> 33 void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName )44 void CreateForegroundTile(Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties) 34 45 { 35 CreateBasicTile(position, width, height, image, 1 );46 CreateBasicTile(position, width, height, image, 1, properties); 36 47 } 37 48 38 49 /// <summary> 39 /// Luo tavallisen tiilen jonka läpi voi kävellä.50 /// Luo tavallisen tiilen. 40 51 /// </summary> 41 void CreateBasicTile(Vector position, double width, double height, Image image, int layer )52 void CreateBasicTile(Vector position, double width, double height, Image image, int layer, Dictionary<string, string> properties) 42 53 { 43 var tile = new GameObject(width, height);54 var tile = properties.ContainsKey("collide")? new PhysicsObject(width, height) : new GameObject(width, height); 44 55 tile.Image = image; 45 56 tile.Position = position; -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs
r6536 r6538 7 7 using Jypeli.Widgets; 8 8 9 class Creature : PhysicsObject 10 { 11 public double MovementSpeed { get; set; } 12 13 public Creature(double width, double height) 14 : base(width, height) 15 { 16 LinearDamping = 0.5; 17 } 18 19 public void Move(Direction direction) 20 { 21 Push(direction.GetVector() * MovementSpeed); 22 } 23 } 24 9 25 public partial class TheLegendOfGabriel : PhysicsGame 10 26 { 27 public const int TILE_SIZE = 20; 28 29 private Creature player; 30 11 31 public override void Begin() 12 32 { … … 18 38 { 19 39 ClearAll(); 20 CreateLevel("testlevel"); 40 CreateLevel("testlevel2"); 41 CreatePlayer(new Vector(30, -30)); 21 42 SetControls(); 22 43 Camera.ZoomToLevel(); … … 25 46 void SetControls() 26 47 { 48 Keyboard.Listen(Key.Left, ButtonState.Down, player.Move, null, Direction.Left); 49 Keyboard.Listen(Key.Right, ButtonState.Down, player.Move, null, Direction.Right); 50 Keyboard.Listen(Key.Up, ButtonState.Down, player.Move, null, Direction.Up); 51 Keyboard.Listen(Key.Down, ButtonState.Down, player.Move, null, Direction.Down); 52 27 53 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 28 54 } -
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TiledTileMap.cs
r6536 r6538 11 11 { 12 12 public delegate void ObjectMethod( 13 Vector position, double width, double height, Angle angle, Shape shape, 14 Dictionary<string, string> properties); 13 Vector position, double width, double height, Angle angle, Shape shape, Dictionary<string, string> properties); 15 14 16 public delegate void TileMethod(Vector position, double width, double height, Image image, string layerName); 15 public delegate void TileMethod( 16 Vector position, double width, double height, Image image, string layerName, Dictionary<string, string> properties); 17 17 18 18 private readonly Dictionary<string, ObjectMethod> objectLegend = new Dictionary<string, ObjectMethod>(); … … 82 82 double realX = game.Level.Left + (tile.X * tileWidth) + (tileWidth / 2); 83 83 double realY = game.Level.Top - (tile.Y * tileHeight) - (tileHeight / 2); 84 method(new Vector(realX, realY), tileWidth, tileHeight, tileImages[tileIndex], layer.Name); 84 Dictionary<string,string> props = level.Tilesets[0].Tiles.Where(t => level.Tilesets[0].FirstGid + t.Id == tile.Gid).Select(t => t.Properties).FirstOrDefault(); 85 props = props ?? new Dictionary<string, string>(); 86 method(new Vector(realX, realY), tileWidth, tileHeight, tileImages[tileIndex], layer.Name, props); 85 87 } 86 88 }
Note: See TracChangeset
for help on using the changeset viewer.