Exemplo n.º 1
0
Arquivo: FxPool.cs Projeto: fengqk/Art
	void OnFxLifeEnd(GFX fx)
	{
		pool.RecyclePrefabInstance(fx.transform);
	}
Exemplo n.º 2
0
        public override void Render()
        {
            GameplayRenderer.End();

            // render the edges of the lava rect.
            if (dirty)
            {
                Vector2 zero = Vector2.Zero;

                Vector2 topLeft     = zero;
                Vector2 topRight    = new Vector2(zero.X + Width, zero.Y);
                Vector2 bottomLeft  = new Vector2(zero.X, zero.Y + Height);
                Vector2 bottomRight = zero + new Vector2(Width, Height);

                Vector2 fadeOffset = new Vector2(Math.Min(Fade, Width / 2f), Math.Min(Fade, Height / 2f));
                vertCount = 0;
                if (OnlyMode == OnlyModes.OnlyLeft)
                {
                    Edge(ref vertCount, topRight, bottomRight, fadeOffset.X);
                    Quad(ref vertCount, topLeft, topRight - new Vector2(fadeOffset.X, 0f), bottomRight - new Vector2(fadeOffset.X, 0f), bottomLeft, CenterColor);
                }
                else if (OnlyMode == OnlyModes.OnlyRight)
                {
                    Edge(ref vertCount, bottomLeft, topLeft, fadeOffset.X);
                    Quad(ref vertCount, topLeft + new Vector2(fadeOffset.X, 0f), topRight, bottomRight, bottomLeft + new Vector2(fadeOffset.X, 0f), CenterColor);
                }

                dirty = false;
            }

            // render the vertices
            Camera camera = (Scene as Level).Camera;

            GFX.DrawVertices(Matrix.CreateTranslation(new Vector3(Entity.Position + Position, 0f)) * camera.Matrix, verts, vertCount);

            GameplayRenderer.Begin();

            Vector2 rectPosition = Entity.Position + Position;

            // render bubbles
            MTexture bubbleTexture = GFX.Game["particles/bubble"];

            for (int i = 0; i < bubbles.Length; i++)
            {
                bubbleTexture.DrawCentered(rectPosition + bubbles[i].Position, SurfaceColor * bubbles[i].Alpha);
            }

            // render surface bubbles
            for (int j = 0; j < surfaceBubbles.Length; j++)
            {
                if (surfaceBubbles[j].Y >= 0f)
                {
                    MTexture surfaceBubbleTexture = surfaceBubbleAnimations[surfaceBubbles[j].Animation][(int)surfaceBubbles[j].Frame];
                    int      bubbleOffset         = (int)(surfaceBubbles[j].Y / SurfaceStep);

                    float x;
                    if (OnlyMode == OnlyModes.OnlyLeft)
                    {
                        x = Width + 7f + Wave(bubbleOffset, Height);
                    }
                    else
                    {
                        x = 1f - Wave(bubbleOffset, Height);
                    }

                    surfaceBubbleTexture.DrawJustified(rectPosition +
                                                       new Vector2(x, OnlyMode == OnlyModes.OnlyRight ? Height - bubbleOffset * SurfaceStep : bubbleOffset * SurfaceStep),
                                                       new Vector2(1f, 0.5f), SurfaceColor);
                }
            }
        }
Exemplo n.º 3
0
        public void onMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isLeftPress = true;
            }
            else
            {
                isLeftPress = false;
            }

            for (int i = 0; i < scene.ow.allentrances.Length; i++)
            {
                EntranceOWEditor en = scene.ow.allentrances[i];
                if (en.mapId >= scene.ow.worldOffset && en.mapId < 64 + scene.ow.worldOffset)
                {
                    if (e.X >= en.x && e.X < en.x + 16 && e.Y >= en.y && e.Y < en.y + 16)
                    {
                        if (scene.mouse_down == false)
                        {
                            if (e.Button == MouseButtons.Left)
                            {
                                selectedEntrance     = en;
                                lastselectedEntrance = en;
                                scene.mouse_down     = true;
                            }
                            else if (e.Button == MouseButtons.Right)
                            {
                                lastselectedEntrance = en;
                                scene.mouse_down     = true;
                                mxRightclick         = (e.X);
                                myRightclick         = (e.Y);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < scene.ow.allholes.Length; i++)
            {
                EntranceOWEditor en = scene.ow.allholes[i];
                if (en.mapId >= scene.ow.worldOffset && en.mapId < 64 + scene.ow.worldOffset)
                {
                    if (e.X >= en.x && e.X < en.x + 16 && e.Y >= en.y && e.Y < en.y + 16)
                    {
                        if (scene.mouse_down == false)
                        {
                            if (e.Button == MouseButtons.Left)
                            {
                                selectedEntrance     = en;
                                lastselectedEntrance = en;
                                scene.mouse_down     = true;
                            }
                            else if (e.Button == MouseButtons.Right)
                            {
                                lastselectedEntrance = en;
                                scene.mouse_down     = true;
                                mxRightclick         = (e.X);
                                myRightclick         = (e.Y);
                            }
                        }
                    }
                }
            }

            if (selectedEntrance != null)
            {
                //scene.owForm.thumbnailBox.Visible = true;
                //scene.owForm.thumbnailBox.Size = new Size(256, 256);
                int roomId = DungeonsData.entrances[selectedEntrance.entranceId].Room;
                if (roomId >= 296)
                {
                    //scene.owForm.thumbnailBox.Visible = false;
                    return;
                }

                if (scene.mainForm.lastRoomID != roomId)
                {
                    scene.mainForm.previewRoom = DungeonsData.all_rooms[roomId];
                    scene.mainForm.previewRoom.reloadGfx();
                    GFX.loadedPalettes = GFX.LoadDungeonPalette(scene.mainForm.previewRoom.palette);
                    scene.mainForm.DrawRoom();
                    DrawTempEntrance();
                    scene.entrancePreview = true;
                    //scene.Refresh();

                    if (scene.mainForm.activeScene.room != null)
                    {
                        GFX.loadedPalettes = GFX.LoadDungeonPalette(scene.mainForm.activeScene.room.palette);
                        scene.mainForm.activeScene.room.reloadGfx();
                        scene.mainForm.activeScene.DrawRoom();
                    }
                }

                scene.mainForm.lastRoomID = roomId;
            }
        }
Exemplo n.º 4
0
        public void Draw()
        {
            var darkTitleRect = new Rectangle(MenuRect.X + DbgMenuTopLeftButtonRect.Width, MenuRect.Y, MenuRect.Width - DbgMenuTopLeftButtonRect.Width, DbgMenuTopLeftButtonRect.Height);


            GFX.SpriteBatchBeginForText();

            var clickMeSize = DBG.DEBUG_FONT_SMALL.MeasureString("MENU");

            GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE, DbgMenuTopLeftButtonRect, Color.Black * 0.85f);

            GFX.SpriteBatch.DrawString(DBG.DEBUG_FONT_SMALL, "MENU", DbgMenuTopLeftButtonRect.Center(), Color.White, 0, clickMeSize / 2, 1, SpriteEffects.None, 0);

            if (MenuOpenState == DbgMenuOpenState.Closed)
            {
                GFX.SpriteBatchEnd();
                return;
            }

            UpdateUI();

            float menuBackgroundOpacityMult = MenuOpenState == DbgMenuOpenState.Open ? 1.0f : 0f;

            // Draw menu background rect

            //---- Full Background
            GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE, SubMenuRect, Color.Black * 0.5f * menuBackgroundOpacityMult);
            //---- Slightly Darker Part On Top
            GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE, darkTitleRect,
                                 Color.Black * 0.75f * menuBackgroundOpacityMult);

            if (MenuOpenState == DbgMenuOpenState.Open)
            {
                var renderPauseStr      = $"Render Pause:{(IsPauseRendering ? "Active" : "Inactive")}\n(Click RS / Press Pause Key)";
                var renderPauseStrScale = DBG.DEBUG_FONT.MeasureString(renderPauseStr);
                var renderPauseStrColor = !IsPauseRendering ? Color.White : Color.Yellow;

                DBG.DrawOutlinedText(renderPauseStr,
                                     new Vector2(8, GFX.Device.Viewport.Height - 20),
                                     renderPauseStrColor, DBG.DEBUG_FONT, scaleOrigin: new Vector2(0, renderPauseStrScale.Y),
                                     //scale: IsPauseRendering ? 1f : 0.75f,
                                     startAndEndSpriteBatchForMe: false);
            }

            // Draw name on top
            var sb = new StringBuilder();

            //---- If in submenu, append the stack of menues preceding this one
            if (DbgMenuStack.Count > 0)
            {
                bool first = true;
                foreach (var chain in DbgMenuStack.Reverse())
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(" > ");
                    }
                    sb.Append($"{chain.Text}{(chain.Items.Count > 0 ? $" ({chain.Items.Count})" : "")}");
                }
                sb.Append(" > ");
            }
            //---- Append the current menu name.
            sb.Append($"{Text}{(Items.Count > 0 ? $" ({Items.Count})" : "")}");

            //---- Draw full menu name
            DBG.DrawOutlinedText(sb.ToString(), darkTitleRect.TopLeftCorner() + new Vector2(8, 4),
                                 CustomColorFunction?.Invoke() ?? Color.White, DBG.DEBUG_FONT, startAndEndSpriteBatchForMe: false);

            if (Items.Count != 0)
            {
                if (SelectedIndex < 0)
                {
                    SelectedIndex = 0;
                }
                else if (SelectedIndex >= Items.Count)
                {
                    SelectedIndex = Items.Count - 1;
                }

                var selectedItemRect = GetItemDisplayRect(SelectedIndex, SubMenuRect);

                if (Items.Count != prevFrameItemCount)
                {
                    menuHeight = GetEntireMenuHeight();
                }

                // Only need to calculate scroll stuff if there's text that reaches past the bottom.
                if (menuHeight > SubMenuRect.Height)
                {
                    // Scroll selected into view.

                    //---- If item is ABOVE view
                    if (selectedItemRect.Top < SubMenuRect.Top)
                    {
                        int distanceNeededToScroll = SubMenuRect.Top - selectedItemRect.Top;
                        Scroll -= distanceNeededToScroll;
                    }
                    //---- If item is BELOW view
                    if (selectedItemRect.Bottom > SubMenuRect.Bottom)
                    {
                        int distanceNeededToScroll = selectedItemRect.Bottom - SubMenuRect.Bottom;
                        Scroll += distanceNeededToScroll;
                    }
                }

                // Clamp scroll

                MaxScroll = Math.Max(GetEntireMenuHeight() - SubMenuRect.Height, 0);
                if (Scroll > MaxScroll)
                {
                    Scroll = MaxScroll;
                }
                else if (Scroll < 0)
                {
                    Scroll = 0;
                }

                // Debug display of menu item rectangles:
                //for (int i = 0; i < Items.Count; i++)
                //{
                //    var TEST_DebugDrawItemRect = GetItemDisplayRect(i, SubMenuRect);

                //    GFX.SpriteBatch.Begin();
                //    GFX.SpriteBatch.Draw(MODEL_VIEWER_MAIN.DEFAULT_TEXTURE_DIFFUSE, TEST_DebugDrawItemRect, Color.Yellow);
                //    GFX.SpriteBatch.End();
                //}

                // ONLY draw the menu items that are in-frame

                int roughStartDrawIndex = (int)((Scroll / menuHeight) * (Items.Count - 1)) - 1;
                int roughEndDrawIndex   = (int)(((Scroll + MenuRect.Height) / menuHeight) * (Items.Count - 1)) + 1;

                if (roughStartDrawIndex < 0)
                {
                    roughStartDrawIndex = 0;
                }
                else if (roughStartDrawIndex >= Items.Count)
                {
                    roughStartDrawIndex = Items.Count - 1;
                }

                if (roughEndDrawIndex < 0)
                {
                    roughEndDrawIndex = 0;
                }
                else if (roughEndDrawIndex >= Items.Count)
                {
                    roughEndDrawIndex = Items.Count - 1;
                }

                GFX.SpriteBatchEnd();

                // Store current viewport, then switch viewport to JUST the menu rect
                var oldViewport = GFX.Device.Viewport;
                GFX.Device.Viewport = new Viewport(
                    oldViewport.X + SubMenuRect.X,
                    oldViewport.Y + SubMenuRect.Y,
                    SubMenuRect.Width,
                    SubMenuRect.Height);

                GFX.SpriteBatchBegin();
                // ---- These braces manually force a smaller scope so we
                //      don't forget to return to the old viewport immediately afterward.
                {
                    // Draw Items

                    var selectionPrefixTextSize = Vector2.Zero;// FONT.MeasureString($"  {UICursorBlinkString} ");

                    for (int i = roughStartDrawIndex; i <= roughEndDrawIndex; i++)
                    {
                        Items[i].UpdateUI();
                        var entryText = GetActualItemDisplayText(i);

                        var itemRect = GetItemDisplayRect(i, SubMenuRect);

                        // Check if this item is inside the actual menu rectangle.
                        if (SubMenuRect.Intersects(itemRect))
                        {
                            var itemTextColor = Items[i].CustomColorFunction?.Invoke() ?? ((SelectedIndex == i &&
                                                                                            MenuOpenState == DbgMenuOpenState.Open)
                                ? Color.LightGreen : Color.White);

                            if (SelectedIndex == i && MenuOpenState == DbgMenuOpenState.Open)
                            {
                                var underlineRect = new Rectangle(
                                    itemRect.X - SubMenuRect.X + (int)selectionPrefixTextSize.X - 4,
                                    itemRect.Y - SubMenuRect.Y - 1,
                                    MenuRect.Width - (int)(selectionPrefixTextSize.X) + 4,
                                    itemRect.Height + 2);


                                if (menuHeight > SubMenuRect.Height)
                                {
                                    underlineRect = new Rectangle(underlineRect.X + 12, underlineRect.Y, underlineRect.Width - 4, underlineRect.Height);
                                }

                                GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE, underlineRect,
                                                     Color.Black);
                            }


                            // We have to SUBTRACT the menu top/left coord because the string
                            // drawing is relative to the VIEWPORT, which takes up just the actual menu rect
                            DBG.DrawOutlinedText(entryText,
                                                 new Vector2(itemRect.X - SubMenuRect.X, itemRect.Y - SubMenuRect.Y),
                                                 itemTextColor, FONT, startAndEndSpriteBatchForMe: false);
                        }
                    }

                    // Draw Scrollbar
                    // Only if there's stuff that passes the bottom of the menu.
                    if (menuHeight > SubMenuRect.Height)
                    {
                        //---- Draw Scrollbar Background
                        GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE,
                                             new Rectangle(0, 0, 8, SubMenuRect.Height), Color.White * 0.5f * menuBackgroundOpacityMult);

                        float curScrollRectTop    = (Scroll / menuHeight) * SubMenuRect.Height;
                        float curScrollRectHeight = (SubMenuRect.Height / menuHeight) * SubMenuRect.Height;

                        //---- Scroll Scrollbar current scroll
                        GFX.SpriteBatch.Draw(Main.DEFAULT_TEXTURE_DIFFUSE,
                                             new Rectangle(0, (int)curScrollRectTop, 8, (int)curScrollRectHeight),
                                             Color.White * 0.75f * menuBackgroundOpacityMult);
                    }
                }
                //---- Return to old viewport
                GFX.SpriteBatchEnd();
                GFX.Device.Viewport = oldViewport;



                prevFrameItemCount = Items.Count;
            }
        }
Exemplo n.º 5
0
        private void createPalette()
        {
            for (int i = 0; i < 256; i++)
            {
                palettes[i] = Color.Black;
            }

            if (paletteUpDown.Value <= 40)
            {
                label9.Text  = "Dungeon Main";
                label10.Text = "Dungeon Sprite Pal1";
                label11.Text = "Dungeon Sprite Pal2";
                label12.Text = "Dungeon Sprite Pal3";

                byte  dungeon_palette_ptr = (byte)(GfxGroups.paletteGfx[(byte)paletteUpDown.Value][0]);
                short palette_pos         = 0;
                int   pId  = 0;
                int   pPos = 32;

                if (GfxGroups.paletteGfx[(byte)paletteUpDown.Value][0] % 2 == 0)
                {
                    palette_pos = (short)((ROM.DATA[0xDEC4B + dungeon_palette_ptr + 1] << 8) + ROM.DATA[0xDEC4B + dungeon_palette_ptr]);
                    pId         = (palette_pos / 180);

                    for (int i = 0; i < 90; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        if (pId < Palettes.dungeonsMain_Palettes.Length)
                        {
                            palettes[pPos] = Palettes.dungeonsMain_Palettes[pId][i];
                        }

                        pPos++;
                    }
                }

                pPos = 128;
                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][1] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][1] < Palettes.spritesAux1_Palettes.Length)
                        {
                            palettes[pPos++] = Palettes.spritesAux1_Palettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][1]][i];
                        }
                    }
                }

                pPos = 208;
                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][2] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][2] < Palettes.spritesAux3_Palettes.Length)
                        {
                            palettes[pPos++] = Palettes.spritesAux3_Palettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][2]][i];
                        }
                    }
                }

                pPos = 224;
                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][3] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][3] < Palettes.spritesAux3_Palettes.Length)
                        {
                            palettes[pPos] = Palettes.spritesAux3_Palettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][3]][i];
                        }

                        pPos++;
                    }
                }

                pPos = 145;
                for (int i = 0; i < 15; i++)
                {
                    /*if (pPos % 16 == 0)
                     * {
                     *  pPos++;
                     * }*/

                    palettes[pPos]      = Palettes.globalSprite_Palettes[0][i];
                    palettes[pPos + 16] = Palettes.globalSprite_Palettes[0][i + 15];
                    palettes[pPos + 32] = Palettes.globalSprite_Palettes[0][i + 30];
                    palettes[pPos + 48] = Palettes.globalSprite_Palettes[0][i + 45];
                    pPos++;
                }
            }
            else
            {
                label9.Text  = "Auxiliary Pal1";
                label10.Text = "Auxiliary Pal2";
                label11.Text = "Animated Pal";
                label12.Text = "???";
                int pPos = 40;

                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][0] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][0]][i];
                        pPos++;
                    }

                    pPos = 56;
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][0]][i + 7];
                        pPos++;
                    }

                    pPos = 72;
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][0]][i + 14];
                        pPos++;
                    }
                }

                pPos = 88;
                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][1] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][1]][i];
                        pPos++;
                    }

                    pPos = 104;
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][1]][i + 7];
                        pPos++;
                    }

                    pPos = 120;
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AuxPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][1]][i + 14];
                        pPos++;
                    }
                }

                pPos = 112;
                if (GfxGroups.paletteGfx[(int)paletteUpDown.Value][2] != 255)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (pPos % 16 == 0)
                        {
                            pPos++;
                        }

                        palettes[pPos] = Palettes.overworld_AnimatedPalettes[GfxGroups.paletteGfx[(int)paletteUpDown.Value][2]][i];
                        pPos++;
                    }
                }

                pPos = 32;
                for (int i = 0; i < 7; i++)
                {
                    if (pPos % 16 == 0)
                    {
                        pPos++;
                    }

                    palettes[pPos] = Palettes.overworld_MainPalettes[0][i];
                    pPos++;
                }

                pPos = 48;
                for (int i = 0; i < 7; i++)
                {
                    if (pPos % 16 == 0)
                    {
                        pPos++;
                    }

                    palettes[pPos] = Palettes.overworld_MainPalettes[0][i + 7];
                    pPos++;
                }

                pPos = 64;
                for (int i = 0; i < 7; i++)
                {
                    if (pPos % 16 == 0)
                    {
                        pPos++;
                    }

                    palettes[pPos] = Palettes.overworld_MainPalettes[0][i + 14];
                    pPos++;
                }

                pPos = 80;
                for (int i = 0; i < 7; i++)
                {
                    if (pPos % 16 == 0)
                    {
                        pPos++;
                    }

                    palettes[pPos] = Palettes.overworld_MainPalettes[0][i + 21];
                    pPos++;
                }

                pPos = 96;
                for (int i = 0; i < 7; i++)
                {
                    if (pPos % 16 == 0)
                    {
                        pPos++;
                    }

                    palettes[pPos] = Palettes.overworld_MainPalettes[0][i + 28];
                    pPos++;
                }
            }

            if (paletteUpDown.Value <= 40)
            {
                if (GfxGroups.paletteGfx[(byte)paletteUpDown.Value][0] % 2 == 0)
                {
                    GFX.loadedPalettes    = GFX.LoadDungeonPalette(mainForm.activeScene.room.palette);
                    GFX.loadedSprPalettes = GFX.LoadSpritesPalette(mainForm.activeScene.room.palette);
                }
            }
        }
Exemplo n.º 6
0
 public OverworldConfig()
 {
     hardCodedDWGrass = GFX.getColor((short)((ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassDW") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassDW")]));
     hardCodedLWGrass = GFX.getColor((short)((ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassLW") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassLW")]));
     hardCodedDMGrass = GFX.getColor((short)((ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassSpecial") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("hardcodedGrassSpecial")]));
 }
        private void BeforeRender()
        {
            List <Entity> glassBlocks = Scene.Tracker.GetEntities <CustomizableGlassBlock>();

            hasBlocks = (glassBlocks.Count > 0);
            if (!hasBlocks)
            {
                return;
            }

            Camera camera       = (Scene as Level).Camera;
            int    screenWidth  = 320;
            int    screenHeight = 180;

            // draw stars
            if (starsTarget == null)
            {
                starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", screenWidth, screenHeight);
            }

            Engine.Graphics.GraphicsDevice.SetRenderTarget(starsTarget);
            Engine.Graphics.GraphicsDevice.Clear(Color.Transparent);
            Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity);
            Vector2 origin = new Vector2(8f, 8f);

            for (int i = 0; i < stars.Length; i++)
            {
                MTexture starTexture        = stars[i].Texture;
                Color    starColor          = stars[i].Color * alpha;
                Vector2  starScroll         = stars[i].Scroll;
                Vector2  starActualPosition = default;
                starActualPosition.X = Mod(stars[i].Position.X - camera.X * (1f - starScroll.X), screenWidth);
                starActualPosition.Y = Mod(stars[i].Position.Y - camera.Y * (1f - starScroll.Y), screenHeight);
                starTexture.Draw(starActualPosition, origin, starColor);

                if (starActualPosition.X < origin.X)
                {
                    starTexture.Draw(starActualPosition + new Vector2(screenWidth, 0f), origin, starColor);
                }
                else if (starActualPosition.X > screenWidth - origin.X)
                {
                    starTexture.Draw(starActualPosition - new Vector2(screenWidth, 0f), origin, starColor);
                }

                if (starActualPosition.Y < origin.Y)
                {
                    starTexture.Draw(starActualPosition + new Vector2(0f, screenHeight), origin, starColor);
                }
                else if (starActualPosition.Y > screenHeight - origin.Y)
                {
                    starTexture.Draw(starActualPosition - new Vector2(0f, screenHeight), origin, starColor);
                }
            }
            Draw.SpriteBatch.End();

            // draw rays/beams
            int vertex = 0;

            for (int j = 0; j < rays.Length; j++)
            {
                Vector2 rayPosition = default;
                rayPosition.X = Mod(rays[j].Position.X - camera.X * 0.9f, screenWidth);
                rayPosition.Y = Mod(rays[j].Position.Y - camera.Y * 0.9f, screenHeight);
                DrawRay(rayPosition, ref vertex, ref rays[j]);
                if (rayPosition.X < 64f)
                {
                    DrawRay(rayPosition + new Vector2(screenWidth, 0f), ref vertex, ref rays[j]);
                }
                else if (rayPosition.X > (screenWidth - 64))
                {
                    DrawRay(rayPosition - new Vector2(screenWidth, 0f), ref vertex, ref rays[j]);
                }
                if (rayPosition.Y < 64f)
                {
                    DrawRay(rayPosition + new Vector2(0f, screenHeight), ref vertex, ref rays[j]);
                }
                else if (rayPosition.Y > (screenHeight - 64))
                {
                    DrawRay(rayPosition - new Vector2(0f, screenHeight), ref vertex, ref rays[j]);
                }
            }

            if (beamsTarget == null)
            {
                beamsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-beams", screenWidth, screenHeight);
            }

            Engine.Graphics.GraphicsDevice.SetRenderTarget(beamsTarget);
            Engine.Graphics.GraphicsDevice.Clear(Color.Transparent);
            GFX.DrawVertices(Matrix.Identity, verts, vertex);

            // if fading in, update the alpha value to fade in in ~0.25 seconds.
            if (alpha != 1f)
            {
                alpha = Calc.Approach(alpha, 1f, Engine.DeltaTime * 4f);
            }
        }
Exemplo n.º 8
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            MyPlayer player   = Main.LocalPlayer.GetModPlayer <MyPlayer>();
            float    quotient = GetPlayerResourceQuotient(player);

            Rectangle hitbox = GetInnerDimensions().ToRectangle();

            hitbox.X     += _barDraggableRectangle.X;
            hitbox.Y     += _barDraggableRectangle.Y;
            hitbox.Width  = _barDraggableRectangle.Width;
            hitbox.Height = _barDraggableRectangle.Height;
            _frameTimer++;
            if (_frameTimer >= 20)
            {
                _frameTimer = 0;
            }

            int     frameHeight   = 0;
            int     frame         = _frameTimer / 5;
            Vector2 textureOffset = Vector2.Zero;

            switch (_stat)
            {
            case ResourceBarMode.Ki:
                texture       = GFX.GetKiBar(player).kiBarFrame;
                frameHeight   = texture.Height / 4;
                textureOffset = new Vector2(16, 8);
                _drawPosition = new Vector2(hitbox.X - 6, hitbox.Y - 6);
                break;

            case ResourceBarMode.Overload:
                texture       = GFX.overloadBarFrame;
                frameHeight   = texture.Height / 4;
                textureOffset = new Vector2(18, 6);
                _drawPosition = new Vector2(hitbox.X - 8, hitbox.Y - 4);
                break;

            default: texture = null;
                break;
            }
            Rectangle sourceRectangle = new Rectangle(0, frameHeight * frame, texture.Width, frameHeight);

            spriteBatch.Draw(texture, _drawPosition, sourceRectangle, Color.White);

            Texture2D barSegmentTexture = null;

            switch (_stat)
            {
            case ResourceBarMode.Ki:
                barSegmentTexture = GFX.GetKiBar(player).kiBarSegment;
                break;

            case ResourceBarMode.Overload:
                barSegmentTexture = GFX.overloadBarSegment;
                break;
            }

            // pessimistic doj
            if (barSegmentTexture != null)
            {
                // draw the segments last.
                int actualSegments = (int)Math.Ceiling(_segments * quotient);
                for (int i = 0; i < actualSegments; i += 1)
                {
                    Vector2 segmentOffsetX  = new Vector2(i * 12, 0);
                    Vector2 segmentPosition = _drawPosition + textureOffset + segmentOffsetX;
                    if (i == actualSegments - 1)
                    {
                        float segmentValue     = 1f / _segments;
                        float segmentRemainder = quotient % segmentValue;
                        float segmentQuotient  = segmentRemainder / segmentValue;
                        // if there's no remainder, it's a full segment, render the whole thing.
                        if (segmentQuotient == 0f)
                        {
                            segmentQuotient = 1f;
                        }
                        // we're on a partial segment, render the whole thing.
                        spriteBatch.Draw(barSegmentTexture, segmentPosition, new Rectangle(0, 0, (int)Math.Ceiling(barSegmentTexture.Width * segmentQuotient), barSegmentTexture.Height), Color.White);
                    }
                    else
                    {
                        // we're on a full segment, render the whole thing.
                        spriteBatch.Draw(barSegmentTexture, segmentPosition, new Rectangle(0, 0, barSegmentTexture.Width, barSegmentTexture.Height), Color.White);
                    }
                }
            }
        }
Exemplo n.º 9
0
 public Animation()
 {
     source = new GFX();
 }