/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { tileMap = new TileMap(this, Registry.Lookup<Scenegraph>(), @"Content\main.tmx"); //tileMap.SetScale(new Vector2(2f, 2f)); // tileMap.SetLocalPosition(new Vector2(32, 32)); Console.WriteLine("TM pos= " + tileMap.GetLocalPosition()); playerStartCell = tileMap.GetCellsWithProperty("placement", "Type", "Player")[0]; playerStartCell.Y -= 2; // player movement speed SpriteFont font = Content.Load<SpriteFont>(@"ScreenFont"); player = new JumpingPlayer(font, tileMap, tileMap, GetPlayerImages(), 75); //player = new JumpingPlayer(font, tileMap, tileMap, new SimpleSpriteImage(playerImage), 50); ResetPlayer(); // load level monsters /* Vector2[] monsterCells = tileMap.GetCellsWithProperty("placement", "Type", "MOB"); foreach (Vector2 monsterCell in monsterCells) { int tileIndex = tileMap.GetTileIndex("placement",monsterCell); Dictionary<string, string> monsterProperties = tileMap.GetTileProperties(tileIndex); Monster monster = new Monster(tileMap,tileMap,playerImage, 50f,monsterProperties); monster.SetLocalCellPosition(monsterCell); player.CollidesWith(monster); }*/ // TODO: use this.Content to load your game content here*/ }
public Player(SpriteFont font, TileMap map, SceneObjectParent parent, SpriteImage[] simage, float pixelPerSecSpeed = 0) : base(map, parent, simage, pixelPerSecSpeed) { Vector2 sz = simage[0].GetCurrentImageSize(); SetHandle(new Vector2(sz.X / 2, sz.Y / 2)); Registry.Require<GraphicsDeviceManager>(); gmgr = Registry.Lookup<GraphicsDeviceManager>(); this.font = font; }
public Tank(Game game, SceneObjectParent parent,TileMap tileMap) : base(tileMap,parent,GetImage(game)) { Texture2D tankTurretImage = game.Content.Load<Texture2D>(@"Textures/TankTurret"); tankTurret = new BasicSprite(this, tankTurretImage); this.SetHandle(new Vector2(GetImage(game).Width / 2, GetImage(game).Height / 2)); tankTurret.SetLocalPosition(new Vector2(GetImage(game).Width / 2, GetImage(game).Height / 2)); tankTurret.SetHandle(new Vector2(7, 7)); tankTurret.SetLocalRotation((float)Math.PI / 4); this.tileMap = tileMap; }
/// <summary> /// This is the constructor for a Tank object /// </summary> /// <param name="game">The Game to use to load the assets</param> /// <param name="parent">The parent scene object to make the tank /// a child of</param> /// <param name="tileMap">The tilemap to scroll when we get too close to an edge</param> public Tank(Game game, SceneObjectParent parent,TileMap tileMap) : base(tileMap,parent) { //Load the images of the tank body and turret Texture2D tankBodyImage = game.Content.Load<Texture2D>(@"Textures/TankBody"); Texture2D tankTurretImage = game.Content.Load<Texture2D>(@"Textures/TankTurret"); // Now make the tank body a basicSprite that is a child of the Tank tankBody = new BasicSprite(this, tankBodyImage); // Now make the tank turret a BasicSprite that is a child of the body tankTurret = new BasicSprite(tankBody, tankTurretImage); // set the rotation and translation origin of the tank body at its center tankBody.SetHandle(new Vector2(tankBodyImage.Width / 2, tankBodyImage.Height / 2)); // set the turret's origin at the approximate center of the round part tankTurret.SetHandle(new Vector2(7, 7)); // set the turret's position as being at the center of the tank tankTurret.SetLocalPosition(new Vector2(tankBodyImage.Width / 2, tankBodyImage.Height / 2)); // save the tile map this.tileMap = tileMap; }
public Monster(TileMap map, SceneObjectParent parent, Texture2D image, float moveSpeed, Dictionary<string, string> properties) : base(map,parent,image,moveSpeed) { SetHandle(new Vector2(image.Width/2,image.Height/2)); foreach (string key in properties.Keys) { switch (key) { case "AI": switch (properties[key]) { case "BackAndForth": ai = new BackAndForthAI(this,properties); break; } break; } } }
/// <summary> /// This wil create the tile map and add it to the scenegraph, /// then create the tan kand add it as a child of the tilemap. /// </summary> protected override void LoadContent() { // This creates the tilemap // The first paremeter is a refence to the game, used to load // content // The second parameter is the parent object of the tilemap in // the scenegraph. The scenegraph itself acts as the root parent, // so we fetch it from the registry and pass it in TileMap map = new TileMap(this,Registry.Lookup<Scenegraph>(), @"Content\SampleTileMap.tmx"); // This creates the tank. // The first paremeter is a refence to the game, used to load // content // The second parameter is again the parent object, // in this case the tile map. // The third parameter is the TileMap this tank is on. // (It happens to be the parent but it wont encessarily alwaays be) // The tnak uses this to scroll the map when it gets near an edge Tank tank = new Tank(this,map,map); tank.SetLocalPosition(new Vector2(GraphicsDevice.Viewport.Width/2,GraphicsDevice.Viewport.Height/2)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { TileMap map = new TileMap(this,Registry.Lookup<Scenegraph>(), @"Content\SampleTileMap.tmx"); Tank tank = new Tank(this,map,map); tank.SetLocalPosition(new Vector2(GraphicsDevice.Viewport.Width/2,GraphicsDevice.Viewport.Height/2)); // tank.SetTurretRotation((float)Math.PI / 8); foreach (Vector2 cellPos in map.GetCellsWithProperty("placement", "Item")) { int itemIdx = map.GetTileIndex("placement",cellPos); string itemType = map.GetTileProperties(itemIdx)["Item"]; switch (itemType) { case "Turret": BasicTilemapSprite turret= new BasicTilemapSprite(map,map,Content.Load<Texture2D>(@"Textures/TankTurret")); turret.SetLocalCellPosition(cellPos); tank.CollidesWith(turret); break; } } // TODO: use this.Content to load your game content here }
/// <summary> /// Creates an empty (invisible) BasicTilemapSprite parented to the passed in parent /// </summary> /// /// <param name="map">The tilemap this sprite is a (potentially indirect) child of</param> /// <param name="parent">The parent scene graph object</param> /// <param name="image">The image to draw for the sprite</param> public BasicTilemapSprite(TileMap map, SceneObjectParent parent) : base(parent) { tileMap = map; }
public BasicTilemapSprite(TileMap map, SceneObjectParent parent, SpriteImage simage) : base(parent, simage) { tileMap = map; }
/// <summary> /// Creates a new BasicTilemapSprite parented to the passed in parent /// </summary> /// /// <param name="map">The tilemap this sprite is a (potentially indirect) child of</param> /// <param name="parent">The parent scene graph object</param> /// <param name="image">The image to draw for the sprite</param> public BasicTilemapSprite(TileMap map, SceneObjectParent parent, Texture2D image) : base(parent,image) { tileMap = map; }
public TextSprite(TileMap map, SceneObjectParent parent, SpriteFont font, string text) : base(map,parent) { this.font = font; this.text = text; }
public JumpingPlayer(SpriteFont font, TileMap map, SceneObjectParent parent, SpriteImage[] simage, float pixelPerSecSpeed = 0) : base(font, map, parent, simage, pixelPerSecSpeed) { }
public JumpingPlayer(SpriteFont font, TileMap map, SceneObjectParent parent, Texture2D image, float pixelPerSecSpeed = 0) : base(font, map, parent, new SimpleSpriteImage(image), pixelPerSecSpeed) { }
public MOB(TileMap map, SceneObjectParent parent, SpriteImage simage, float pixelPerSecSpeed = 0) : base(map, parent, simage) { this.pixelPerSecSpeed = pixelPerSecSpeed; }
/// <summary> /// Creates an MOB from the passed in image, parented to the passed in parent, that mvoes at the given speed /// </summary> /// /// <param name="map">The tilemap this sprite is a (potentially indirect) child of</param> /// <param name="parent">The parent scene graph object</param> /// <param name="image">The image to draw for the sprite</param> /// <param name="image">The image to draw for the sprite</param> /// <param name="pixelPerSecSpeed">The movement speed of the MOB</param> public MOB(TileMap map, SceneObjectParent parent, Texture2D image, float pixelPerSecSpeed = 0) : base(map, parent, image) { this.pixelPerSecSpeed = pixelPerSecSpeed; }