public MapBackground(Size mapSize, Size tileSize) { IsSelectable = false; // * Opret en statisk baggrund baseret på de forskellige tiles der er til rådighed string tempFile = GameController.imageRoot + "/bg.png"; if (File.Exists(tempFile) == false) { Bitmap bgBitmap = new Bitmap(mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height); Graphics graphic = Graphics.FromImage(bgBitmap); // * Lav ét stort billede istedet for mange små -> meget bedre performance Random rand = new Random(); int bitmapTileWidth = 24, bitmapTileHeight = 24; for (int y = 0; y < mapSize.Height; y++) { for (int x = 0; x < mapSize.Width; x++) { graphic.DrawImage( new Bitmap(GameController.imageRoot + "/tiles/green/" + rand.Next(1, 16) + ".png"), x * tileSize.Width, y * tileSize.Height, bitmapTileWidth, bitmapTileHeight ); // * Lav lidt huller i jorden, så det ser federe ud, 1/20 chance per tile if (rand.Next(1, 20) == 1) { string path = String.Format(GameController.imageRoot + "/craters/cr1 {0:000}.png", rand.Next(0, 4)); graphic.DrawImage( new Bitmap(path), x * tileSize.Width, y * tileSize.Height, bitmapTileWidth, bitmapTileHeight ); } } } bgBitmap.Save(tempFile, System.Drawing.Imaging.ImageFormat.Png); } SpriteFrame bgFrame = new SpriteFrame( new SpriteImage(tempFile, Color.FromArgb(255, 255, 255)), 1); GameSprite bgSprite = new GameSprite(); bgSprite.AddFrame(bgFrame); AddSprite("background", bgSprite); SetSprite("background"); // * Som udgangs er starter et map selvf. i (0, 0) this.WorldPosition = new Point(0, 0); this.ZIndex = Int32.MinValue; // * Forsøg altid at ligge bagerst }
// * Indlæser diverse animationer STATISK (kaldes af GameController) så de ikke genindlæses i hver instans public static void InitializeGraphics() { Animations = new Dictionary <string, GameSprite>(); string imageRoot = GameController.imageRoot + "/jeep"; // * Flydende bevægelsesanimationer for en jeep List <string> directionDirs = new List <string>(8); directionDirs.Add("up-upright"); directionDirs.Add("upright-right"); directionDirs.Add("right-downright"); directionDirs.Add("downright-down"); directionDirs.Add("down-downleft"); directionDirs.Add("downleft-left"); directionDirs.Add("left-upleft"); directionDirs.Add("upleft-up"); foreach (string direction in directionDirs) { GameSprite moveSprite = new GameSprite(); List <GameSprite> sprites = new List <GameSprite>(); for (int i = 1; i <= 5; i++) { string imagePath = imageRoot + "/" + direction + "/jeep " + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); moveSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("drive_" + direction, moveSprite); } }
// * Indlæser diverse animationer STATISK (kaldes af GameController) så de ikke genindlæses i hver instans public static void InitializeGraphics() { Animations = new Dictionary <string, GameSprite>(); string barracksRoot = GameController.imageRoot + "/barracks"; GameSprite constructSprite = new GameSprite(); constructSprite.RepeatCount = 0; for (int i = 0; i <= 12; i++) { string imagePath = barracksRoot + "/make/barrmake " + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); constructSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404"); } } Animations.Add("make", constructSprite); }
// * Indlæser diverse animationer STATISK (kaldes af GameController) så de ikke genindlæses i hver instans public static void InitializeGraphics() { Animations = new Dictionary <string, GameSprite>(); string rifleRoot = GameController.imageRoot + "/rifle_infantry"; List <string> directionDirs = new List <string>(8); directionDirs.Add("up"); directionDirs.Add("upright"); directionDirs.Add("right"); directionDirs.Add("downright"); directionDirs.Add("down"); directionDirs.Add("downleft"); directionDirs.Add("left"); directionDirs.Add("upleft"); foreach (string direction in directionDirs) { GameSprite runSprite = new GameSprite(); List <GameSprite> sprites = new List <GameSprite>(); for (int i = 1; i <= 6; i++) { string imagePath = rifleRoot + "/run/" + direction + "/" + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); runSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("run_" + direction, runSprite); } GameSprite dieSprite = new GameSprite(); // * Gentag ikke, afspil kun død én gang, // * hvorefter IsDonePlaying angiver om vi officielt kan slette enheden dieSprite.RepeatCount = 0; for (int i = 1; i <= 7; i++) { string imagePath = rifleRoot + "/die/right/" + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); dieSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("die_right", dieSprite); GameSprite standSprite = new GameSprite(); for (int i = 1; i <= 1; i++) { string imagePath = rifleRoot + "/stand/right.png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); standSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("stand_right", standSprite); foreach (string direction in directionDirs) { GameSprite attackSprite = new GameSprite(); attackSprite.RepeatCount = 0; for (int i = 1; i <= 8; i++) { string imagePath = rifleRoot + "/attack/" + direction + "/" + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); attackSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("attack_" + direction, attackSprite); } GameSprite piffSprite = new GameSprite(); piffSprite.RepeatCount = 0; for (int i = 0; i <= 3; i++) { string imagePath = GameController.resourceRoot + "/images/gunfire/piffpiff " + i + ".png"; if (File.Exists(imagePath)) { SpriteImage spriteImg = new SpriteImage(imagePath, Color.Transparent); SpriteFrame spriteFrame = new SpriteFrame(spriteImg, 5); piffSprite.AddFrame(spriteFrame); } else { throw new FileNotFoundException("404 on " + imagePath); } } Animations.Add("piff", piffSprite); }