Example #1
0
        public virtual bool Collision(PlayerVehicle p)
        {
            //return false;
            bool cond = false;

            if (!(p.isInvisible) || ((p.isInvisible) &&
                                     (GetObstacleType == ObstacleType.Fuel ||
                                      GetObstacleType == ObstacleType.Invisible ||
                                      GetObstacleType == ObstacleType.Life ||
                                      GetObstacleType == ObstacleType.Score ||
                                      GetObstacleType == ObstacleType.Turbo)))
            {
                cond  = SwinGame.PointInRect(SwinGame.PointAt((float)X, (float)Y), (float)p.X - WIDTH, (float)p.Y - HEIGHT, WIDTH, HEIGHT);
                cond |= SwinGame.PointInRect(SwinGame.PointAt((float)X - WIDTH, (float)Y), (float)p.X - WIDTH, (float)p.Y - HEIGHT, WIDTH, HEIGHT);
                cond |= SwinGame.PointInRect(SwinGame.PointAt((float)X, (float)Y - HEIGHT), (float)p.X - WIDTH, (float)p.Y - HEIGHT, WIDTH, HEIGHT);
                cond |= SwinGame.PointInRect(SwinGame.PointAt((float)X - WIDTH, (float)Y - HEIGHT), (float)p.X - WIDTH, (float)p.Y - HEIGHT, WIDTH, HEIGHT);
                if (!p.isInvisible && cond &&
                    (
                        GetObstacleType == ObstacleType.Car ||
                        GetObstacleType == ObstacleType.Lorry ||
                        GetObstacleType == ObstacleType.Motorcycle
                    ))
                {
                    SwinGame.PlaySoundEffect("error.wav");
                }
                return(cond);
            }
            return(false);
        }
Example #2
0
 public GameController()
 {
     gameBoard = new GameBoard();
     ScoreBoard.Initialize(0, 3, 1, "Peak Hours");
     p              = new PlayerVehicle(415, 570);
     p.SpeedX       = 100;
     p.SpeedY       = 100;
     p.Acceleration = 0;
 }
Example #3
0
 public void RandomSpawnVehicle(PlayerVehicle p, Obstacle o)
 {
     _spawnpoints = _random.Next(0, 3);
     o.X          = positionX [_spawnpoints];
     o.Y          = UtilityFunction.InitialY;
     DifficultyHandler(p, o);
     Obstacles.Add(o);
     o.Draw();
 }
Example #4
0
        internal void MoveObstacle(PlayerVehicle p)
        {
            for (int i = 1; i < debugPattern.Count; i++)
            {
                SwinGame.DrawText(debugPattern [i].Y.ToString() + " " + debugPattern [i].X.ToString(),
                                  Color.AliceBlue,
                                  0, 12 * i);
            }
            for (int i = 0; i < _obstacles.Count; i++)
            {
                _obstacles[i].Drop(p);
                if (_obstacles [i].Y >= 600 || _obstacles [i].Collision(p) == true)
                {
                    if (_obstacles [i].Collision(p) == true)
                    {
                        if (_obstacles [i] is Invisible)
                        {
                            p.Transparent = true;
                            PlayerVehicle.sw.Restart();
                            p.isInvisible = true;
                            p.Draw();
                        }

                        ScoreBoard.Life += _obstacles [i].LifeReward;

                        if (_obstacles [i] is Score)
                        {
                            ScoreBoard.Score += 10;
                        }

                        if (_obstacles [i] is Bomb)
                        {
                            ScoreBoard.Life = 0;
                            SwinGame.PlaySoundEffect("Bomb.wav");
                            SwinGame.DrawBitmap("explosion1.png", (float)xMin, (float)yMin);
                        }

                        if (_obstacles [i] is Turbo)
                        {
                            p.speed   = true;
                            p.SpeedX += 100;
                            p.SpeedY += 100;
                        }
                    }
                    if (_obstacles [i].GetObstacleType == ObstacleType.Bomb ||
                        _obstacles [i].GetObstacleType == ObstacleType.Car ||
                        _obstacles [i].GetObstacleType == ObstacleType.Lorry ||
                        _obstacles [i].GetObstacleType == ObstacleType.Motorcycle)
                    {
                        ScoreBoard.Score += 1;
                    }
                    _obstacles.Remove(_obstacles [i]);
                    i--;
                }
            }
        }
Example #5
0
        public bool RandomSpawnVehicle(Car c, ScoreBoard s, PlayerVehicle p)
        {
            while (_spawnpoints == 4)
            {
                _spawnpoints = _random.Next(0, 3);
                if (_spawnpoints == 0)
                {
                    c.X = 320;
                }
                else if (_spawnpoints == 1)
                {
                    c.X = 415;
                }
                else if (_spawnpoints == 2)
                {
                    c.X = 510;
                }
            }


            if (s1.Elapsed.TotalSeconds > 20 && s1.Elapsed.TotalSeconds <= 40)
            {
                c.Speed = 5;
                s.Stage = 2;
            }
            else if (s1.Elapsed.TotalSeconds > 40 && s1.Elapsed.TotalSeconds <= 60)
            {
                c.Speed = 10;
                s.Stage = 3;
            }


            c.Drop();
            c.Draw();


            if (c.Collision(p) == true)
            {
                s.Decrement();
            }
            else if (c.Y == 570 && c.Collision(p) != true)
            {
                _obstacles.Add(c);
            }


            if (c.Y == 600)
            {
                Spawnpoints = 4;
                return(_spawned = true);
            }
            else
            {
                return(_spawned = false);
            }
        }
Example #6
0
        public void TestDrop()
        {
            Car           car = new Car(GameController.startLane1X, GameController.startLaneY);
            PlayerVehicle p   = new PlayerVehicle(GameController.startLane2X, 20);

            car.Drop(p);
            car.SpeedY = 100;
            SwinGame.Delay(10);
            car.Drop(p);
            Assert.AreNotEqual(GameController.startLaneY - car.SpeedY * 10, car.Y);
        }
Example #7
0
        public void TestSpawnVehicle()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);

            ScoreBoard.Initialize(0, 3, 1, "Peak Hours");
            Car c = new Car(415, 20);

            gb.RandomSpawnVehicle(p, c);
            Assert.AreEqual(UtilityFunction.InitialY, c.Y);
        }
Example #8
0
        public void TestSpawnVehicle()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);
            ScoreBoard    s  = new ScoreBoard(0, 3, 1, "Peak Hours");
            Car           c  = new Car(415, 20);
            Lorry         l  = new Lorry(415, 20);
            Motorcycle    m  = new Motorcycle(415, 20);
            Fuel          f  = new Fuel(415, 20);

            gb.RandomSpawnVehicle(c, s, p);
            Assert.AreEqual(22.5, c.Y);
        }
Example #9
0
        public void TestNagivate()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);

            ScoreBoard.Initialize(0, 0, 1, "Peak Hours");
            //right
            p.SpeedX = 10000;
            p.SpeedY = 10000;
            SwinGame.Delay(20);
            p.UpdateTime();
            p.NavigateRight();
            Assert.AreEqual(GameController.startLane3X + 20, p.X);
        }
Example #10
0
        public void Testspeed()
        {
            //Ensure that speed must be manually changed
            Car c = new Car(415, 20);

            UtilityFunction.currentDifficulty = GameDifficulty.Easy;
            c.SpeedY       = 0;
            c.Acceleration = 1000;
            Assert.AreEqual(0, c.SpeedY);
            SwinGame.Delay(1);
            PlayerVehicle p = new PlayerVehicle(415, 570);

            c.Drop(p);
            Assert.IsTrue(c.SpeedY > 1);
        }
Example #11
0
        public void TestDrop()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);
            ScoreBoard    s  = new ScoreBoard(0, 3, 1, "Peak Hours");
            Car           c  = new Car(415, 20);
            Lorry         l  = new Lorry(415, 20);
            Motorcycle    m  = new Motorcycle(415, 20);
            Fuel          f  = new Fuel(415, 20);


            while (gb.Spawned == false)
            {
                gb.RandomSpawnVehicle(c, s, p);
            }

            Assert.AreEqual(620, c.Y);
        }
Example #12
0
        public void Testspeed()
        {
            GameBoard gb = new GameBoard();
            Stopwatch s1 = Stopwatch.StartNew();

            s1.Start();
            PlayerVehicle p = new PlayerVehicle(415, 570);
            ScoreBoard    s = new ScoreBoard(0, 0, 1, "Peak Hours");
            Car           c = new Car(415, 20);
            Lorry         l = new Lorry(415, 20);
            Motorcycle    m = new Motorcycle(415, 20);
            Fuel          f = new Fuel(415, 20);


            gb.RandomSpawnVehicle(c, s, p);

            Assert.AreEqual(2.5, c.Speed);
        }
Example #13
0
        public void TestgameOver()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);
            ScoreBoard    s  = new ScoreBoard(0, 0, 1, "Peak Hours");
            Car           c  = new Car(415, 20);
            Lorry         l  = new Lorry(415, 20);
            Motorcycle    m  = new Motorcycle(415, 20);
            Fuel          f  = new Fuel(415, 20);

            if (gb.GameOver(s) == true)
            {
                s.Life  = 3;
                s.Score = 1;
            }


            Assert.AreEqual(3, s.Life);
        }
Example #14
0
        public void TestNagivate()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);
            ScoreBoard    s  = new ScoreBoard(0, 0, 1, "Peak Hours");
            Car           c  = new Car(415, 20);
            Lorry         l  = new Lorry(415, 20);
            Motorcycle    m  = new Motorcycle(415, 20);
            Fuel          f  = new Fuel(415, 20);

            //right
            p.NavigateRight();
            Assert.AreEqual(510, p.X);
            //middle
            p.NavigateLeft();
            Assert.AreEqual(415, p.X);
            //left
            p.NavigateLeft();
            Assert.AreEqual(320, p.X);
        }
Example #15
0
        public void TestgameOver()
        {
            GameBoard     gb = new GameBoard();
            PlayerVehicle p  = new PlayerVehicle(415, 570);

            ScoreBoard.Initialize(0, 0, 1, "Peak Hours");
            Car        c  = new Car(415, 20);
            Lorry      l  = new Lorry(415, 20);
            Motorcycle m  = new Motorcycle(415, 20);
            Fuel       f  = new Fuel(415, 20);
            Life       lf = new Life(415, 20);
            Invisible  i  = new Invisible(415, 20);
            Score      s  = new Score(415, 20);
            Bomb       b  = new Bomb(415, 20);
            Turbo      t  = new Turbo(415, 20);

            if (gb.GameOver() == true)
            {
                ScoreBoard.Life  = 3;
                ScoreBoard.Score = 1;
            }
            Assert.AreEqual(3, ScoreBoard.Life);
        }
Example #16
0
        public virtual void Drop(PlayerVehicle p)
        {
            _curTime = DateTime.Now;
            double prevY = Y;

            if (Y < END)
            {
                _speedY += _curTime.Subtract(_prevTime).TotalMilliseconds / 1000 * _acc;
                Y       += _curTime.Subtract(_prevTime).TotalMilliseconds / 1000 * SpeedY;
            }
            if (PatternQueue.Count > 0)
            {
                if (Y >= PatternQueue.Peek().Y)
                {
                    int xDirection = Math.Sign(_patternQueue.Peek().X - _x);
                    SpeedX = SpeedY * xDirection * 2 > 500 ? 500:SpeedY * xDirection * 2;
                    nextX  = PatternQueue.Peek().X;
                }
                if ((Math.Abs(X - nextX) < 5))
                {
                    X = nextX;
                }
            }
            if ((Math.Abs(X - nextX) < 0.01))
            {
                SpeedX = 0;
            }
            else if (X >= minX && X <= maxX)
            {
                double tempX = X + _curTime.Subtract(_prevTime).TotalMilliseconds / 1000 * SpeedX;
                if (tempX >= minX && tempX <= maxX)
                {
                    X += _curTime.Subtract(_prevTime).TotalMilliseconds / 1000 * SpeedX;
                }
            }
            _prevTime = _curTime;
        }
Example #17
0
        public static void Main()
        {
            //Open the game window
            SwinGame.OpenGraphicsWindow("GameMain", 900, 650);


            GameBoard gb = new GameBoard();

            gb.BackgroundColor = SwinGame.RandomRGBColor(255);
            ObstacleType  obstacleToAdd = ObstacleType.Car;
            PlayerVehicle p             = new PlayerVehicle(415, 570);
            ScoreBoard    s             = new ScoreBoard(0, 3, 1, "Peak Hours");

            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                Random     _random = new Random();
                int        _chance = _random.Next(0, 10);
                Car        c       = new Car(415, 20);
                Lorry      l       = new Lorry(415, 20);
                Motorcycle m       = new Motorcycle(415, 20);
                Fuel       f       = new Fuel(415, 20);



                if (_chance == 0 || _chance == 1 || _chance == 2)
                {
                    obstacleToAdd = ObstacleType.Car;
                }
                else if (_chance == 3 || _chance == 4 || _chance == 5)
                {
                    obstacleToAdd = ObstacleType.Lorry;
                }
                else if (_chance == 6 || _chance == 7 || _chance == 8)
                {
                    obstacleToAdd = ObstacleType.Motorcycle;
                }
                else if (_chance == 9)
                {
                    obstacleToAdd = ObstacleType.Fuel;
                }
                SwinGame.ProcessEvents();
                SwinGame.ClearScreen(Color.White);

                gb.Draw();
                gb.Spawned = false;


                while (gb.Spawned == false)
                {
                    //Fetch the next batch of UI interaction
                    SwinGame.ProcessEvents();

                    //Clear the screen and draw the framerate
                    SwinGame.ClearScreen(Color.White);
                    gb.Draw();

                    if (obstacleToAdd == ObstacleType.Car)
                    {
                        gb.RandomSpawnVehicle(c, s, p);
                    }
                    else if (obstacleToAdd == ObstacleType.Lorry)
                    {
                        gb.RandomSpawnVehicle(l, s, p);
                    }
                    else if (obstacleToAdd == ObstacleType.Motorcycle)
                    {
                        gb.RandomSpawnVehicle(m, s, p);
                    }
                    else if (obstacleToAdd == ObstacleType.Fuel)
                    {
                        gb.RandomSpawnVehicle(f, s, p);
                    }

                    if (SwinGame.KeyTyped(KeyCode.vk_LEFT))
                    {
                        p.NavigateLeft();
                    }
                    else if (SwinGame.KeyTyped(KeyCode.vk_RIGHT))
                    {
                        p.NavigateRight();
                    }
                    p.Draw();

                    SwinGame.DrawText("Score:" + s.Score.ToString(), Color.Black, 10, 100);
                    SwinGame.DrawText("Life:" + s.Life.ToString(), Color.Black, 10, 150);
                    SwinGame.DrawText("Stage:" + s.Stage.ToString(), Color.Black, 10, 200);
                    SwinGame.DrawText("Speed:" + s.Traffic.ToString(), Color.Black, 10, 350);
                    SwinGame.DrawText("Right Arrow key to move right", Color.Black, 10, 250);
                    SwinGame.DrawText("Left Arrow key to move left", Color.Black, 10, 300);
                    SwinGame.DrawFramerate(0, 0);

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

                gb.GetScore(s);
                gb.ClearScreen();
                gb.DisplaySpeed(s);
                if (gb.GameOver(s) == true)
                {
//
//					if (SwinGame.KeyTyped (KeyCode.vk_y))
//					{
//						SwinGame.ClearScreen();
//						s.Life = 3;
//						s.Score = 0;
//					}
//					else if (SwinGame.KeyTyped (KeyCode.vk_n))
//					{
//						do
//						{
//							SwinGame.DrawBitmapOnScreen (new Bitmap("thankyou.jpg"), 0, 0);
//							SwinGame.RefreshScreen (60);
//							SwinGame.ReleaseBitmap("thankyou.jpg");
//						} while (false == SwinGame.WindowCloseRequested ());
//					}
//					else
//					{
//							do
//							{
//							SwinGame.DrawBitmapOnScreen(new Bitmap("gameover.jpg"), 0, 0);
//								SwinGame.RefreshScreen (25);
//							SwinGame.ReleaseBitmap("gameover.jpg");
//							} while (false == SwinGame.WindowCloseRequested());
//					}

                    do
                    {
                        SwinGame.ProcessEvents();
                        SwinGame.DrawBitmapOnScreen(new Bitmap("gameover.jpg"), 0, 0);
                        SwinGame.RefreshScreen(60);
                        SwinGame.ReleaseBitmap("gameover.jpg");
                    } while (SwinGame.AnyKeyPressed() == false);
                    //}while (!(SwinGame.KeyTyped (KeyCode.vk_y)) || !(SwinGame.KeyTyped (KeyCode.vk_n)) );

                    if (SwinGame.KeyTyped(KeyCode.vk_y))
                    {
                        s.Life  = 3;
                        s.Score = 0;
                        gb.RestartTimer();
                    }
                    else if (SwinGame.KeyTyped(KeyCode.vk_n))
                    {
                        do
                        {
                            SwinGame.DrawBitmapOnScreen(new Bitmap("thankyou.jpg"), 0, 0);
                            SwinGame.RefreshScreen(60);
                            SwinGame.ReleaseBitmap("thankyou.jpg");
                        } while (false == SwinGame.WindowCloseRequested());
                    }
                }

                SwinGame.DrawFramerate(0, 0);

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
Example #18
0
 public abstract bool Collision(PlayerVehicle p);
Example #19
0
        void DifficultyHandler(PlayerVehicle p, Obstacle o)
        {
            //difficulty control
            if (UtilityFunction.currentDifficulty.Equals(GameDifficulty.Easy))
            {
                o.SpeedY       = 200 + (ScoreBoard.Stage - 1) * 100;
                o.Acceleration = 0;
            }

            if (UtilityFunction.currentDifficulty.Equals(GameDifficulty.Medium))
            {
                o.SpeedY       = 200;
                o.Acceleration = 500 + (ScoreBoard.Stage - 1) * 100;
            }

            if (UtilityFunction.currentDifficulty.Equals(GameDifficulty.Hard))
            {
                o.SpeedY       = 200 + (ScoreBoard.Stage - 1) * 100;
                o.Acceleration = 500 + (ScoreBoard.Stage - 1) * 100;
            }
            if (UtilityFunction.currentDifficulty.Equals(GameDifficulty.Extreme))
            {
                o.SpeedY       = 400 + (ScoreBoard.Stage - 1) * 100;
                o.SpeedX       = 400;
                o.Acceleration = 0 + (ScoreBoard.Stage - 1) * 100;
                int desiredPositionCount = 2;
                int prevX = (int)o.X;
                //debugPattern.Clear ();
                for (int i = 0; i < desiredPositionCount; i++)
                {
                    Pattern pattern = new Pattern();
                    pattern.Y = _random.Next(0, (int)((double)(yFullRange - desiredPositionCount * 100) / desiredPositionCount))
                                + ((double)(yFullRange - desiredPositionCount * 100) / desiredPositionCount + 100) * i;
                    int xTemp = prevX;
                    while (xTemp == prevX)
                    {
                        xTemp = positionX [(_random.Next(0, 3))];
                    }
                    pattern.X = xTemp;
                    prevX     = (int)pattern.X;
                    o.PatternQueue.Enqueue(pattern);
                }
            }
            ScoreBoard.Stage = (int)(s1.Elapsed.TotalSeconds / 5) + 1;
            if (ScoreBoard.Stage % 5 == 0)
            {
                if (_stage == GameStage.NormalStage)
                {
                    Font font = new Font("Notification", "arial.ttf", 36);
                    font.FontStyle = FontStyle.BoldFont;
                    s1.Stop();
                    SwinGame.DrawBitmap("bg2.jpg", 0, 0);
                    SwinGame.DrawText("BONUS STAGE! READY...3", Color.Magenta, "Notification", new Point2D()
                    {
                        X = 200, Y = 300
                    });
                    SwinGame.RefreshScreen(60);
                    SwinGame.Delay(1000);
                    SwinGame.DrawBitmap("bg2.jpg", 0, 0);
                    SwinGame.DrawText("BONUS STAGE! READY...2", Color.Magenta, "Notification", new Point2D()
                    {
                        X = 200, Y = 300
                    });
                    SwinGame.RefreshScreen(60);
                    SwinGame.Delay(1000);
                    SwinGame.DrawBitmap("bg2.jpg", 0, 0);
                    SwinGame.DrawText("BONUS STAGE! READY...1", Color.Magenta, "Notification", new Point2D()
                    {
                        X = 200, Y = 300
                    });
                    SwinGame.RefreshScreen(60);
                    SwinGame.Delay(1000);
                    s1.Start();
                    font.Dispose();
                    p.X = GameController.startLane2X;
                    p.Y = 600;
                }
                _stage = GameStage.BonusStage;
            }
            else
            {
                _stage = GameStage.NormalStage;
            }
        }
Example #20
0
 public override bool Collision(PlayerVehicle p)
 {
     return(SwinGame.PointInRect(SwinGame.PointAt((float)X, (float)Y), (float)p.X, (float)p.Y, 1, 1));
 }