示例#1
0
 // Use this for initialization
 void Start()
 {
     gameManager     = GameObject.FindGameObjectWithTag("Game Manager").GetComponent <GameManager>();
     audioManager    = GameObject.FindGameObjectWithTag("Game Manager").GetComponent <AudioManager>();
     spriteGenerator = GameObject.FindGameObjectWithTag("Sprite Generator").GetComponent <SpriteGenerator>();
     playerMovement  = GetComponent <PlayerMovement>();
 }
        public SpriteGenerator Sprite(String path, String layer, String origin)
        {
            var generator = new SpriteGenerator(layer, origin, path);

            generators.Add(generator);
            return(generator);
        }
示例#3
0
文件: Vic.cs 项目: ddugovic/RASuite
		public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd)
		{
			{
				this.hblankStart = hblankStart;
				this.hblankEnd = hblankEnd;
				this.vblankStart = vblankStart;
				this.vblankEnd = vblankEnd;

				totalCycles = newCycles;
				totalLines = newLines;
				pipeline = newPipeline;
				cyclesPerSec = newCyclesPerSec;

				bufWidth = TimingBuilder_ScreenWidth(pipeline[0], hblankStart, hblankEnd);
				bufHeight = TimingBuilder_ScreenHeight(vblankStart, vblankEnd, newLines);

				buf = new int[bufWidth * bufHeight];
				bufLength = buf.Length;

				sprites = new SpriteGenerator[8];
				for (int i = 0; i < 8; i++)
					sprites[i] = new SpriteGenerator();

				bufferC = new int[40];
				bufferG = new int[40];
			}
		}
示例#4
0
        public static void PostStart() 
		{
            var configuration = SpriteThumbsGlobalConfiguration.Configuration;

            var outputFolder = HostingEnvironment.MapPath("~/App_Data/SpriteThumbsOutput");

            if (outputFolder != null && !Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            configuration.SetSpriteOutputPath(outputFolder);

            foreach (var meme in GlobalMemeConfiguration.Memes.GetMemes())
            {
                configuration.RawImages.Add(new RawImage
                {
                    Id = meme.ImageFileNameWithoutExtension,
                    FullFilePath = HostingEnvironment.MapPath(meme.ImagePath)

                });
            }
			
            var spriteGenerator = new SpriteGenerator(SpriteThumbsGlobalConfiguration.Configuration);

            spriteGenerator.Generate();
        }
示例#5
0
        /// <summary>
        /// Creates a sprite.
        /// ex:
        ///		var sprite = SB.Sprite("s.png", SB.Foreground, SB.Centre);
        /// </summary>
        public static SpriteGenerator Sprite(String path, String layer, String origin)
        {
            var generator = new SpriteGenerator(layer, origin, path);

            GlobalMemory.Instance.RegisterStoryboardGenerator(generator);
            return(generator);
        }
示例#6
0
        public Level(ContentManager content, List <IRoomLayout> worlds, IPlayerObject hero, Dictionary <TextTypes, SpriteFont> spriteFonts, IEffectMusic effects)
        {
            this.effectMusic = effects;
            heroPlayer       = hero;
            this.worlds      = worlds;
            this.content     = content;
            opbouwSprites    = new SpriteGenerator(content);
            this.spriteFonts = spriteFonts;

            #region initialize all lists
            worldsTiles              = new List <List <ITile> >();
            worldsDoors              = new List <List <AStaticObject> >();
            worldsEnemys             = new List <List <AEnemyObject> >();
            worldsMoveEnemys         = new List <List <AEnemyMovement> >();
            worldsCollectables       = new List <List <ICollectableObject> >();
            worldsMoveCollectables   = new List <List <ACollectableMovement> >();
            currMovementEnemy        = new List <AEnemyMovement>();
            CurrMovementCollectables = new List <ACollectableMovement>();
            CurrEnemys      = new List <AEnemyObject>();
            CurrTiles       = new List <ITile>();
            CurrCollectable = new List <ICollectableObject>();
            currDoors       = new List <AStaticObject>();

            #endregion
            AMoveCommandFollowWhenNearby.HeroPlayer = heroPlayer;
            ACollectableMovement.HeroPlayer         = heroPlayer;
        }
示例#7
0
        public static void GenerateGodIconSprites(IOrderedEnumerable <FileInfo> files, string targetFilePathNoExtension)
        {
            var spriteBase = targetFilePathNoExtension;

            Console.WriteLine($"Generating sprite for {files.Count()} files of square size {squareItemSize}...");
            using var bitmap = SpriteGenerator.GenerateForBitmaps(files, squareItemSize);
            bitmap.Save(spriteBase + ".png", ImageFormat.Png);
            bitmap.Save(spriteBase + ".jpg", ImageFormat.Jpeg);

            Console.WriteLine("Writing sprite data files...");
            File.WriteAllText(spriteBase + ".spriteorder", string.Join("\n", files.Select(x => x.Name)) + "\n");
            File.WriteAllText(spriteBase + ".json", @"{""images"":[{" + string.Join("},{", files.Select((x, i) => $@"""name"":""{x.Name}"",""x"":{i * squareItemSize}")) + "}]}");

            Console.WriteLine("Converting sprites to additional image formats...");
            var pWebp = Process.Start("ffmpeg.exe", $@"-hide_banner -y -i ""{spriteBase}.png"" ""{spriteBase}.webp""");

            pWebp.WaitForExit();
            if (pWebp.ExitCode != 0)
            {
                Console.WriteLine($"ERROR: Sprite webp conversion with ffmpeg.exe failed with exit code {pWebp.ExitCode}");
            }

            var pAvif = Process.Start("avifenc.exe", $@"""{spriteBase}.png"" ""{spriteBase}.avif""");

            pAvif.WaitForExit();
            if (pAvif.ExitCode != 0)
            {
                Console.WriteLine($"ERROR: Sprite avif conversion with avifenc.exe failed with exit code {pAvif.ExitCode}");
            }
        }
示例#8
0
        public static void PostStart()
        {
            var configuration = SpriteThumbsGlobalConfiguration.Configuration;

            var outputFolder = HostingEnvironment.MapPath("~/App_Data/SpriteThumbsOutput");

            if (outputFolder != null && !Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            configuration.SetSpriteOutputPath(outputFolder);

            foreach (var meme in GlobalMemeConfiguration.Memes.GetMemes())
            {
                configuration.RawImages.Add(new RawImage
                {
                    Id           = meme.ImageFileNameWithoutExtension,
                    FullFilePath = HostingEnvironment.MapPath(meme.ImagePath)
                });
            }

            var spriteGenerator = new SpriteGenerator(SpriteThumbsGlobalConfiguration.Configuration);

            spriteGenerator.Generate();
        }
示例#9
0
        public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd)
        {
            {
                this.hblankStart = hblankStart;
                this.hblankEnd   = hblankEnd;
                this.vblankStart = vblankStart;
                this.vblankEnd   = vblankEnd;

                totalCycles  = newCycles;
                totalLines   = newLines;
                pipeline     = newPipeline;
                cyclesPerSec = newCyclesPerSec;

                bufWidth  = TimingBuilder_ScreenWidth(pipeline[0], hblankStart, hblankEnd);
                bufHeight = TimingBuilder_ScreenHeight(vblankStart, vblankEnd, newLines);

                buf       = new int[bufWidth * bufHeight];
                bufLength = buf.Length;

                sprites = new SpriteGenerator[8];
                for (int i = 0; i < 8; i++)
                {
                    sprites[i] = new SpriteGenerator();
                }

                bufferC = new int[40];
                bufferG = new int[40];
            }
        }
示例#10
0
 public void Setup()
 {
     _artifacts         = new DirectoryInfo(@"..\..\Artifacts").FullName;
     _generator         = new SpriteGenerator();
     _generator.Saving += SavingEventHandler;
     _generator.Saved  += SavingEventHandler;
 }
示例#11
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates a station. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="factoryTypeName">  Name of the factory type for this Station to use. </param>
        /// <param name="codename">         The Name of the Module with NO SPACES. </param>
        /// <param name="maxStack">         The Maximum you can have of this item in a stack. </param>
        /// <param name="name">             The Spaced Name of your Module. </param>
        /// <param name="desc">             The Description of your Module. </param>
        /// <param name="guidString">       The GUID for this Item. </param>
        /// <param name="iconPath">         Full pathname of the icon file. </param>
        /// <param name="variantname">      The Name of the Variant, Such as Tier1 or Tier2. </param>
        /// <param name="categoryList">     Array of Strings for Categories for the Station Item to be
        ///                                 placed in. </param>
        ///-------------------------------------------------------------------------------------------------

        public void CreateStation(string factoryTypeName, string codename, int maxStack, LocalizedString name, LocalizedString desc, string guidString, string iconPath, string variantname, string[] categoryList)
        {
            FactoryType factoryType = FindFactoryCategories.FindFactoryNames(factoryTypeName);
            Sprite      icon        = SpriteGenerator.GenerateSprite(iconPath);

            RecipeCategory[] categories = GenerateCategories.GenerateCategoryArray(categoryList);
            Station.CreateStation(factoryType, codename, maxStack, name, desc, guidString, icon, variantname, categories);
        }
示例#12
0
 // Use this for initialization
 void Start()
 {
     rB = GetComponent <Rigidbody2D>();
     animationController = GetComponent <PlayerAnimationController>();
     wallKickLeft        = wallKickRight;
     wallKickLeft.x      = -wallKickLeft.x;
     spriteGenerator     = GameObject.FindGameObjectWithTag("Sprite Generator").GetComponent <SpriteGenerator>();
     audioManager        = GameObject.FindGameObjectWithTag("Game Manager").GetComponent <AudioManager>();
 }
示例#13
0
 public AEnemyObject(PigTypes pigType, SpriteGenerator sprites, Vector2 beginPosition, Dictionary <TextTypes, SpriteFont> spriteFonts, int hearts, int attackDamage, MoveTypes moveTypes) : base(pigType, sprites, beginPosition, spriteFonts, moveTypes)
 {
     beginHearts       = hearts;
     beginAttackDamage = attackDamage;
     Attack            = new AttackCommand();
     Hearts            = hearts;
     AttackDamage      = attackDamage;
     CheckSprites();
 }
示例#14
0
 public void Generate()
 {
     using (var fs = new FileStream(WADFilename, FileMode.Open))
     {
         var pal = WADReader.GetPalette(fs, 0);
         var sd  = WADReader.GetPictureSprite(fs, SpriteEntries[TestSpriteIndex]);
         ResultTexture = SpriteGenerator.GenerateSprite(sd, pal);
     }
 }
示例#15
0
        public static void Initialize()
        {
            SpriteDocument.Saving += SpriteSaving;
            SpriteDocument.Saved  += SpriteSaved;

            _generator         = new SpriteGenerator();
            _generator.Saving += SpriteImageSaving;
            _generator.Saved  += SpriteImageSaved;
        }
示例#16
0
        public static AEnemyObject EnemyFactory(PigTypes types, SpriteGenerator opbouwSprites, int oneBlockStep, List <IRoomLayout> worlds, int a, int x, int y, Dictionary <TextTypes, SpriteFont> spriteFonts, int enemyHearts, int enemyAttackDamage)
        {
            var type = Type.GetType("Pigit.Objects.NPCObjects." + types.ToString(), throwOnError: false);

            if (type != null)
            {
                return((AEnemyObject)Activator.CreateInstance(type, opbouwSprites.GetSpritePig(12), new Vector2(y * oneBlockStep, x * oneBlockStep), (MoveTypes)(worlds[a].Enemys[x, y] % 10), spriteFonts, enemyHearts, enemyAttackDamage));
            }
            return(null);
        }
示例#17
0
    IEnumerator FinishLoading()
    {
        SpriteGenerator spriteGen = SpriteGenerator.Instance;

        while (spriteGen.IsLoadingSprites &&
               !TwitterManager.Instance.IsReady)
        {
            yield return(new WaitForSeconds(.1f));
        }

        DynamicBKG.Instance.UpdateFogColor();
        LoadingScreen.Instance.FinishLoading();
    }
示例#18
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates a Module. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="codename">         The Name of the Module with NO SPACES. </param>
        /// <param name="variantname">      The Name of the Variant, Such as Tier1 or Tier2. </param>
        /// <param name="maxstack">         The Maximum you can have of this item in a stack. </param>
        /// <param name="baseitem">         The Item to Base this object off, Pick a Module with the same
        ///                                 Variant. </param>
        /// <param name="name">             The Spaced Name of your Module. </param>
        /// <param name="desc">             The Description of your Module. </param>
        /// <param name="guidstring">       The GUID in String Form for your module. </param>
        /// <param name="categoryname">     The Category in which your Module is in. </param>
        /// <param name="factorytypename">  The Factory Type that is Module is a Part of. </param>
        /// <param name="iconPath">         Full pathname of the icon file. </param>
        /// <param name="categoryList">     Array of Strings for Categories for the Module Item to be
        ///                                 placed in. </param>
        /// <param name="looping">          If you are creating a new FactoryType, This is true for the
        ///                                 first Module in that category, False at all other times. </param>
        ///-------------------------------------------------------------------------------------------------

        public void CreateModule(string codename, string variantname, int maxstack, string baseitem, LocalizedString name, LocalizedString desc, string guidstring, string categoryname, string factorytypename, string iconPath, string[] categoryList, bool looping)
        {
            Sprite icon = SpriteGenerator.GenerateSprite(iconPath);

            RecipeCategory[] categories = GenerateCategories.GenerateCategoryArray(categoryList);
            if (looping)
            {
                Module.CreateProductionModule(codename, variantname, maxstack, baseitem, name, desc, guidstring, categoryname, factorytypename, icon, categories, true);
            }
            else
            {
                Module.CreateProductionModule(codename, variantname, maxstack, baseitem, name, desc, guidstring, categoryname, factorytypename, icon, categories);
            }
        }
示例#19
0
    public static void OpenGeneratorWindow()
    {
        SpriteGenerator newGen = GetWindow <SpriteGenerator>("Sprite Generator");

        newGen.directory        = EditorPrefs.GetString("SG_Directory", newGen.directory);
        newGen.imageResolutionX = EditorPrefs.GetInt("SG_ResolutionX", newGen.imageResolutionX);
        newGen.imageResolutionY = EditorPrefs.GetInt("SG_ResolutionY", newGen.imageResolutionY);
        newGen.perspectiveMode  = EditorPrefs.GetBool("SG_Perspective", newGen.perspectiveMode);
        newGen.fieldOfView      = EditorPrefs.GetFloat("SG_FieldOfView", newGen.fieldOfView);
        newGen.orthoSize        = EditorPrefs.GetFloat("SG_OrthoSize", newGen.orthoSize);
        newGen.lastRenderTime   = EditorApplication.timeSinceStartup;

        newGen.Update();
    }
        public ANPCObject(PigTypes pigType, SpriteGenerator sprites, Vector2 beginPosition, Dictionary <TextTypes, SpriteFont> spriteFonts, MoveTypes moveTypes)
        {
            text = new EnemyText(spriteFonts);
            switch (pigType)
            {
            case PigTypes.Standard:
                this.sprites = sprites.GetSpritePig(12);
                break;

            default:
                break;
            }
            Positie           = beginPosition;
            this.MovementType = moveTypes;
            CheckSprites();
        }
示例#21
0
        protected override void LoadContent()
        {
            keyBoardReader = new KeyBoardReader();
            _spriteBatch   = new SpriteBatch(GraphicsDevice);
            #region add worlds to level1
            levelsWorld1 = new List <IRoomLayout>();
            levelsWorld1.Add(new StartWorldLayout());
            levelsWorld1.Add(new World1Room1Layout());
            levelsWorld1.Add(new World1Room2Layout());
            levelsWorld1.Add(new World1Room3Layout());
            levelsWorld1.Add(new World1Room4Layout());
            #endregion
            #region add menu items to the menus
            startMenuItems = new List <string>
            {
                "Pigit", "Play", "Exit Game", "->"
            };

            pauseMenuItems = new List <string>
            {
                "Pause", "Resume", "Main Menu", "->"
            };

            deadMenuItems = new List <string>
            {
                "Dead", "Main Menu", "Exit Game", "->"
            };

            endMenuItems = new List <string>
            {
                "End", "Main Menu", "Exit Game", "->"
            };
            #endregion
            #region generate
            fontGenerator   = new FontGenerator(Content);
            generateSprites = new SpriteGenerator(Content);
            musicGenerator  = new MusicGenerator(Content);
            #endregion
            InitializeGameObjects();
        }
示例#22
0
文件: Test.cs 项目: WS-QA/cassette
        public void TestSpriting()
        {
            var loader           = new TestLoader();
            var spritingSettings = new SpritingSettings
            {
                SpriteSizeLimit           = 100 * 100,
                SpriteColorLimit          = 4096,
                ImageOptimizationDisabled = true,
                ImageQuantizationDisabled = true
            };
            var generator = new SpriteGenerator(
                new CssImageExtractor(new CssSelectorAnalyzer()),
                path => new SpriteManager(
                    spritingSettings,
                    loader,
                    bytes => "/url",
                    new NullOptimizer()
                    )
                );
            var package = generator.GenerateFromCss(
                ".a { background: url(a.png) no-repeat; width: 10px; height: 10px; }\n" +
                ".b { background: url(b.png) no-repeat; width: 10px; height: 10px; }",
                "/test.css");

            package.Exceptions.ShouldBeEmpty();
            package.GeneratedCss.ShouldEqual(
                ".a { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -0px 0;}\n" +
                ".b { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -11px 0;}"
                );

            var s = new MemoryStream(package.Sprites[0].Image);

            using (var bmp = new Bitmap(s))
            {
                bmp.Width.ShouldEqual(22);
                bmp.Height.ShouldEqual(10);
            }
        }
        public AItemObject(CollectableTypes collectableType, SpriteGenerator sprites, CollectableTypes type, Vector2 positie, MoveTypes movement)
        {
            this.MovementType = movement;

            switch (collectableType)
            {
            case CollectableTypes.BigHeart:
                this.sprites = sprites.GetSpriteBigHeart(6);
                this.Value   = (int)CollectableValues.BigHeart;
                break;

            case CollectableTypes.BigDiamond:
                this.sprites = sprites.GetSpriteBigDiamond(6);
                this.Value   = (int)CollectableValues.BigDiamond;
                break;

            case CollectableTypes.SmallHeart:
                this.sprites = sprites.GetSpriteSmallHeart(6);
                this.Value   = (int)CollectableValues.SmallgHeart;
                break;

            case CollectableTypes.SmallDiamond:
                this.sprites = sprites.GetSpriteSmallDiamond(6);
                this.Value   = (int)CollectableValues.SmallgDiamond;
                break;

            default:
                this.sprites = sprites.GetSpriteSmallHeart(6);
                this.Value   = (int)CollectableValues.SmallgHeart;
                break;
            }
            this.Positie     = positie;
            this.ItemType    = type;
            this.IsCollected = false;
            CheckSprites();
        }
示例#24
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates an item. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="codename">             The Name of the Module with NO SPACES. </param>
        /// <param name="maxstack">             The Maximum you can have of this item in a stack. </param>
        /// <param name="name">                 The Spaced Name of your Module. </param>
        /// <param name="desc">                 The Description of your Module. </param>
        /// <param name="guidstring">           The GUID in String Form for your module. </param>
        /// <param name="recipecategoryname">   The Base Item for your Item. </param>
        /// <param name="iconPath">             Full pathname of the icon file. </param>
        ///-------------------------------------------------------------------------------------------------

        public void CreateItem(string codename, int maxstack, LocalizedString name, LocalizedString desc, string guidstring, string recipecategoryname, string iconPath)
        {
            Sprite icon = SpriteGenerator.GenerateSprite(iconPath);

            Item.CreateItem(codename, maxstack, name, desc, guidstring, recipecategoryname, icon);
        }
示例#25
0
 private void Start()
 {
     //defines the prefabs as something you can use
     generator = FindObjectOfType <SpriteGenerator>();
 }
示例#26
0
		private void Render()
		{
			if (hblankCheckEnableL)
			{
				if (rasterX == hblankEnd)
					hblank = false;
			}
			else if (hblankCheckEnableR)
			{
				if (rasterX == hblankStart)
					hblank = true;
			}

			renderEnabled = (!hblank && !vblank);
			for (int i = 0; i < 4; i++)
			{

				if (delayC > 0)
					delayC--;
				else
					displayC = (srC >> 12) & 0xFFF;


				if (borderCheckLEnable && (rasterX == borderL))
				{
					if (rasterLine == borderB)
						borderOnVertical = true;
					if (rasterLine == borderT && displayEnable)
						borderOnVertical = false;
					if (!borderOnVertical)
						borderOnMain = false;
				}

				switch (videoMode)
				{
					case VicVideoMode.Mode000:
						pixelData = sr & srMask2;
						pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
						break;
					case VicVideoMode.Mode001:
						if ((displayC & 0x800) != 0)
						{
							// multicolor 001
							if ((srSync & srMask2) != 0)
								pixelData = sr & srMask3;

							if (pixelData == 0)
								pixel = backgroundColor0;
							else if (pixelData == srMask1)
								pixel = backgroundColor1;
							else if (pixelData == srMask2)
								pixel = backgroundColor2;
							else
								pixel = (displayC & 0x700) >> 8;
						}
						else
						{
							// standard 001
							pixelData = sr & srMask2;
							pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
						}
						break;
					case VicVideoMode.Mode010:
						pixelData = sr & srMask2;
						pixel = (pixelData != 0) ? (displayC >> 4) : (displayC);
						break;
					case VicVideoMode.Mode011:
						if ((srSync & srMask2) != 0)
							pixelData = sr & srMask3;

						if (pixelData == 0)
							pixel = backgroundColor0;
						else if (pixelData == srMask1)
							pixel = (displayC >> 4);
						else if (pixelData == srMask2)
							pixel = displayC;
						else
							pixel = (displayC >> 8);
						break;
					case VicVideoMode.Mode100:
						pixelData = sr & srMask2;
						if (pixelData != 0)
						{
							pixel = displayC >> 8;
						}
						else
						{
							ecmPixel = (displayC) & 0xC0;
							if (ecmPixel == 0x00)
								pixel = backgroundColor0;
							else if (ecmPixel == 0x40)
								pixel = backgroundColor1;
							else if (ecmPixel == 0x80)
								pixel = backgroundColor2;
							else
								pixel = backgroundColor3;
						}
						break;
					default:
						pixelData = 0;
						pixel = 0;
						break;
				}
				pixel &= 0xF;
				sr <<= 1;
				srSync <<= 1;

				// render sprite
				pixelOwner = null;
				foreach (SpriteGenerator spr in sprites)
				{
					sprData = 0;
					sprPixel = pixel;

					if (spr.x == rasterX)
						spr.shiftEnable = true;

					if (spr.shiftEnable)
					{
						if (spr.multicolor)
						{
							sprData = (spr.sr & srSpriteMaskMC);
							if (spr.multicolorCrunch && spr.xCrunch && !rasterXHold)
								spr.sr <<= 2;
							spr.multicolorCrunch ^= spr.xCrunch;
						}
						else
						{
							sprData = (spr.sr & srSpriteMask);
							if (spr.xCrunch && !rasterXHold)
								spr.sr <<= 1;
						}
						spr.xCrunch ^= spr.xExpand;

						if (sprData != 0)
						{
							// sprite-sprite collision
							if (pixelOwner == null)
							{
								if (!spr.priority || (pixelData == 0))
								{
									if (sprData == srSpriteMask1)
										pixel = spriteMulticolor0;
									else if (sprData == srSpriteMask2)
										pixel = spr.color;
									else if (sprData == srSpriteMask3)
										pixel = spriteMulticolor1;
								}
								pixelOwner = spr;
							}
							else
							{
								if (!borderOnVertical)
								{
									spr.collideSprite = true;
									pixelOwner.collideSprite = true;
								}
							}

							// sprite-data collision
							if (!borderOnVertical && (pixelData < srMask2))
							{
								spr.collideData = true;
							}
						}
						if (spr.sr == 0)
							spr.shiftEnable = false; //optimization
					}
				}

				if (borderCheckREnable && (rasterX == borderR))
					borderOnMain = true;

				// border doesn't work with the background buffer
				if (borderOnMain || borderOnVertical)
					pixel = borderColor;

				// plot pixel if within viewing area
				if (renderEnabled)
				{
					buf[bufOffset] = palette[pixBuffer[pixBufferIndex]];
					bufOffset++;
					if (bufOffset == bufLength)
						bufOffset = 0;
				}

				pixBuffer[pixBufferIndex] = pixel;
				pixBufferIndex++;

				if (!rasterXHold)
					rasterX++;
				bitmapColumn++;
			}

			if (pixBufferIndex >= pixBufferSize)
				pixBufferIndex = 0;
		}
示例#27
0
 public PooledSprite(SpriteGenerator sprite, double endTime)
 {
     this.sprite  = sprite;
     this.endTime = endTime;
 }
示例#28
0
 public void Release(SpriteGenerator sprite, double endTime)
 {
     pooledSprites.Add(new PooledSprite(sprite, endTime));
 }
示例#29
0
        private void Render()
        {
            if (hblankCheckEnableL)
            {
                if (rasterX == hblankEnd)
                {
                    hblank = false;
                }
            }
            else if (hblankCheckEnableR)
            {
                if (rasterX == hblankStart)
                {
                    hblank = true;
                }
            }

            renderEnabled = (!hblank && !vblank);
            for (int i = 0; i < 4; i++)
            {
                if (delayC > 0)
                {
                    delayC--;
                }
                else
                {
                    displayC = (srC >> 12) & 0xFFF;
                }


                if (borderCheckLEnable && (rasterX == borderL))
                {
                    if (rasterLine == borderB)
                    {
                        borderOnVertical = true;
                    }
                    if (rasterLine == borderT && displayEnable)
                    {
                        borderOnVertical = false;
                    }
                    if (!borderOnVertical)
                    {
                        borderOnMain = false;
                    }
                }

                switch (videoMode)
                {
                case VicVideoMode.Mode000:
                    pixelData = sr & srMask2;
                    pixel     = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
                    break;

                case VicVideoMode.Mode001:
                    if ((displayC & 0x800) != 0)
                    {
                        // multicolor 001
                        if ((srSync & srMask2) != 0)
                        {
                            pixelData = sr & srMask3;
                        }

                        if (pixelData == 0)
                        {
                            pixel = backgroundColor0;
                        }
                        else if (pixelData == srMask1)
                        {
                            pixel = backgroundColor1;
                        }
                        else if (pixelData == srMask2)
                        {
                            pixel = backgroundColor2;
                        }
                        else
                        {
                            pixel = (displayC & 0x700) >> 8;
                        }
                    }
                    else
                    {
                        // standard 001
                        pixelData = sr & srMask2;
                        pixel     = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
                    }
                    break;

                case VicVideoMode.Mode010:
                    pixelData = sr & srMask2;
                    pixel     = (pixelData != 0) ? (displayC >> 4) : (displayC);
                    break;

                case VicVideoMode.Mode011:
                    if ((srSync & srMask2) != 0)
                    {
                        pixelData = sr & srMask3;
                    }

                    if (pixelData == 0)
                    {
                        pixel = backgroundColor0;
                    }
                    else if (pixelData == srMask1)
                    {
                        pixel = (displayC >> 4);
                    }
                    else if (pixelData == srMask2)
                    {
                        pixel = displayC;
                    }
                    else
                    {
                        pixel = (displayC >> 8);
                    }
                    break;

                case VicVideoMode.Mode100:
                    pixelData = sr & srMask2;
                    if (pixelData != 0)
                    {
                        pixel = displayC >> 8;
                    }
                    else
                    {
                        ecmPixel = (displayC) & 0xC0;
                        if (ecmPixel == 0x00)
                        {
                            pixel = backgroundColor0;
                        }
                        else if (ecmPixel == 0x40)
                        {
                            pixel = backgroundColor1;
                        }
                        else if (ecmPixel == 0x80)
                        {
                            pixel = backgroundColor2;
                        }
                        else
                        {
                            pixel = backgroundColor3;
                        }
                    }
                    break;

                default:
                    pixelData = 0;
                    pixel     = 0;
                    break;
                }
                pixel   &= 0xF;
                sr     <<= 1;
                srSync <<= 1;

                // render sprite
                pixelOwner = null;
                foreach (SpriteGenerator spr in sprites)
                {
                    sprData  = 0;
                    sprPixel = pixel;

                    if (spr.x == rasterX)
                    {
                        spr.shiftEnable = true;
                    }

                    if (spr.shiftEnable)
                    {
                        if (spr.multicolor)
                        {
                            sprData = (spr.sr & srSpriteMaskMC);
                            if (spr.multicolorCrunch && spr.xCrunch && !rasterXHold)
                            {
                                spr.sr <<= 2;
                            }
                            spr.multicolorCrunch ^= spr.xCrunch;
                        }
                        else
                        {
                            sprData = (spr.sr & srSpriteMask);
                            if (spr.xCrunch && !rasterXHold)
                            {
                                spr.sr <<= 1;
                            }
                        }
                        spr.xCrunch ^= spr.xExpand;

                        if (sprData != 0)
                        {
                            // sprite-sprite collision
                            if (pixelOwner == null)
                            {
                                if (!spr.priority || (pixelData == 0))
                                {
                                    if (sprData == srSpriteMask1)
                                    {
                                        pixel = spriteMulticolor0;
                                    }
                                    else if (sprData == srSpriteMask2)
                                    {
                                        pixel = spr.color;
                                    }
                                    else if (sprData == srSpriteMask3)
                                    {
                                        pixel = spriteMulticolor1;
                                    }
                                }
                                pixelOwner = spr;
                            }
                            else
                            {
                                if (!borderOnVertical)
                                {
                                    spr.collideSprite        = true;
                                    pixelOwner.collideSprite = true;
                                }
                            }

                            // sprite-data collision
                            if (!borderOnVertical && (pixelData < srMask2))
                            {
                                spr.collideData = true;
                            }
                        }
                        if (spr.sr == 0)
                        {
                            spr.shiftEnable = false;                             //optimization
                        }
                    }
                }

                if (borderCheckREnable && (rasterX == borderR))
                {
                    borderOnMain = true;
                }

                // border doesn't work with the background buffer
                if (borderOnMain || borderOnVertical)
                {
                    pixel = borderColor;
                }

                // plot pixel if within viewing area
                if (renderEnabled)
                {
                    buf[bufOffset] = palette[pixBuffer[pixBufferIndex]];
                    bufOffset++;
                    if (bufOffset == bufLength)
                    {
                        bufOffset = 0;
                    }
                }

                pixBuffer[pixBufferIndex] = pixel;
                pixBufferIndex++;

                if (!rasterXHold)
                {
                    rasterX++;
                }
                bitmapColumn++;
            }

            if (pixBufferIndex >= pixBufferSize)
            {
                pixBufferIndex = 0;
            }
        }
 public Enemy(PigTypes pigType, SpriteGenerator sprites, Vector2 beginPosition, MoveTypes moveTypes, Dictionary <TextTypes, SpriteFont> spriteFonts, int hearts = 10, int attackDamage = 1) : base(pigType, sprites, beginPosition, spriteFonts, hearts, attackDamage, moveTypes)
 {
 }
示例#31
0
        /// <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 SpriteBatch(GraphicsDevice);

            // load texture and contents
            messageFont = this.Content.Load <SpriteFont>(MessageFontContentName);
            scoreFont   = this.Content.Load <SpriteFont>(ScoreFontContentName);

            laserTexture      = this.Content.Load <Texture2D>(LaserContentName);
            spaceshipTexture  = this.Content.Load <Texture2D>(SpaceshipContentName);
            enemy4Texture     = this.Content.Load <Texture2D>(Enemy4ContentName);
            explosionTexture  = this.Content.Load <Texture2D>(ExplosionsContentName);
            backgroundTexture = this.Content.Load <Texture2D>(BackgroundContentName);
            starTexture       = this.Content.Load <Texture2D>(ParallaxStarContentName);
            //bgmEffect = this.Content.Load<SoundEffect>(BgmContentName);
            bgmEffect             = this.Content.Load <SoundEffect>(this.settings.BgmSoundEffect);
            explosionSoundEffect  = this.Content.Load <SoundEffect>(ExplosionSoundContentName);
            explosionSound        = explosionSoundEffect.CreateInstance();
            explosionSound.Volume = 1.0F;

            laserSoundEffect  = this.Content.Load <SoundEffect>(LaserSoundContentName);
            laserSound        = laserSoundEffect.CreateInstance();
            laserSound.Volume = 1.0F;

            // create sprites
            spaceshipSprite  = new SpaceshipSprite(spaceshipTexture);
            backgroundSprite = new BackgroundSprite(backgroundTexture, graphics);

            // create sprite generators
            enemyGenerator =
                new SpriteGenerator <EnemySprite>(
                    () =>
                    new EnemySprite(enemy4Texture,
                                    new Vector2(Utils.GetRandomNumber(1, GraphicsDevice.Viewport.Width - enemy4Texture.Width), 1),
                                    Utils.GetRandomNumber(5, 10)), enemyPool, TimeSpan.FromMilliseconds(1000.0F / settings.NumOfEnemiesPerSecond));

            starGenerator =
                new SpriteGenerator <ParallaxStarSprite>(() => new ParallaxStarSprite(starTexture, new Vector2(
                                                                                          Utils.GetRandomNumber(1,
                                                                                                                GraphicsDevice.Viewport.Width - starTexture.Width), 1), Utils.GetRandomNumber(5, 20)), starPool,
                                                         TimeSpan.FromMilliseconds(100));

            gameOverScene = new GameOverScene(this, () => !spaceshipSprite.IsActive, () =>
            {
                this.enemyPool.Clear();
                this.laserPool.Clear();
                this.explosionPool.Clear();

                this.enemyGenerator.IsActive = false;

                if (explosionSound != null && !explosionSound.IsDisposed)
                {
                    explosionSound.Stop(true);
                    explosionSound.Dispose();
                }
                if (laserSound != null && !laserSound.IsDisposed)
                {
                    laserSound.Stop(true);
                    laserSound.Dispose();
                }
                bgmEffect.Dispose();
            })
            {
                IsActive = !settings.LiveForever
            };

            var bgm = bgmEffect.CreateInstance();

            bgm.IsLooped = true;
            bgm.Play();
        }
示例#32
0
        /// <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 SpriteBatch(GraphicsDevice);

            // load texture and contents
            messageFont = this.Content.Load<SpriteFont>(MessageFontContentName);
            scoreFont = this.Content.Load<SpriteFont>(ScoreFontContentName);

            laserTexture = this.Content.Load<Texture2D>(LaserContentName);
            spaceshipTexture = this.Content.Load<Texture2D>(SpaceshipContentName);
            enemy4Texture = this.Content.Load<Texture2D>(Enemy4ContentName);
            explosionTexture = this.Content.Load<Texture2D>(ExplosionsContentName);
            backgroundTexture = this.Content.Load<Texture2D>(BackgroundContentName);
            starTexture = this.Content.Load<Texture2D>(ParallaxStarContentName);
            //bgmEffect = this.Content.Load<SoundEffect>(BgmContentName);
            bgmEffect = this.Content.Load<SoundEffect>(this.settings.BgmSoundEffect);
            explosionSoundEffect = this.Content.Load<SoundEffect>(ExplosionSoundContentName);
            explosionSound = explosionSoundEffect.CreateInstance();
            explosionSound.Volume = 1.0F;

            laserSoundEffect = this.Content.Load<SoundEffect>(LaserSoundContentName);
            laserSound = laserSoundEffect.CreateInstance();
            laserSound.Volume = 1.0F;

            // create sprites
            spaceshipSprite = new SpaceshipSprite(spaceshipTexture);
            backgroundSprite = new BackgroundSprite(backgroundTexture, graphics);

            // create sprite generators
            enemyGenerator =
                new SpriteGenerator<EnemySprite>(
                    () =>
                        new EnemySprite(enemy4Texture,
                            new Vector2(Utils.GetRandomNumber(1, GraphicsDevice.Viewport.Width - enemy4Texture.Width), 1),
                            Utils.GetRandomNumber(5, 10)), enemyPool, TimeSpan.FromMilliseconds(1000.0F/settings.NumOfEnemiesPerSecond));

            starGenerator =
                new SpriteGenerator<ParallaxStarSprite>(() => new ParallaxStarSprite(starTexture, new Vector2(
                    Utils.GetRandomNumber(1,
                        GraphicsDevice.Viewport.Width - starTexture.Width), 1), Utils.GetRandomNumber(5, 20)), starPool,
                    TimeSpan.FromMilliseconds(100));

            gameOverScene = new GameOverScene(this, () => !spaceshipSprite.IsActive, () =>
            {
                this.enemyPool.Clear();
                this.laserPool.Clear();
                this.explosionPool.Clear();

                this.enemyGenerator.IsActive = false;

                if (explosionSound != null && !explosionSound.IsDisposed)
                {
                    explosionSound.Stop(true);
                    explosionSound.Dispose();
                }
                if (laserSound != null && !laserSound.IsDisposed)
                {
                    laserSound.Stop(true);
                    laserSound.Dispose();
                }
                bgmEffect.Dispose();
            }) {IsActive = !settings.LiveForever};

            var bgm = bgmEffect.CreateInstance();
            bgm.IsLooped = true;
            bgm.Play();
        }
示例#33
0
 private void InitializiseSpriteGenerator()
 {
     visualObject = new SpriteGenerator(layer, origin, path);
     // we need to save this object in order to generate the storyboard when all parsing processes finished
     GlobalMemory.Instance.RegisterStoryboardGenerator(visualObject);
 }
示例#34
0
        private void ParseCycle()
        {
            {
                parseaddr  = 0x3FFF;
                parsefetch = pipeline[1][cycleIndex];
                parseba    = pipeline[2][cycleIndex];
                parseact   = pipeline[3][cycleIndex];

                // apply X location
                rasterX     = pipeline[0][cycleIndex];
                rasterXHold = ((parseact & pipelineHoldX) != 0);

                // perform fetch
                parsefetchType = parsefetch & 0xFF00;
                if (parsefetchType == 0x100)
                {
                    // fetch R
                    refreshCounter = (refreshCounter - 1) & 0xFF;
                    parseaddr      = (0x3F00 | refreshCounter);
                    ReadMemory(parseaddr);
                }
                else if (parsefetchType == 0x200)
                {
                    delayC = xScroll;
                    if (!idle)
                    {
                        if (badline)
                        {
                            parseaddr     = (pointerVM | vc);
                            dataC         = ReadMemory(parseaddr);
                            dataC        |= ((int)ReadColorRam(parseaddr) & 0xF) << 8;
                            bufferC[vmli] = dataC;
                        }
                        else
                        {
                            dataC = bufferC[vmli];
                        }
                    }
                    else
                    {
                        dataC         = 0;
                        bufferC[vmli] = dataC;
                    }
                    srC <<= 12;
                    srC  |= dataC;
                }
                else if (parsefetchType == 0x300)
                {
                    // fetch G
                    if (idle)
                    {
                        parseaddr = 0x3FFF;
                    }
                    else
                    {
                        if (bitmapMode)
                        {
                            parseaddr = (rc | (vc << 3) | ((pointerCB & 0x4) << 11));
                        }
                        else
                        {
                            parseaddr = (rc | ((dataC & 0xFF) << 3) | (pointerCB << 11));
                        }
                    }
                    if (extraColorMode)
                    {
                        parseaddr &= 0x39FF;
                    }
                    dataG   = ReadMemory(parseaddr);
                    sr     |= dataG << (7 - xScroll);
                    srSync |= 0xAA << (7 - xScroll);
                    if (!idle)
                    {
                        bufferG[vmli] = dataG;
                        vmli          = (vmli + 1) & 0x3F;
                        vc            = (vc + 1) & 0x3FF;
                    }
                }
                else if (parsefetchType == 0x400)
                {
                    // fetch I
                    parseaddr = (extraColorMode ? 0x39FF : 0x3FFF);
                    dataG     = ReadMemory(parseaddr);
                }
                else if (parsefetchType == 0x500)
                {
                    // fetch none
                }
                else
                {
                    parsecycleFetchSpriteIndex = (parsefetch & 0x7);
                    if ((parsefetch & 0xF0) == 0)
                    {
                        // fetch P
                        parseaddr = (0x3F8 | pointerVM | parsecycleFetchSpriteIndex);
                        sprites[parsecycleFetchSpriteIndex].pointer     = ReadMemory(parseaddr);
                        sprites[parsecycleFetchSpriteIndex].shiftEnable = false;
                    }
                    else
                    {
                        // fetch S
                        if (sprites[parsecycleFetchSpriteIndex].dma)
                        {
                            SpriteGenerator spr = sprites[parsecycleFetchSpriteIndex];
                            parseaddr = (spr.mc | (spr.pointer << 6));
                            spr.sr  <<= 8;
                            spr.sr   |= ReadMemory(parseaddr);
                            spr.mc++;
                        }
                    }
                }

                // perform BA flag manipulation
                if (parseba == 0x0000)
                {
                    pinBA = true;
                }
                else if (parseba == 0x1000)
                {
                    pinBA = !badline;
                }
                else
                {
                    parsecycleBAsprite0 = (parseba & 0x000F);
                    parsecycleBAsprite1 = (parseba & 0x00F0) >> 4;
                    parsecycleBAsprite2 = (parseba & 0x0F00) >> 8;
                    if ((parsecycleBAsprite0 < 8 && sprites[parsecycleBAsprite0].dma) ||
                        (parsecycleBAsprite1 < 8 && sprites[parsecycleBAsprite1].dma) ||
                        (parsecycleBAsprite2 < 8 && sprites[parsecycleBAsprite2].dma))
                    {
                        pinBA = false;
                    }
                    else
                    {
                        pinBA = true;
                    }
                }

                // perform actions
                borderCheckLEnable = ((parseact & (pipelineChkBrdL0 | pipelineChkBrdL1)) != 0);
                borderCheckREnable = ((parseact & (pipelineChkBrdR0 | pipelineChkBrdR1)) != 0);
                hblankCheckEnableL = ((parseact & pipelineHBlankL) != 0);
                hblankCheckEnableR = ((parseact & pipelineHBlankR) != 0);

                if (parseact != 0)
                {
                    if ((parseact & pipelineChkSprCrunch) != 0)
                    {
                        foreach (SpriteGenerator spr in sprites)
                        {
                            if (spr.yCrunch)
                            {
                                spr.mcbase += 2;
                            }
                            spr.shiftEnable      = false;
                            spr.xCrunch          = !spr.xExpand;
                            spr.multicolorCrunch = !spr.multicolor;
                        }
                    }

                    else if ((parseact & pipelineChkSprDisp) != 0)
                    {
                        foreach (SpriteGenerator spr in sprites)
                        {
                            spr.mc = spr.mcbase;
                            if (spr.dma && spr.y == (rasterLine & 0xFF))
                            {
                                spr.display = true;
                            }
                        }
                    }

                    else if ((parseact & pipelineChkSprDma) != 0)
                    {
                        foreach (SpriteGenerator spr in sprites)
                        {
                            if (spr.enable && spr.y == (rasterLine & 0xFF) && !spr.dma)
                            {
                                spr.dma     = true;
                                spr.mcbase  = 0;
                                spr.yCrunch = !spr.yExpand;
                            }
                        }
                    }

                    else if ((parseact & pipelineChkSprExp) != 0)
                    {
                        foreach (SpriteGenerator spr in sprites)
                        {
                            if (spr.yExpand)
                            {
                                spr.yCrunch ^= true;
                            }
                        }
                    }

                    else if ((parseact & pipelineUpdateMcBase) != 0)
                    {
                        foreach (SpriteGenerator spr in sprites)
                        {
                            if (spr.yCrunch)
                            {
                                spr.mcbase++;
                                if (spr.mcbase == 63)
                                {
                                    spr.dma     = false;
                                    spr.display = false;
                                }
                            }
                        }
                    }

                    else if ((parseact & pipelineUpdateRc) != 0)
                    {
                        if (rc == 7)
                        {
                            idle   = true;
                            vcbase = vc;
                        }
                        if (!idle)
                        {
                            rc = (rc + 1) & 0x7;
                        }
                    }

                    else if ((parseact & pipelineUpdateVc) != 0)
                    {
                        vc   = vcbase;
                        vmli = 0;
                        if (badline)
                        {
                            rc = 0;
                        }
                    }
                }

                cycleIndex++;
            }
        }