コード例 #1
0
ファイル: Derp.cs プロジェクト: GoodSky/derp-adventure
        public Derp(double x, double y, int team)
        {
            ContentManager Content = Game.game.Content;

            this.x = x;
            this.y = y;
            facing = direction.EAST;
            state = derpState.MOVING;
            stats = new DerpStats(10, 1, 1, 1, 0, 0, 0, 0);
            this.team = team;

            if (team == 1)
                graphic = Content.Load<Texture2D>(@"GameBlocks\Derp_1");
            else if (team == 2)
                graphic = Content.Load<Texture2D>(@"GameBlocks\Derp_2");
        }
コード例 #2
0
ファイル: Spawner.cs プロジェクト: GoodSky/game-nuggets
        // Per-Cycle Update
        public void Update(GameTime gameTime)
        {
            if (!Active)
            {
                return;
            }

            // Look if we need to add a new spawn
            if (DateTime.Now.Subtract(lastSpawn).TotalSeconds > nextSpawnTime && (spawning.Count == 0 || Math.Abs(spawning.Last.Value.x - worldX) > DerpSpawn.width))
            {
                spawning.AddLast(new DerpSpawn(worldX + (team == TEAM.AWAY ? Field.BLOCK_WIDTH : 0), worldY));

                lastSpawn     = DateTime.Now;
                nextSpawnTime = spawningBaseTime + (MyRandom.NextDouble(team) * spawningVariance * 2 - spawningVariance);
            }

            // Update all of the exists derp spawns we are in charge of
            LinkedListNode <DerpSpawn> cur = spawning.First;

            while (cur != null)
            {
                // See if we are at the end and need to create a derp
                int distanceFromStart;
                if (team == TEAM.HOME)
                {
                    distanceFromStart = cur.Value.x - worldX;
                }
                else
                {
                    distanceFromStart = worldX - cur.Value.x;
                }

                if (distanceFromStart >= strand.Count * Field.BLOCK_WIDTH + (team == TEAM.HOME ? Field.BLOCK_WIDTH : 0))
                {
                    // Generate stats for the new derp
                    int hp   = 5 + MyRandom.Next(team, 10);
                    int spd  = 25 + MyRandom.Next(team, 50);
                    int atk  = 3 + MyRandom.Next(team, 4);
                    int aspd = 25 + MyRandom.Next(team, 50);
                    int rng  = 2 + MyRandom.Next(team, 30);

                    DerpStats stats = new DerpStats(hp, spd, atk, aspd, rng, 16, 16);

                    // Make sure there is no obstruction
                    int newDerpX, newDerpY;

                    newDerpX = worldX;
                    if (team == TEAM.HOME)
                    {
                        newDerpX += (strand.Count + 1) * Field.BLOCK_WIDTH;
                    }
                    else
                    {
                        newDerpX -= strand.Count * Field.BLOCK_WIDTH;
                    }

                    newDerpY = worldY + (Field.BLOCK_WIDTH / 2);


                    if (Field.derpManager.SearchForDerp(newDerpX, newDerpY, stats.width) == null)
                    {
                        Field.derpManager.SpawnDerp(newDerpX, newDerpY, team, stats);
                        spawning.RemoveFirst();
                    }
                }
                // Otherwise move us forward
                else
                {
                    // Make sure there is no obstruction
                    if (cur.Next == null || Math.Abs(cur.Next.Value.x - cur.Value.x) > DerpSpawn.width + spawnMoveSpeed)
                    {
                        cur.Value.Step(team == TEAM.HOME ? spawnMoveSpeed : -spawnMoveSpeed);
                    }
                }

                cur = cur.Next;
            }
        }
コード例 #3
0
ファイル: Spawner.cs プロジェクト: GoodSky/derp-adventure
        // Per-Cycle Update
        public void Update(GameTime gameTime)
        {
            if (!Active)
                return;

            // Look if we need to add a new spawn
            if (DateTime.Now.Subtract(lastSpawn).TotalSeconds > nextSpawnTime && (spawning.Count == 0 || Math.Abs(spawning.Last.Value.x - worldX) > DerpSpawn.width))
            {
                spawning.AddLast(new DerpSpawn(worldX + (team == TEAM.AWAY ? Field.BLOCK_WIDTH : 0), worldY));

                lastSpawn = DateTime.Now;
                nextSpawnTime = spawningBaseTime + (MyRandom.NextDouble(team) * spawningVariance * 2 - spawningVariance);
            }

            // Update all of the exists derp spawns we are in charge of
            LinkedListNode<DerpSpawn> cur = spawning.First;
            while (cur != null)
            {
                // See if we are at the end and need to create a derp
                int distanceFromStart;
                if (team == TEAM.HOME)
                {
                    distanceFromStart = cur.Value.x - worldX;
                }
                else
                {
                    distanceFromStart = worldX - cur.Value.x;
                }

                if (distanceFromStart >= strand.Count*Field.BLOCK_WIDTH + (team == TEAM.HOME ? Field.BLOCK_WIDTH : 0))
                {
                    // Generate stats for the new derp
                    int hp = 5 + MyRandom.Next(team, 10);
                    int spd = 25 + MyRandom.Next(team, 50);
                    int atk = 3 + MyRandom.Next(team, 4);
                    int aspd = 25 + MyRandom.Next(team, 50);
                    int rng = 2 + MyRandom.Next(team, 30);

                    DerpStats stats = new DerpStats(hp, spd, atk, aspd, rng, 16, 16);

                    // Make sure there is no obstruction
                    int newDerpX, newDerpY;

                    newDerpX = worldX;
                    if (team == TEAM.HOME)
                        newDerpX += (strand.Count + 1) * Field.BLOCK_WIDTH;
                    else
                        newDerpX -= strand.Count * Field.BLOCK_WIDTH;

                    newDerpY = worldY + (Field.BLOCK_WIDTH/2);

                    if (Field.derpManager.SearchForDerp(newDerpX, newDerpY, stats.width) == null)
                    {
                        Field.derpManager.SpawnDerp(newDerpX, newDerpY, team, stats);
                        spawning.RemoveFirst();
                    }
                }
                // Otherwise move us forward
                else
                {
                    // Make sure there is no obstruction
                    if (cur.Next == null || Math.Abs(cur.Next.Value.x - cur.Value.x) > DerpSpawn.width + spawnMoveSpeed)
                    {
                        cur.Value.Step(team == TEAM.HOME ? spawnMoveSpeed : -spawnMoveSpeed);
                    }
                }

                cur = cur.Next;
            }
        }
コード例 #4
0
ファイル: Field.cs プロジェクト: GoodSky/derp-adventure
        public void Update(GameTime gameTime)
        {
            // Scroll back and forth
            if (Game.input.KeyDown(Keys.A) || Game.input.KeyDown(Keys.Left)) SlideView(-2);
            if (Game.input.KeyDown(Keys.D) || Game.input.KeyDown(Keys.Right)) SlideView(2);

            // Move the Screen with Velocity
            if (xVel < -15) xVel = -15;
            if (xVel > 15) xVel = 15;
            camX += (int)xVel;
            xVel /= 1.13;
            if (Math.Abs(xVel) < 0.9) xVel = 0.0;

            // Move the Screen with the mouse
            if (Game.input.MouseY() > 0 && Game.input.MouseY() < Game.GAME_HEIGHT)
            {
                // Move the screen to the Right. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() < BLOCK_WIDTH * 2)
                    camX -= ((BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10) <= 15 ? (BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10 : 15;

                // Move the screen to the Left. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() > Game.GAME_WIDTH - BLOCK_WIDTH * 2)
                    camX += ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) <= 15 ? ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) : 15;
            }

            // Cap the camera position
            if (camX < 0) camX = 0;
            if (camX > width * BLOCK_WIDTH - Game.WINDOW_WIDTH) camX = width * BLOCK_WIDTH - Game.WINDOW_WIDTH;

            // Calculare Selected box
            int selectedX = (camX + Game.input.MouseX()) / BLOCK_WIDTH;
            int selectedY = Game.input.MouseY() / BLOCK_HEIGHT;
            selectedBox = new Point(selectedX, selectedY);

            // Update all Spawners
            for (int y = 0; y < height; ++y)
            {
                if (leftSpawners[y] != null)
                {
                    leftSpawners[y].Update(gameTime);
                    rightSpawners[y].Update(gameTime);
                }
            }

            // Handle the "Mouse State"
            // This will change when we are trying to build DNA, delete DNA, etc
            // This is also where we will build DNA onto the field

            // Stop Construction if we Right-Click (a universal cancel)
            if (Game.input.constructionState != 0 && Game.input.MouseRightKeyClicked())
            {
                Game.input.constructionState = 0;
            }

            // Check for Construction if we Left-Click
            if (Game.input.constructionState != 0 && Game.input.MouseLeftKeyClicked())
            {
                // Find the X,Y coordinate in the grid that the mouse is in
                int sx = selectedBox.X - (camX / BLOCK_WIDTH);
                int sy = selectedBox.Y - (camY / BLOCK_HEIGHT);

                // Make sure we are within the game boundry, otherwise do nothing
                if (sx >= 0 && sx <= Game.GAME_WIDTH / BLOCK_WIDTH && sy >= 0 && sy <= Game.GAME_HEIGHT / BLOCK_HEIGHT && Game.input.mouseClear)
                {
                    // Check if any Spawner accepts this position as a valid DNA location
                    // If so, add the DNA to their strand and continue. Luckily there should never be overlap, so we don't have to worry about doing double.
                    int mx = Game.input.MouseX();
                    int my = Game.input.MouseY();
                    for (int i = 0; i < leftSpawners.Length; ++i)
                    {
                        if (leftSpawners[i] != null && leftSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            leftSpawners[i].AddDNA(leftSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }

                        // DEBUG: Only do this on the right side for debugging purposes
                        if (rightSpawners[i] != null && rightSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            rightSpawners[i].AddDNA(rightSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }
                    }

                    // Reset Construction State
                    Game.input.constructionState = 0;
                }
            }

            // DEBUG CODE:
            // - create a derp for now if you click on a hub
            if (Game.input.MouseLeftKeyClicked() && selectedX >= 0 && selectedX < width && selectedY >= 0 && selectedY < height && gameGrid[selectedY, selectedX] == 'A')
            {
                int hp = 5 + MyRandom.Next(TEAM.HOME, 10);
                int spd = 25 + MyRandom.Next(TEAM.HOME, 50);
                int atk = 3 + MyRandom.Next(TEAM.HOME, 4);
                int aspd = 25 + MyRandom.Next(TEAM.HOME, 50);
                int rng = 2 + MyRandom.Next(TEAM.HOME, 30);

                DerpStats stats = new DerpStats(hp, spd, atk, aspd, rng, 16, 16);
                TEAM derpTeam;

                if (selectedX == 0)
                {
                    derpTeam = TEAM.HOME;
                }
                else
                {
                    derpTeam = TEAM.AWAY;
                }

                derpManager.SpawnDerp(selectedX * BLOCK_WIDTH + (BLOCK_WIDTH / 2), selectedY * BLOCK_HEIGHT + (BLOCK_HEIGHT / 2), derpTeam, stats);
            }

            // Update all the Derps
            derpManager.Update(gameTime);
        }
コード例 #5
0
ファイル: Field.cs プロジェクト: GoodSky/game-nuggets
        public void Update(GameTime gameTime)
        {
            // Scroll back and forth
            if (Game.input.KeyDown(Keys.A) || Game.input.KeyDown(Keys.Left))
            {
                SlideView(-2);
            }
            if (Game.input.KeyDown(Keys.D) || Game.input.KeyDown(Keys.Right))
            {
                SlideView(2);
            }

            // Move the Screen with Velocity
            if (xVel < -15)
            {
                xVel = -15;
            }
            if (xVel > 15)
            {
                xVel = 15;
            }
            camX += (int)xVel;
            xVel /= 1.13;
            if (Math.Abs(xVel) < 0.9)
            {
                xVel = 0.0;
            }

            // Move the Screen with the mouse
            if (Game.input.MouseY() > 0 && Game.input.MouseY() < Game.GAME_HEIGHT)
            {
                // Move the screen to the Right. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() < BLOCK_WIDTH * 2)
                {
                    camX -= ((BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10) <= 15 ? (BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10 : 15;
                }

                // Move the screen to the Left. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() > Game.GAME_WIDTH - BLOCK_WIDTH * 2)
                {
                    camX += ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) <= 15 ? ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) : 15;
                }
            }

            // Cap the camera position
            if (camX < 0)
            {
                camX = 0;
            }
            if (camX > width * BLOCK_WIDTH - Game.WINDOW_WIDTH)
            {
                camX = width * BLOCK_WIDTH - Game.WINDOW_WIDTH;
            }

            // Calculare Selected box
            int selectedX = (camX + Game.input.MouseX()) / BLOCK_WIDTH;
            int selectedY = Game.input.MouseY() / BLOCK_HEIGHT;

            selectedBox = new Point(selectedX, selectedY);

            // Update all Spawners
            for (int y = 0; y < height; ++y)
            {
                if (leftSpawners[y] != null)
                {
                    leftSpawners[y].Update(gameTime);
                    rightSpawners[y].Update(gameTime);
                }
            }

            // Handle the "Mouse State"
            // This will change when we are trying to build DNA, delete DNA, etc
            // This is also where we will build DNA onto the field

            // Stop Construction if we Right-Click (a universal cancel)
            if (Game.input.constructionState != 0 && Game.input.MouseRightKeyClicked())
            {
                Game.input.constructionState = 0;
            }

            // Check for Construction if we Left-Click
            if (Game.input.constructionState != 0 && Game.input.MouseLeftKeyClicked())
            {
                // Find the X,Y coordinate in the grid that the mouse is in
                int sx = selectedBox.X - (camX / BLOCK_WIDTH);
                int sy = selectedBox.Y - (camY / BLOCK_HEIGHT);

                // Make sure we are within the game boundry, otherwise do nothing
                if (sx >= 0 && sx <= Game.GAME_WIDTH / BLOCK_WIDTH && sy >= 0 && sy <= Game.GAME_HEIGHT / BLOCK_HEIGHT && Game.input.mouseClear)
                {
                    // Check if any Spawner accepts this position as a valid DNA location
                    // If so, add the DNA to their strand and continue. Luckily there should never be overlap, so we don't have to worry about doing double.
                    int mx = Game.input.MouseX();
                    int my = Game.input.MouseY();
                    for (int i = 0; i < leftSpawners.Length; ++i)
                    {
                        if (leftSpawners[i] != null && leftSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            leftSpawners[i].AddDNA(leftSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }

                        // DEBUG: Only do this on the right side for debugging purposes
                        if (rightSpawners[i] != null && rightSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            rightSpawners[i].AddDNA(rightSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }
                    }

                    // Reset Construction State
                    Game.input.constructionState = 0;
                }
            }

            // DEBUG CODE:
            // - create a derp for now if you click on a hub
            if (Game.input.MouseLeftKeyClicked() && selectedX >= 0 && selectedX < width && selectedY >= 0 && selectedY < height && gameGrid[selectedY, selectedX] == 'A')
            {
                int hp   = 5 + MyRandom.Next(TEAM.HOME, 10);
                int spd  = 25 + MyRandom.Next(TEAM.HOME, 50);
                int atk  = 3 + MyRandom.Next(TEAM.HOME, 4);
                int aspd = 25 + MyRandom.Next(TEAM.HOME, 50);
                int rng  = 2 + MyRandom.Next(TEAM.HOME, 30);

                DerpStats stats = new DerpStats(hp, spd, atk, aspd, rng, 16, 16);
                TEAM      derpTeam;

                if (selectedX == 0)
                {
                    derpTeam = TEAM.HOME;
                }
                else
                {
                    derpTeam = TEAM.AWAY;
                }

                derpManager.SpawnDerp(selectedX * BLOCK_WIDTH + (BLOCK_WIDTH / 2), selectedY * BLOCK_HEIGHT + (BLOCK_HEIGHT / 2), derpTeam, stats);
            }

            // Update all the Derps
            derpManager.Update(gameTime);
        }