Exemplo n.º 1
0
 public void DrawTiles()
 {
     for (int xx = 0; xx < TileGridValues.GetLength(0); xx++)
     {
         for (int yy = 0; yy < TileGridValues.GetLength(1); yy++)
         {
             if (TileGridValues[xx, yy] == 1)
             {
                 DrawRectangleRec(MathMore.toRayRect(new Rectangle(xx * CellWidth, yy * CellHeight, CellWidth, CellHeight)), MathMore.toRayColour(Colour.Gray));
                 DrawRectangleLinesEx(MathMore.toRayRect(new Rectangle(xx * CellWidth, yy * CellHeight, CellWidth, CellHeight)), 2, MathMore.toRayColour(Colour.Black));
             }
         }
     }
 }
Exemplo n.º 2
0
        public void PlayerMovement(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds * 60;

            KeyboardState kb = Keyboard.GetState();

            bool keyRight  = kb.IsKeyDown(Keys.Right);
            bool keyLeft   = kb.IsKeyDown(Keys.Left);
            bool keyJump   = kb.IsKeyDown(Keys.Z);
            bool keyActive = kb.IsKeyDown(Keys.X);

            float fricc = GroundFricc * deltaTime;

            if (!OnGround())
            {
                fricc = AirFricc * deltaTime;
            }

            if (keyRight)
            {
                Velocity.X = MathMore.Approach(Velocity.X, MoveSpeed, fricc);
            }

            if (keyLeft)
            {
                Velocity.X = MathMore.Approach(Velocity.X, -MoveSpeed, fricc);
            }

            if ((keyRight && keyLeft) || (!keyRight && !keyLeft))
            {
                Velocity.X = MathMore.Approach(Velocity.X, 0, fricc);
            }

            //Grav
            Velocity.Y = MathMore.Approach(Velocity.Y, 10, Grav * deltaTime);

            if (OnGround())
            {
                if (keyJump)
                {
                    Velocity.Y = -JumpSpeed;
                }
            }

            Collision(deltaTime);
        }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            BackgroundsUpdate(gameTime, Vector2.One);
            SinTimer += (float)gameTime.ElapsedGameTime.TotalSeconds * 60;

            if (baseGame.input.GetKeyPressed(Keys.Up))
            {
                MenuPos--;
                menuPosScale = 0.5f;
            }

            if (baseGame.input.GetKeyPressed(Keys.Down))
            {
                MenuPos++;
                menuPosScale = 0.5f;
            }

            MenuPos = MathMore.WrapValue(MenuPos, 0, MenuItems.Count());
        }
Exemplo n.º 4
0
        public override void DrawGui(SpriteBatch spriteBatch, GameTime gameTime)
        {
            //Draw Logo
            spriteBatch.Draw(Logo, new Vector2(Screen.GameWidth / 2, Screen.GameHeight / 4) - new Vector2(Logo.Width / 2, Logo.Height / 2), Color.White);
            menuPosScale = MathHelper.Lerp(menuPosScale, 1.5f, 0.08f);

            for (int i = 0; i < MenuItems.Count(); i++)
            {
                if (MenuPos != i)
                {
                    Vector2 pos = new Vector2(Screen.GameWidth / 2, Screen.GameHeight / 2);
                    pos.Y += (16 * i) + MathMore.SinWave(-4, 4, 4, (float)i / 4.0f, SinTimer);
                    Drawing.DrawTextExtShadow(spriteBatch, baseGame.BasicFont, MenuItems[i], pos, TextAlign.Center, TextAlign.Center, Vector2.One, Color.White, new Color(24, 20, 37, 128));
                }
                else
                {
                    Vector2 pos = new Vector2(Screen.GameWidth / 2, Screen.GameHeight / 2);
                    pos.Y += (16 * i) + MathMore.SinWave(-4, 4, 4, (float)i / 4.0f, SinTimer);
                    Vector2 Scale = (Vector2.One * MathMore.SinWave(0.9f, 1.1f, 4, (float)i / 4.0f, SinTimer)) * menuPosScale;
                    Drawing.DrawTextExtShadow(spriteBatch, baseGame.BasicFont, MenuItems[i], pos, TextAlign.Center, TextAlign.Center, Scale, Color.White, new Color(24, 20, 37, 128));
                }
            }
        }
Exemplo n.º 5
0
        public void GameWindow()
        {
            {
                ImGui.Begin("Level Window");
                //
                ImGui.BeginChild("Level batch", Num.Vector2.Zero, true, ImGuiWindowFlags.AlwaysHorizontalScrollbar);

                //TileTools
                ImGui.BeginGroup();

                if (ImGui.Button("Pencil"))
                {
                    PlaceMode = 0;
                }
                ImGui.SameLine();
                if (ImGui.Button("Rectangle"))
                {
                    PlaceMode = 1;
                }
                ImGui.SameLine();
                if (ImGui.Button("Fill (Unimplemented)"))
                {
                    PlaceMode = 2;
                }
                ImGui.SliderInt("GameZoom", ref GameZoom, 1, 4);

                ImGui.EndGroup();

                ImGui.Image(levelTexture, new Num.Vector2((MapSize.X * 16) * GameZoom, (MapSize.Y * 16) * GameZoom));
                //Get Top left of image
                Num.Vector2 editorTopLeft = ImGui.GetItemRectMin();
                Rectangle   editorRect    = new Rectangle((int)(editorTopLeft.X), (int)(editorTopLeft.Y), (int)(MapSize.X * 16) * GameZoom, (int)((MapSize.Y * 16) * GameZoom));
                Prim.DrawRectangle(editorRect, Color.Black);
                if (viewTileGrid)
                {
                    Prim.DrawGrid(editorRect, (16 * GameZoom), (16 * GameZoom), new Color(0, 0, 0, 128));
                }
                Prim.DrawGrid(editorRect, (Screen.GameWidth * GameZoom), (Screen.GameHeight * GameZoom), Color.Yellow);

                //MousePosition in tile pallate
                editorMousePos   = (ImGui.GetMousePos() - editorTopLeft);
                editorMousePos  /= (16 * GameZoom);
                editorMousePos.X = (int)Math.Floor(editorMousePos.X);
                editorMousePos.Y = (int)Math.Floor(editorMousePos.Y);
                editorMousePos  *= (16 * GameZoom);

                Num.Vector2 flatMousePos = ImGui.GetMousePos();
                if (MathMore.PointInRectangle(new Vector2(flatMousePos.X, flatMousePos.Y), editorRect))
                {
                    switch (PlaceMode)
                    {
                    case 0:         // Pen
                    {
                        #region     // PenTool
                        Rectangle editorCursorRect = new Rectangle((int)(editorMousePos.X + editorRect.X), (int)(editorMousePos.Y + editorRect.Y), (SelectedTileBrush.GetLength(0) * 16) * GameZoom, (SelectedTileBrush.GetLength(1) * 16) * GameZoom);
                        Prim.DrawRectangle(editorCursorRect, Color.Maroon);

                        //Click Tile
                        if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                        {
                            Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));

                            //Draw rect
                            for (int xx = (int)gridPos.X; xx < (int)gridPos.X + SelectedTileBrush.GetLength(0); xx++)
                            {
                                for (int yy = (int)gridPos.Y; yy < (int)gridPos.Y + SelectedTileBrush.GetLength(1); yy++)
                                {
                                    int bX = (int)(xx - (int)gridPos.X);
                                    int bY = (int)(yy - (int)gridPos.Y);

                                    Point tileP = SelectedTileBrush[bX, bY];

                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), tileP);
                                }
                            }
                        }

                        if (ImGui.IsMouseDown(ImGuiMouseButton.Right))
                        {
                            Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));
                            //EraseRect
                            for (int xx = (int)gridPos.X; xx < (int)gridPos.X + SelectedTileBrush.GetLength(0); xx++)
                            {
                                for (int yy = (int)gridPos.Y; yy < (int)gridPos.Y + SelectedTileBrush.GetLength(1); yy++)
                                {
                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), Point.Zero);
                                }
                            }
                        }
                        #endregion         // EndPenTool
                        break;
                    }

                    case 1:
                    {
                        #region         // RectangleTool
                        Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));

                        if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                        {
                            rectPlaceTopLeft  = new Point((int)gridPos.X, (int)gridPos.Y);
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);
                        }
                        else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                        {
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);

                            //order
                            Point tl = new Point(Math.Min(rectPlaceBotRight.X, rectPlaceTopLeft.X), Math.Min(rectPlaceBotRight.Y, rectPlaceTopLeft.Y));
                            Point rl = new Point(Math.Max(rectPlaceBotRight.X, rectPlaceTopLeft.X), Math.Max(rectPlaceBotRight.Y, rectPlaceTopLeft.Y));

                            rectPlaceTopLeft  = tl;
                            rectPlaceBotRight = rl;

                            //Place
                            int xdif = rectPlaceBotRight.X - rectPlaceTopLeft.X;
                            int ydif = rectPlaceBotRight.Y - rectPlaceTopLeft.Y;
                            xdif = Math.Max(1, xdif);
                            ydif = Math.Max(1, ydif);

                            for (int xx = rectPlaceTopLeft.X; xx < rectPlaceTopLeft.X + xdif; xx++)
                            {
                                for (int yy = rectPlaceTopLeft.Y; yy < rectPlaceTopLeft.Y + ydif; yy++)
                                {
                                    int bX = (int)(xx - (int)rectPlaceTopLeft.X) % SelectedTileBrush.GetLength(0);
                                    int bY = (int)(yy - (int)rectPlaceTopLeft.Y) % SelectedTileBrush.GetLength(1);



                                    Point tileP = SelectedTileBrush[bX, bY];

                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), tileP);
                                }
                            }
                        }
                        else if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                        {
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);

                            int       mgic     = 16 * GameZoom;
                            Point     tl       = new Point((int)editorTopLeft.X + (rectPlaceTopLeft.X * mgic), (int)editorTopLeft.Y + (rectPlaceTopLeft.Y * mgic));
                            Rectangle rectRect = new Rectangle(tl, new Point((rectPlaceBotRight.X - rectPlaceTopLeft.X) * mgic, (rectPlaceBotRight.Y - rectPlaceTopLeft.Y) * mgic));

                            Prim.DrawRectangle(rectRect, Color.Maroon);
                        }
                        else
                        {
                            Rectangle editorCursorRect = new Rectangle((int)(editorMousePos.X + editorRect.X), (int)(editorMousePos.Y + editorRect.Y), (SelectedTileBrush.GetLength(0) * 16) * GameZoom, (SelectedTileBrush.GetLength(1) * 16) * GameZoom);
                            Prim.DrawRectangle(editorCursorRect, Color.Maroon);
                        }

                        #endregion
                        break;
                    }
                    }
                }

                ImGui.EndChild();

                //
                ImGui.End();
            }
        }
Exemplo n.º 6
0
        public void TilePallateWindow()
        {
            //Tile Pallate Window
            {
                ImGui.Begin("Tiles");
                //Draw Tile set
                ImGui.Image(tilePallateTexture, new Num.Vector2(tilePallateTextureSize.X, tilePallateTextureSize.Y) * tileSetZoom);

                //Get top left of window and draw rect around texture
                Num.Vector2 imageTopLeft    = ImGui.GetItemRectMin();
                Rectangle   tilePallateRect = new Rectangle((int)(imageTopLeft.X), (int)(imageTopLeft.Y), (int)tilePallateTextureSize.X * tileSetZoom, (int)tilePallateTextureSize.Y * tileSetZoom);
                Prim.DrawRectangle(tilePallateRect, Color.Black);

                Prim.DrawGrid(tilePallateRect, (16 * tileSetZoom), (16 * tileSetZoom), Color.Black);

                //Allow zoom on tileset
                ImGui.InputInt("Zoom", ref tileSetZoom, 1);
                tileSetZoom = MathHelper.Clamp(tileSetZoom, 1, 3);

                //MousePosition in tile pallate
                tilePallateMousePos   = (ImGui.GetMousePos() - imageTopLeft);
                tilePallateMousePos  /= (16 * tileSetZoom);
                tilePallateMousePos.X = (int)Math.Floor(tilePallateMousePos.X);
                tilePallateMousePos.Y = (int)Math.Floor(tilePallateMousePos.Y);
                tilePallateMousePos  *= (16 * tileSetZoom);

                int xdif = selectedTopRight.X - selectedTopLeft.X;
                int ydif = selectedTopRight.Y - selectedTopLeft.Y;
                xdif = Math.Max(1, xdif);
                ydif = Math.Max(1, ydif);

                Rectangle tileSelectedRect = new Rectangle((int)((selectedTopLeft.X * 16 * tileSetZoom) + imageTopLeft.X), (int)((selectedTopLeft.Y * 16 * tileSetZoom) + imageTopLeft.Y), (16 * tileSetZoom) * xdif, (16 * tileSetZoom) * ydif);
                Prim.DrawRectangle(tileSelectedRect, Color.Lime);

                //Select Rectangle of tiles
                Num.Vector2 flatMousePos = ImGui.GetMousePos();
                if (MathMore.PointInRectangle(new Vector2(flatMousePos.X, flatMousePos.Y), tilePallateRect))
                {
                    Num.Vector2 tilePos = (tilePallateMousePos / (16 * tileSetZoom));

                    Rectangle tileCursorRect = new Rectangle((int)((selectedTopLeft.X * 16 * tileSetZoom) + imageTopLeft.X), (int)((selectedTopLeft.Y * 16 * tileSetZoom) + imageTopLeft.Y), (16 * tileSetZoom) * xdif, (16 * tileSetZoom) * ydif);
                    Prim.DrawRectangle(tileCursorRect, Color.Maroon);

                    if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                    {
                        selectedTopLeft = new Point((int)tilePos.X, (int)tilePos.Y);
                    }
                    else if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                    {
                        selectedTopRight = new Point((int)tilePos.X + 1, (int)tilePos.Y + 1);
                    }
                    else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                    {
                        SelectedTileBrush = new Point[xdif, ydif];

                        for (int xx = 0; xx < xdif; xx++)
                        {
                            for (int yy = 0; yy < ydif; yy++)
                            {
                                SelectedTileBrush[xx, yy] = new Point(xx + selectedTopLeft.X, yy + selectedTopLeft.Y);
                            }
                        }
                    }
                }
                //ImGui.Text($"Tile Pos: {SelectedTile.ToString()}");

                ImGui.End();
            }
        }