public static BitmapData GetBitmapData(String path, bool useCache = false)
 {
     var bitmapData = new BitmapData();
     try
     {
         if (useCache && assetCache.ContainsKey(path))
         {
             bitmapData = (assetCache[path] as BitmapData);
         }
         else
         {
             bitmapData.texture = content.Load<Texture2D>(path);
             if (useCache)
             {
                 assetCache.Add(path, bitmapData);
             }
         }
     }
     catch (ContentLoadException exc)
     {
         Debug.WriteLine(exc);
         return null;
     }
     return bitmapData;
 }
        public Bitmap(BitmapData bitmapData)
        {
            if (bitmapData == null)
                throw new ArgumentNullException("Given BitmapData is null");

            this.bitmapData = bitmapData;
            width = bitmapData.texture.Width;
            height = bitmapData.texture.Height;
            color = Color.White;
        }
Beispiel #3
0
        public override void Load()
        {
            random = new Random();

            background = new GameBackground();
            AddChild(background);
            background.Y += GameMain.ScreenHeight * 0.2f;
            gameContainer = new Sprite();
            AddChild(gameContainer);

            player = new Player();
            player.X = 5 * Level.TILE_SIZE;
            player.Y = 5 * Level.TILE_SIZE;

            objects = new List<MovingObject>();
            objects.Add(player);
            bullets = new List<Bullet>();

            particleTexture = Assets.GetBitmapData("blood");
            particles = new List<Particle>();

            level = new Level(1);

            gameContainer.AddChild(level);

            gameInterface = new GameInterface();
            #if __MOBILE__
            AddChild(gameInterface);
            gameInterface.left.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.right.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.up.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.left.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.right.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.up.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.fire.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            #endif
            inputX = 0;
            inputY = 0;

            tutorText = new TextField();
            tutorText.font = Assets.GetFont("MainFont");
            tutorText.text = "JUMP!!!";
            tutorText.X = (PHYS_BEGIN + 1) * Level.TILE_SIZE;
            tutorText.Y = 5 * Level.TILE_SIZE;

            gameContainer.AddChild(player);

            var zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 5 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 10 * Level.TILE_SIZE;
            zombie.Y = 6 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 11 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            var zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 7 * Level.TILE_SIZE;
            zombie2.Y = 4 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 15 * Level.TILE_SIZE;
            zombie2.Y = 9 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 30 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 32 * Level.TILE_SIZE;
            zombie.Y = 6 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 35 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 40 * Level.TILE_SIZE;
            zombie2.Y = 8 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 55 * Level.TILE_SIZE;
            zombie2.Y = 9 * Level.TILE_SIZE;

            gameContainer.AddChild(tutorText);
        }
Beispiel #4
0
 public Particle(BitmapData bitmapData)
     : base(bitmapData)
 {
     color = new Microsoft.Xna.Framework.Color(0.5f, 0.5f, 0.5f, 1f);
 }