Exemple #1
0
        internal static PaletteID ToFruitPalette(this GraphicsID id)
        {
            switch (id)
            {
            default:
                throw new Exception("Unhandled GraphicsID.");

            case GraphicsID.SpriteCherry:
                return(PaletteID.Cherry);

            case GraphicsID.SpriteStrawberry:
                return(PaletteID.Strawberry);

            case GraphicsID.SpriteOrange:
                return(PaletteID.Orange);

            case GraphicsID.SpriteApple:
                return(PaletteID.Apple);

            case GraphicsID.SpriteMelon:
                return(PaletteID.Melon);

            case GraphicsID.SpriteGalaxian:
                return(PaletteID.Galaxian);

            case GraphicsID.SpriteBell:
                return(PaletteID.Bell);

            case GraphicsID.SpriteKey:
                return(PaletteID.Key);
            }
        }
Exemple #2
0
 internal void SetStaticSprite(GameObject obj, GraphicsID id, PaletteID palette, Bitmap source, int width)
 {
     gameObjectMap[obj] = new StaticSprite(source, id, width, source.Width / width)
     {
         Palette = palette
     };
 }
 public void DrawSprite(int x, int y, GraphicsID spriteSheet, int spriteIndex)
 {
     DrawSprite(
         x, y,
         _sprite_sheets[spriteSheet].SpriteWidth, _sprite_sheets[spriteSheet].SpriteHeight,
         spriteSheet,
         spriteIndex
         );
 }
 public void DrawSprite(Point center, Point size, Point camera, GraphicsID spriteSheet, int spriteIndex)
 {
     DrawSprite(
         (center.X - size.X / 2) - (int)camera.X,
         (center.Y - size.Y / 2) - (int)camera.Y,
         size.X,
         size.Y,
         spriteSheet,
         spriteIndex
         );
 }
        public void DrawScene(GraphicsID backgroundTile, Point backgroundOffset, Action drawScene)
        {
            // render scene

            _graphics_device.SetRenderTarget(_render_target);
            _graphics_device.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.None
            };

            DrawTiledSprite(0, 0, Width, Height, backgroundTile, backgroundOffset.X, backgroundOffset.Y);

            drawScene();

            DrawBufferToScreen();
        }
Exemple #6
0
        internal FruitObject(GraphicsHandler handler, GraphicsID spriteID)
            : base(GraphicsConstants.SpriteSize)
        {
            sprite = new StaticSprite(Resources.Sprites, spriteID, GraphicsConstants.SpriteWidth, Resources.Sprites.Width / GraphicsConstants.SpriteWidth)
            {
                Palette = spriteID.ToFruitPalette()
            };
            handler.Register(this, sprite);
            switch (spriteID)
            {
            default:
                throw new Exception("Unhandled GraphicsID.");

            case GraphicsID.SpriteCherry:
                Score = 100;
                break;

            case GraphicsID.SpriteStrawberry:
                Score = 300;
                break;

            case GraphicsID.SpriteOrange:
                Score = 500;
                break;

            case GraphicsID.SpriteApple:
                Score = 700;
                break;

            case GraphicsID.SpriteMelon:
                Score = 1000;
                break;

            case GraphicsID.SpriteGalaxian:
                Score = 2000;
                break;

            case GraphicsID.SpriteBell:
                Score = 3000;
                break;

            case GraphicsID.SpriteKey:
                Score = 5000;
                break;
            }
        }
        private void LoadSprite(GraphicsID spriteSheetID, GraphicsMeta meta)
        {
            _sprite_sheets.Add(
                spriteSheetID,
                new SpriteSheet(
                    _content_manager.Load <Texture2D>("Graphics/" + spriteSheetID.ToString().Replace('_', '/')),
                    meta.SpriteWidth, meta.SpriteHeight,
                    new BasicEffect(_graphics_device)
            {
                World      = Matrix.Identity,
                View       = _view_matrix,
                Projection = _projection_matrix,
            }
                    )
                );

            LoadProgress++;
        }
        public void DrawTiledSprite(int x, int y, int width, int height, GraphicsID spriteSheet, float offsetX, float offsetY)
        {
            int spriteWidth  = _sprite_sheets[spriteSheet].SpriteWidth;
            int spriteHeight = _sprite_sheets[spriteSheet].SpriteHeight;

            foreach (EffectPass pass in _sprite_sheets[spriteSheet].Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _graphics_device.DrawUserPrimitives(PrimitiveType.TriangleStrip, new VertexPositionTexture[]
                {
                    new VertexPositionTexture(new Vector3(x, y, 0), new Vector2(offsetX, offsetY)),
                    new VertexPositionTexture(new Vector3(x + width, y, 0), new Vector2(offsetX + (float)width / spriteWidth, offsetY)),
                    new VertexPositionTexture(new Vector3(x, y + height, 0), new Vector2(offsetX, offsetY + (float)height / spriteHeight)),
                    new VertexPositionTexture(new Vector3(x + width, y + height, 0), new Vector2(offsetX + (float)width / spriteWidth, offsetY + (float)height / spriteHeight)),
                }, 0, 2, VertexPositionTexture.VertexDeclaration);
            }
        }
        public void DrawSprite(int x, int y, int width, int height, GraphicsID spriteSheet, int spriteIndex)
        {
            int spriteX = spriteIndex % _sprite_sheets[spriteSheet].Columns;
            int spriteY = spriteIndex / _sprite_sheets[spriteSheet].Columns;

            float spriteXWidth  = 1 / (float)_sprite_sheets[spriteSheet].Columns;
            float spriteYHeight = 1 / (float)_sprite_sheets[spriteSheet].Rows;

            float spriteXOffset = spriteX * spriteXWidth;
            float spriteYOffset = spriteY * spriteYHeight;

            foreach (EffectPass pass in _sprite_sheets[spriteSheet].Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _graphics_device.DrawUserPrimitives(PrimitiveType.TriangleStrip, new VertexPositionTexture[]
                {
                    new VertexPositionTexture(new Vector3(x, y, 0), new Vector2(spriteXOffset, spriteYOffset)),
                    new VertexPositionTexture(new Vector3(x + width, y, 0), new Vector2(spriteXOffset + spriteXWidth, spriteYOffset)),
                    new VertexPositionTexture(new Vector3(x, y + height, 0), new Vector2(spriteXOffset, spriteYOffset + spriteYHeight)),
                    new VertexPositionTexture(new Vector3(x + width, y + height, 0), new Vector2(spriteXOffset + spriteXWidth, spriteYOffset + spriteYHeight)),
                }, 0, 2, VertexPositionTexture.VertexDeclaration);
            }
        }
Exemple #10
0
 internal void SetStaticSprite(GameObject obj, GraphicsID id, PaletteID palette)
 => SetStaticSprite(obj, id, palette, Resources.Sprites, GraphicsConstants.SpriteWidth);
Exemple #11
0
 internal static Rectangle GetGraphicSourceRectangle(GraphicsID id, int width, int sourceTilesPerRow)
 {
     return(new Rectangle(new Point((int)id % sourceTilesPerRow * width, (int)id / sourceTilesPerRow * width), new Size(width, width)));
 }
Exemple #12
0
 internal StaticSprite(Bitmap source, GraphicsID graphicsId, int width, int sourceTilesPerRow)
 {
     sourceImage  = source.Clone(GraphicsUtils.GetGraphicSourceRectangle(graphicsId, width, sourceTilesPerRow), source.PixelFormat);
     currentImage = sourceImage;
 }
 public int SpriteCount(GraphicsID spriteSheet)
 {
     return(_sprite_sheets[spriteSheet].Columns * _sprite_sheets[spriteSheet].Rows);
 }
 public Point SpriteSize(GraphicsID spriteSheet)
 {
     return(new Point(_sprite_sheets[spriteSheet].SpriteWidth, _sprite_sheets[spriteSheet].SpriteHeight));
 }
 public void DrawSprite(double centerX, double centerY, Point size, Point camera, GraphicsID spriteSheet, int spriteIndex)
 {
     DrawSprite(
         (int)(centerX - size.X / 2) - camera.X,
         (int)(centerY - size.Y / 2) - camera.Y,
         size.X,
         size.Y,
         spriteSheet,
         spriteIndex
         );
 }