Beispiel #1
0
        public static void RandomPlacementOfItems()
        {
            Random rand = new Random();

            ItemType[] items = new ItemType[]
            {
                ItemType.BigPower,
                ItemType.Bomb,
                ItemType.FullPower,
                ItemType.Life,
                ItemType.Point,
                ItemType.Power,
                ItemType.Star
            };

            int[] trigger = new int[]
            {
                rand.Next() % 340 + 600,
                  rand.Next() % 340 + 40,
                  rand.Next() % 340 + 6000,
                  rand.Next() % 340 + 60,
                  rand.Next() % 140 + 40,
                  rand.Next() % 140 + 20,
                  rand.Next() % 140 + 40
            };

            for (int i = 0; i < 7; ++i)
            {
                if (tick % (trigger[i]) == 0 && tick > 0)
                {
                    GameObjects.AddItem(new ItemEntity(new Point2D((rand.Next() % (460 - GameResources.GameImage("Item" + items[i].ToString()).Width)) + 40, 50), items[i]));
                }
            }

            if (tick % (rand.Next() % 80 + 50) == 0 && tick > 0)
            {
                double x = rand.Next() % 460 + 40;
                double y = rand.Next() % 460 + 40;
                int    n = rand.Next() % 24;
                for (int j = 0; j < n; ++j)
                {
                    GameObjects.AddBullet(new BulletEntity(new Point2D(x, y), new Velocity2D(2.8, 360 / n * j), 360 / n * j, BulletColour.Red, BulletType.Ring, null));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Main Function, main acces point for the program
        /// </summary>
        public static void Main()
        {
            //Open the game window
            SwinGame.OpenGraphicsWindow(Title + " v" + Version, 800, 600);

            //SwinGame.ToggleFullScreen();
            //SwinGame.ShowSwinGameSplashScreen();

            //Load the game assets
            GameResources.LoadResources();

            GameScores.Initalise();
            GameObjects.Initalise();

            //Run the game loop
            while (false == SwinGame.WindowCloseRequested() && GameScores.Player != 0)
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.Grey);
                SwinGame.DrawRectangle(Color.DarkGray, true, 40, 20, 460, 560);


                SwinGame.DrawFramerate(0, 0);

                //Update Game
                GameObjects.ProcessEvents();

                RandomPlacementOfItems();

                tick++;
                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }

            GameResources.FreeResources();
        }
Beispiel #3
0
        public override void ProcessEvents()
        {
            //process item collisions
            if (GameObjects.Items != null)
            {
                for (int i = 0; i < GameObjects.Items.Count; ++i)
                {
                    if (GameObjects.Items[i].Colides(this))
                    {
                        switch (GameObjects.Items[i].ItemType.ToString())
                        {
                        case "BigPower":
                            for (int j = 0; j < 5; ++j)
                            {
                                GameScores.IncrementPower();
                            }
                            if (GameScores.Power < 128)
                            {
                                GameScores.Score += GameScores.Points[0];
                            }
                            else
                            {
                                GameScores.Score += GameScores.Points[GameScores.iterator];
                                for (int k = 0; k < 8; ++k)
                                {
                                    if (GameScores.iterator < 30)
                                    {
                                        GameScores.iterator++;
                                    }
                                }
                            }
                            break;

                        case "Bomb":
                            GameScores.Bomb++;
                            break;

                        case "FullPower":
                            for (int l = 0; l < 128; ++l)
                            {
                                GameScores.IncrementPower();
                            }
                            break;

                        case "Life":
                            GameScores.Player++;
                            break;

                        case "Point":
                            GameScores.Bonus++;
                            break;

                        case "Power":
                            GameScores.IncrementPower();
                            if (GameScores.Power < 128)
                            {
                                GameScores.Score += GameScores.Points[0];
                            }
                            else
                            {
                                GameScores.Score += GameScores.Points[GameScores.iterator];
                                if (GameScores.iterator < 30)
                                {
                                    GameScores.iterator++;
                                }
                            }
                            break;

                        case "Star":
                            GameScores.Score += 500 + (10 * (GameScores.Graze / 3));
                            break;
                        }
                        GameObjects.Items[i].Hitpoints = 0;
                    }
                }
            }

            foreach (BulletEntity bullet in GameObjects.Bullets)
            {
                if (bullet.Owner != this && bullet.Colides(this))
                {
                    Hitpoints       -= bullet.Hitpoints;
                    bullet.Hitpoints = 0;
                }
            }

            Level();

            if (SwinGame.KeyDown(GameKeys.SHOOT))
            {
                Cannon();
            }

            if (SwinGame.KeyDown(GameKeys.BOMB) && GameScores.Bomb > 0 && _coolDown == 0)
            {
                foreach (BulletEntity bullet in GameObjects.Bullets)
                {
                    if (bullet.Owner != this)
                    {
                        GameObjects.AddItem(new ItemEntity(bullet.Position, ItemType.Star));
                        bullet.Hitpoints = 0;
                    }
                }

                foreach (ItemEntity item in GameObjects.Items)
                {
                    item.Flag = true;
                }

                GameScores.Bomb--;
                _coolDown = 60;
            }

            if (Y < 160)
            {
                foreach (ItemEntity item in GameObjects.Items)
                {
                    item.Flag = true;
                }
            }

            ProcessMovement();

            DrawEntity();

            if (_cannonAux > 0)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("YingYang" + (Tick % 64) / 8), (float)(X + 30) - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Width / 2), (float)Y - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Height / 2));
                SwinGame.DrawBitmap(GameResources.GameImage("YingYang" + (Tick % 64) / 8), (float)(X - 30) - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Width / 2), (float)Y - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Height / 2));
            }

            Tick++;

            if (_coolDown > 0)
            {
                _coolDown--;
            }
        }
        /// <summary>
        /// ProcessEvents, overide method.
        /// </summary>
        public override void ProcessEvents()
        {
            //process item collisions
            if (GameObjects.Items != null)
            {
                for (int i = 0; i < GameObjects.Items.Count; ++i)
                {
                    if (GameObjects.Items[i].Colides(this))
                    {
                        switch (GameObjects.Items[i].ItemType.ToString())
                        {
                        case "BigPower":
                            for (int j = 0; j < 5; ++j)
                            {
                                GameScores.IncrementPower();
                            }
                            if (GameScores.Power < 128)
                            {
                                GameScores.Score += GameScores.Points[0];
                            }
                            else
                            {
                                GameScores.Score += GameScores.Points[GameScores.iterator];
                                for (int k = 0; k < 8; ++k)
                                {
                                    if (GameScores.iterator < 30)
                                    {
                                        GameScores.iterator++;
                                    }
                                }
                            }
                            break;

                        case "Bomb":
                            GameScores.Bomb++;
                            break;

                        case "FullPower":
                            for (int l = 0; l < 128; ++l)
                            {
                                GameScores.IncrementPower();
                            }
                            break;

                        case "Life":
                            GameScores.Player++;
                            break;

                        case "Point":
                            GameScores.Bonus++;
                            break;

                        case "Power":
                            GameScores.IncrementPower();
                            if (GameScores.Power < 128)
                            {
                                GameScores.Score += GameScores.Points[0];
                            }
                            else
                            {
                                GameScores.Score += GameScores.Points[GameScores.iterator];
                                if (GameScores.iterator < 30)
                                {
                                    GameScores.iterator++;
                                }
                            }
                            break;

                        case "Star":
                            GameScores.Score += 500 + (10 * (GameScores.Graze / 3));
                            break;
                        }
                        GameObjects.RemoveItem(GameObjects.Items[i]);
                    }
                }
            }

            PowerLevel();

            if (SwinGame.KeyDown(GameKeys.SHOOT))
            {
                MainCannon();
                AuxCannon();
            }

            ProcessMovement();

            foreach (BulletEntity bullet in _bullets)
            {
                bullet.ProcessEvents();
            }

            for (int i = 0; i < _bullets.Count; ++i)
            {
                if (_bullets[i].Y < 0)
                {
                    _bullets.Remove(_bullets[i]);
                }
            }

            DrawEntity();

            if (_auxLevel > 0)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("YingYang" + (Tick % 64) / 8), (float)(X + 30) - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Width / 2), (float)Y - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Height / 2));
                SwinGame.DrawBitmap(GameResources.GameImage("YingYang" + (Tick % 64) / 8), (float)(X - 30) - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Width / 2), (float)Y - (GameResources.GameImage("YingYang" + (Tick % 64) / 8).Height / 2));
            }

            Tick++;
        }
Beispiel #5
0
        public void Cannon()
        {
            switch (_playerType)
            {
            case PlayerType.NarrowA:
                switch (_cannonMain)
                {
                case 0:
                    if (Tick % 6 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -90.0), -90.0, BulletColour.Blue, BulletType.Seed, this));
                    }
                    break;

                case 1:
                    if (Tick % 6 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -92.0), -92.0, BulletColour.Blue, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -88.0), -88.0, BulletColour.Blue, BulletType.Seed, this));
                    }
                    break;

                case 2:
                    if (Tick % 6 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -94.0), -94.0, BulletColour.Turquoise, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -90.0), -90.0, BulletColour.Blue, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -86.0), -86.0, BulletColour.Turquoise, BulletType.Seed, this));
                    }
                    break;

                case 3:
                    if (Tick % 6 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -98.0), -98.0, BulletColour.Green, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -94.0), -94.0, BulletColour.Turquoise, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -90.0), -90.0, BulletColour.Blue, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -86.0), -86.0, BulletColour.Turquoise, BulletType.Seed, this));
                        GameObjects.AddBullet(new BulletEntity(Position, new Velocity2D(8.0, -82.0), -82.0, BulletColour.Green, BulletType.Seed, this));
                    }
                    break;
                }
                switch (_cannonAux)
                {
                case 1:
                    if (Tick % 24 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                    }
                    break;

                case 2:
                    if (Tick % 36 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                    }
                    if ((Tick + 18) % 36 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 28, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Red, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 28, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Red, BulletType.Star, this));
                    }
                    break;

                case 3:
                    if (Tick % 24 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 32, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Purple, BulletType.Star, this));
                    }
                    if ((Tick + 12) % 24 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 28, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Red, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 28, Y), new Velocity2D(5.8, -90.0), -90.0, BulletColour.Red, BulletType.Star, this));
                    }
                    break;

                case 4:
                    if (Tick % 24 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 32, Y), new Velocity2D(5.8, -92.0), -92.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 32, Y), new Velocity2D(5.8, -88.0), -88.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 32, Y), new Velocity2D(5.8, -92.0), -92.0, BulletColour.Red, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 32, Y), new Velocity2D(5.8, -88.0), -88.0, BulletColour.Red, BulletType.Star, this));
                    }
                    if ((Tick + 12) % 24 == 0)
                    {
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 28, Y), new Velocity2D(5.8, -92.0), -92.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 28, Y), new Velocity2D(5.8, -88.0), -88.0, BulletColour.Purple, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X + 28, Y), new Velocity2D(5.8, -92.0), -92.0, BulletColour.Red, BulletType.Star, this));
                        GameObjects.AddBullet(new BulletEntity(new Point2D(X - 28, Y), new Velocity2D(5.8, -88.0), -88.0, BulletColour.Red, BulletType.Star, this));
                    }
                    break;
                }
                break;

            case PlayerType.NarrowB:
                break;

            case PlayerType.WideA:
                break;

            case PlayerType.WideB:
                break;
            }
        }