public void DrawLine(Vector2 a, Vector2 b, int thickness, Color color) { Vector2 start; Vector2 end; if (a.X < b.X) { start = a; end = b; } else { start = b; end = a; } float angle = (float)Math.Atan2((double)(end.Y - start.Y), (double)(end.X - start.X)); //this.Draw(GraphicsDispenser.getTexture("pixel_bmp"), start, new Vector2(a.X + (b - a).Length, a.Y) this.Draw(GraphicsDispenser.getTexture("pixel_bmp") //, new Rectangle(start.X, start.Y, (int)((end - start).Length()), start.Y) , new Rectangle((int)start.X , (int)start.Y , (int)((end - start).Length()) , thickness) , null , color , angle , Vector2.Zero , SpriteEffects.None , 0f); }
protected void LoadData() { player = new Player(new Vector2(0, 0), "player_bmp"); player.Graphic.Texture = GraphicsDispenser.getTexture("player_bmp"); player.AddSkill(new Skill(SkillNames.MEDICAL_SKILL)); player.Inventory.Add(ItemFactory.CreateDefaultItem()); player.Inventory.Add(ItemFactory.CreateDefaultItem()); player.Inventory.Add(ItemFactory.CreateDefaultItem()); player.Inventory.Add(ItemFactory.CreateBandage(player)); player.Inventory.Add(ItemFactory.CreateBandage(player)); Weapon sword2 = WeaponFactory.CreateSword(); sword2.Name = "OTHER Sword"; player.Inventory.Add(sword2); player.Inventory.Add(WeaponFactory.CreateSword()); map = new Map(80, 80); map.GetBlockAt(5, 5).AddObject(player); MapGenerator.map = map; MapGenerator.CreateWoodenBuilding(10, 10, 30, 30); Light l = new Light(80, Color.Blue); map.AddObjectAt(l, 21, 23); Door d = new Door("door_closed_bmp"); d.Interaction = new UseDoorPAbility(d); map.GetBlockAt(5, 10).AddObject(d); camera = new Camera(player, Game.VISBLE_MAP_WIDTH, Game.VISBLE_MAP_HEIGHT, map); Zombie z = EntityFactory.CreateZombie(player); z.ChangeStateTo(ZombieStateNames.SEARCH_STATE, player.Location); entities.Add(z); map.GetBlockAt(6, 6).AddObject(z); MapGenerator.PutZombiesEverywhere(100, player); Item item = new Item("item_bmp"); map.GetBlockAt(3, 3).AddObject(item); MessageBus.Instance.AddMessage(new DominatingMessage(player, z, item)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { Logger.Log("Loading Content"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new ZSpriteBatch(GraphicsDevice); GraphicsDispenser.LoadTextureData(Content); GraphicsDispenser.LoadFontData(Content); MessageLog.Font = GraphicsDispenser.GetFont("MessageBarFont"); LoadData(); StateFactory.Init(this); this.AddState(StateFactory.CreatePlayState(camera)); }
public Game() : base() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1024; graphics.PreferredBackBufferHeight = 768; graphics.ApplyChanges(); GraphicsDispenser.initialize(); //inputHandler = InputHandler.Instance; Content.RootDirectory = "Content"; entities = new List <Entity>(); states = new LinkedList <GameState>(); this.IsMouseVisible = true; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new ZSpriteBatch(GraphicsDevice); DirectoryInfo di = new DirectoryInfo(Content.RootDirectory); foreach (FileInfo fi in di.GetFiles("*_bmp.xnb")) { GraphicsDispenser.addTexture(fi.Name.Remove(fi.Name.Length - 4), Content.Load <Texture2D>(Content.RootDirectory + "/" + fi.Name.Remove(fi.Name.Length - 4))); } font = Content.Load <SpriteFont>("Courier New"); GraphicsDispenser.AddFont("Courier New", font); GraphicsDispenser.AddFont("Default", font); MessageLog.Font = font; LoadData(); StateFactory.Init(this); this.AddState(StateFactory.CreatePlayState(camera)); }
/// <summary> /// Render map centered on focus with line of sight /// </summary> public void Draw(ZSpriteBatch spriteBatch) { UpdateLoS(); // draw map for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { //spriteBatch.Draw(map.GetBlockAt(x, y).Graphic.Texture, new Vector2(x * Game.MAP_BLOCK_SIZE, y * Game.MAP_BLOCK_SIZE), Color.White); //player.Location.Coordinates.X + x, y); //Coord coord = new Coord(focus.Location.Coordinates.X + x - Game.VISIBLE_MAP_OFFSET, focus.Location.Coordinates.Y + y - Game.VISIBLE_MAP_OFFSET); Coord coord = this[x, y]; int r = GameMap.LightMap[x, y].R; if (map.IsInMap(coord) && visiblePositions[x, y]) { Texture2D texture = map.GetBlockAt(coord).Graphic.Texture; spriteBatch.Draw(texture, new Rectangle(x * Game.MAP_BLOCK_SIZE, y * Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE), GameMap.LightMap[coord.X, coord.Y]); } else if (map.IsInMap(coord)) { Texture2D texture = map.GetBlockAt(coord).Graphic.Texture; spriteBatch.DrawRectangle(x * Game.MAP_BLOCK_SIZE, y * Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE, Color.Gray); //spriteBatch.Draw(texture, // new Rectangle(x * Game.MAP_BLOCK_SIZE, y * Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE), // Color.White); } else { spriteBatch.Draw(GraphicsDispenser.getTexture("void_bmp"), new Rectangle(x * Game.MAP_BLOCK_SIZE, y * Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE, Game.MAP_BLOCK_SIZE), Color.White); } } } this.ResetVision(); }
public Sprite(string nImgLoc) { imgLoc = nImgLoc; texture = GraphicsDispenser.GetTexture(nImgLoc); }