Пример #1
0
        public override void Paint()
        {
            if (Registers.gameState == GameState.Running)
            {
                GAME_ENGINE.SetColor(200, 50, 0);

                drawHere = Utils.Lerp2D(origin, dest, curTime / 2);
                GAME_ENGINE.FillRectangle(drawHere.X, drawHere.Y, 5, 5);
                GAME_ENGINE.DrawLine(origin, new Vector2f(drawHere.X + 2.5f, drawHere.Y + 2.5f), 5f);

                //Explode when ,missile has reached its destination
                if (Utils.Distance(drawHere, dest) <= 1)
                {
                    if (targetID <= gameManager.GetBuildings().Count - 1)
                    {
                        explM = new Explosion(gameManager, enemySpawner, this, drawHere, gameManager.GetBuildings()[targetID], 0);
                    }
                    Console.WriteLine(string.Format("Explosions #{0}", gameManager.explosions.Count));
                    enemySpawner.EMissileDetonate(this);
                    Dispose();
                }
                curTime += GAME_ENGINE.GetDeltaTime() / 2.5f;

                //Destroy missile when out of screen
                if (Utils.Distance(drawHere, new Vector2f(Alignment.X.Left, Alignment.Y.Up)) <= 0 && Utils.Distance(drawHere, new Vector2f(Alignment.X.Right, Alignment.Y.Down)) <= 0)
                {
                    enemySpawner.EMissileDetonate(this);
                    Dispose();
                }
            }
        }
Пример #2
0
        public override void Update()
        {
            if (Registers.gameState == GameState.Running)
            {
                timeLeft -= GAME_ENGINE.GetDeltaTime();
                if (timeLeft <= 0)
                {
                    int targ = rng.Next(0, targets.Count);
                    emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targ], targ);
                    emissiles.Add(emis);

                    //60% chance a second missile will spawn
                    if (Utils.Chance(60))
                    {
                        int targSec = rng.Next(0, targets.Count);
                        emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targSec], targSec);
                        emissiles.Add(emis);
                    }
                    //20% chance a third missile will spawn
                    if (Utils.Chance(20))
                    {
                        int targThr = rng.Next(0, targets.Count);
                        emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targThr], targThr);
                        emissiles.Add(emis);
                    }
                    timeLeft = interval;
                }
            }
        }
Пример #3
0
        public override void Paint()
        {
            if (Registers.gameState == GameState.Running)
            {
                //Type = 0, friendly missile
                //Type = 1, enemy missile
                if (type == 0)
                {
                    GAME_ENGINE.SetColor(rda.Next(0, 255), rda.Next(0, 255), rda.Next(0, 255));
                    GAME_ENGINE.FillEllipse(rec_explosion);
                }
                else
                {
#if (DEBUG)
                    GAME_ENGINE.DrawBitmap(explosion_bmp, ExplosionLocationTopLeft);
#endif
                }

                duration -= GAME_ENGINE.GetDeltaTime() * 2.4f;
                if (nukeTown != null && nuked == false)
                {
                    List <Building> checkBuildings = gm.GetBuildings();
                    for (int i = 0; i < 6; i++)
                    {
                        if (i == 5)
                        {
                            Console.WriteLine(string.Format("Size: {0}", checkBuildings.Count));
                            i = 5;
                        }
                        if (checkBuildings[i] == null)
                        {
                            continue;
                        }
                        if (Utils.Distance(new Vector2f(checkBuildings[i].GetX() + checkBuildings[i].GetWidth() * 0.5f,
                                                        checkBuildings[i].GetY() + checkBuildings[i].GetHeight()), ExplosionLocation) < 40f)
                        {
                            Console.WriteLine(string.Format("Building hit! {0}", i));
                            nukeTown.Nuke();
                            nuked = true;
                            break;
                        }
                    }
                }
                if (type == 0)
                {
                    ExplosionCollision();
                }
                if (duration <= 0f)
                {
                    Dispose();
                }
            }
        }
Пример #4
0
        public override void Paint()
        {
            if (Registers.gameState == GameState.Running)
            {
                GAME_ENGINE.SetColor(0, 255, 0);

                drawHere = Utils.Lerp2D(orgin, dest, curTime);
                GAME_ENGINE.FillRectangle(drawHere.X, drawHere.Y, 5, 5);
                GAME_ENGINE.DrawLine(orgin, drawHere);
                if (Utils.Distance(drawHere, dest) <= 1)
                {
                    explM = new Explosion(gameManager, missileLauncher, this, drawHere);
                    Console.WriteLine(string.Format("Explosions #{0}", gameManager.explosions.Count));
                    missileLauncher.MissileDetonate(this);
                    Dispose();
                }
                curTime += GAME_ENGINE.GetDeltaTime() * 2f;

                if (misLocY <= 0)
                {
                    Dispose();
                }
            }
        }
        public override void Update()
        {
            missileLauncher.ForwardCollision();
            if (GAME_ENGINE.GetKey(Key.Escape))
            {
                if (Registers.gameState == GameState.Error)
                {
                    GAME_ENGINE.Quit();
                }
                if (Registers.gameState == GameState.Running)
                {
                    Registers.gameState = GameState.Paused;
                }
                if (Registers.gameState == GameState.Stopped)
                {
                    GAME_ENGINE.Quit();
                }
            }
            if (GAME_ENGINE.GetKey(Key.ShiftKey))
            {
                Registers.sprint = true;
            }
            else
            {
                Registers.sprint = false;
            }
            if (GAME_ENGINE.GetMouseButtonDown(0) && Registers.gameState == GameState.Paused)
            {
            }
            if (Registers.gameState == GameState.Running)
            {
                if (GAME_ENGINE.GetKeyDown(Key.Space))
                {
                    Registers.fireNow = true;
                }
                //make the crosshair move faster when shift is held
                if (Registers.sprint == false)
                {
                    float speedMultiplier = 1.1f;
                    if (GAME_ENGINE.GetKey(Key.W))
                    {
                        Registers.CrosshairY -= aimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.S) && Registers.CrosshairY < Alignment.Y.Down - 70)
                    {
                        Registers.CrosshairY += aimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.D))
                    {
                        Registers.CrosshairX += aimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.A))
                    {
                        Registers.CrosshairX -= aimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                }
                else
                {
                    float speedMultiplier = 1.3f;
                    if (GAME_ENGINE.GetKey(Key.W))
                    {
                        Registers.CrosshairY -= shiftAimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.S) && Registers.CrosshairY < Alignment.Y.Down - 70)
                    {
                        Registers.CrosshairY += shiftAimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.D))
                    {
                        Registers.CrosshairX += shiftAimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                    if (GAME_ENGINE.GetKey(Key.A))
                    {
                        Registers.CrosshairX -= shiftAimspeed * GAME_ENGINE.GetDeltaTime() * speedMultiplier;
                    }
                }
            }

            //Trigger the error screen by force
            if (GAME_ENGINE.GetKeyDown(Key.F12))
            {
                Registers.gameState = GameState.Error;
            }
            if (GAME_ENGINE.GetKeyUp(Key.F12))
            {
                Registers.gameState = GameState.Running;
            }


            //RESETING THE GAME CAN CAUSE PROBLEMS
            if (GAME_ENGINE.GetKeyDown(Key.R) && Registers.gameState == GameState.Stopped)
            {
                Registers.gameState = GameState.Reseting;

                Registers.CrosshairX = Alignment.X.Center;
                Registers.CrosshairY = Alignment.Y.Center;

                cities.Clear();
                for (int i = 0; i < 6; i++)
                {
                    cities.Add(new Building(this, i));
                }
                GC.Collect();
                destroyedCities     = 0;
                Registers.gameState = GameState.Running;
            }

            //Force lose the game
            if (GAME_ENGINE.GetKeyDown(Key.F2))
            {
                destroyedCities = 6;
            }

            //Enable all cities
            if (GAME_ENGINE.GetKeyDown(Key.F3))
            {
                destroyedCities     = 0;
                Registers.gameState = GameState.Running;
            }
        }