Example #1
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            /*// How much time change has there been?
             * long time = stopwatch.ElapsedMilliseconds;
             * float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds
             * lastTime = time;
             * foreach (Polygon p in world)
             *  p.Advance(delta);
             * player.Advance(delta);
             * playerSpeed.Y = playerSpeed.Y * 9.8f;
             * playerLoc += playerSpeed * delta;
             * if (playerLoc.X < playerMinX)
             *  playerLoc.X = playerMinX;
             * else if (playerLoc.X > playerMaxX)
             *  playerLoc.X = playerMaxX;
             * playerSpeed.Y = 0;
             * playerLoc += playerSpeed * delta;
             * if (playerLoc.X < playerMinX)
             *  playerLoc.X = playerMinX;
             * else if (playerLoc.X > playerMaxX)
             *  playerLoc.X = playerMaxX;*/

            // How much time change has there been?
            long  time             = stopwatch.ElapsedMilliseconds;
            long  power_start_time = 0;
            float delta            = (time - lastTime) * 0.001f; // Delta time in milliseconds

            lastTime = time;

            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }

                player.Advance(step);
                basketball.Advance(step);
                foreach (Wolverine wolverine in wolverines)
                {
                    wolverine.Advance(step);
                }
                foreach (Sword p in swords)
                {
                    p.Advance(step);
                    if (p.P.X > 15)
                    {
                        sword_to_remove = p;
                    }
                }
                swords.Remove(sword_to_remove);
                //sword_sprite.Advance(step);

                /* foreach (Polygon p in world)
                 * {
                 *   p.Advance(step);
                 * }*///Some refactoring
                foreach (Polygon p in world)
                {
                    p.Advance(step);
                    if (collision.Test(player, p))
                    {
                        //powerup.Add(basketball);
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                        }

                        player.V = v;
                        player.Advance(0);
                    }
                    else if (player.P.X > 10)
                    {
                        //Restart();
                        //Microsoft.DirectX.Direct3D.Font font = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 40f));
                        //font.DrawText(null, "You Win!" + score, new Point(3, 3), Color.Black);
                        game_over = true;
                        //while (true) { ; }
                    }
                    if (collision.Test(basketball, p))
                    {
                        //powerup.Add(basketball);
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        basketball.P = basketball.P + collision.N * depth;
                        Vector2 v2 = basketball.V;
                        if (collision.N.X != 0)
                        {
                            v2.X = -v2.X;
                        }
                        if (collision.N.Y != 0)
                        {
                            v2.Y = -0.5f;
                        }

                        basketball.V = v2;
                        basketball.Advance(0);
                    }
                    foreach (Wolverine wolverine in wolverines)
                    {
                        if (collision.Test(wolverine, p))
                        {
                            //powerup.Add(basketball);
                            float depth = collision.P1inP2 ?
                                          collision.Depth : -collision.Depth;
                            wolverine.P = wolverine.P + collision.N * depth;
                            Vector2 v3 = wolverine.V;
                            Vector2 v4 = wolverine.P;
                            if (collision.N.X != 0)
                            {
                                v4.X = v4.X + 1;
                            }
                            v3.X = -v3.X;
                            if (collision.N.Y != 0)
                            {
                                v3.Y = 0;
                            }

                            wolverine.P = v4;
                            wolverine.V = v3;
                            wolverine.Advance(0);
                        }
                    }
                }

                if (collision.Test(pt, player))
                {
                    Vector2 v = basketball.V;
                    v.X = .5f;
                    //v.Y = -0.5f;

                    if (powerup.Count < 1)
                    {
                        basketball.P = new Vector2(1.5f, 3.7f);
                        basketball.V = v;
                        powerup.Add(basketball);
                    }
                }

                foreach (Polygon p in powerup)
                {
                    if (collision.Test(p, player))
                    {
                        //powerup.Remove(basketball);
                        powerup_to_remove = p;
                        player.Tex        = spritepowertexture;
                        power_start_time  = time;
                    }
                }
                powerup.Remove(powerup_to_remove);

                if (power_start_time != 0)
                {
                    if ((time - power_start_time) > 5)
                    {
                        player.Tex = spritetexture;
                    }
                }

                foreach (Polygon p in coins)
                {
                    //p.Advance(step);
                    if (collision.Test(player, p))
                    {
                        coin_to_remove = p;
                        sound.Coin();
                        score += 100;
                        //coins.Remove(p);
                    }
                }

                coins.Remove(coin_to_remove);

                foreach (Sword s in swords)
                {
                    foreach (Wolverine p in wolverines)
                    {
                        /*if (collision.Test(s, p))
                         * {
                         *  wolverine_to_remove = p;
                         *  sword_to_remove = s;
                         *  sound.Death();
                         * }*/


                        if (Math.Abs(s.P.X - .7f - p.P.X) < .01 && Math.Abs(s.P.Y - p.P.Y) < 1)
                        {
                            sword_to_remove     = s;
                            wolverine_to_remove = p;
                            score += 250;
                            sound.Death();
                        }
                    }
                }

                wolverines.Remove(wolverine_to_remove);
                swords.Remove(sword_to_remove);

                foreach (Wolverine w in wolverines)
                {
                    if (Math.Abs(player.P.X - w.P.X - 3.5) < .6 && Math.Abs(player.P.Y - w.P.Y) < 1)
                    {
                        Restart();
                    }
                }


                delta -= step;
            }
        }
Example #2
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long time = stopwatch.ElapsedMilliseconds;

            score = 1000 - (int)time / 100;
            if (score < 0)
            {
                Defeat();
            }
            currentPlat = null;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;

            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }



                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }

                player.Advance(step);

                foreach (Polygon p in world)
                {
                    p.Advance(step);
                }
                player.isStanding = false;
                foreach (Polygon p in world)
                {
                    if (collision.Test(player, p))
                    {
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (p is Projectile)
                        {
                            if (collision.N.Y != -1 && collision.N.X == 0)
                            {
                                sounds.Attack();
                                v.Y      = -1 * player.V.Y;
                                v.Y      = (v.Y < 5) ? v.Y : 5;
                                player.V = v;
                                ((Projectile)p).DropRate = -5;
                                continue;
                            }
                            else
                            {
                                PlayerDied();
                                continue;
                            }
                        }
                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                            if (collision.N.Y != -1)
                            {
                                //Check that player didn't just hit its head on ceiling
                                player.isStanding = true;
                            }
                            if (p is Platform)
                            {
                                Platform x  = (Platform)p;
                                Vector2  v2 = player.V;
                                v.Y               = x.GetSpeed;
                                player.V          = v;
                                player.isStanding = true;
                            }
                            if (p is HorizontalPlat)
                            {
                                HorizontalPlat x  = (HorizontalPlat)p;
                                Vector2        v2 = player.V;
                                currentPlat       = x;
                                v.X               = x.GetSpeed;
                                player.isStanding = true;
                            }
                            if (p is EndPlat)
                            {
                                Victory();
                                return;
                            }
                        }


                        player.V = v;
                        player.Advance(0);
                    }
                }
                world  = projectileGen.Advance(delta, world);
                delta -= step;
            }
            //Check to see if we need a reset
            if (player.P.Y < -.5f)
            {
                PlayerDied();
            }
        }
Example #3
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long  time  = stopwatch.ElapsedMilliseconds;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;


            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }
                player.PostStood(stood);  // post stood condition variable to GameSprite object
                player.Advance(step);

                foreach (Polygon p in world)
                {
                    p.Advance(step);
                }

                foreach (Polygon p in world)
                {
                    if (collision.Test(player, p))
                    {
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y   = 0;
                            stood = true;
                        }



                        //
                        if (p.ismapped)
                        {
                            score.AddFlyingScore(-1, PlayerFeet().X, PlayerFeet().Y, lastTime);
                        }



                        // IF PLAYER is not on GROUND and touches a MONSTER!!!
                        if (p.isMonster && player.V.Y != 0)
                        {
                            v.Y   = 5.5f;
                            stood = false;

                            v.X = -10.5f;

                            player.A = new Vector2(0, -6.8f);

                            if (p.points_to_give > 0)
                            {
                                if (p.is2)
                                {
                                    v.X = -125.5f;
                                    score.AddFlyingScore(2, PlayerFeet().X, PlayerFeet().Y, lastTime);
                                    p.points_to_give   += 1; // this will always give points
                                    lives.lives_number -= 1;
                                    if (lives.lives_number < 1)
                                    {
                                        lives.lives_number = 0;
                                        game_over.gameOver = true;
                                    }
                                }
                                if (p.is748)
                                {
                                    score.AddFlyingScore(748, PlayerFeet().X, PlayerFeet().Y, lastTime);
                                    v.X = -25.5f;
                                    lives.lives_number -= 1;
                                    if (lives.lives_number < 1)
                                    {
                                        lives.lives_number = 0;
                                        game_over.gameOver = true;
                                    }
                                }
                                else if (!p.isBig)
                                {
                                    score.AddFlyingScore(100, PlayerFeet().X, PlayerFeet().Y, lastTime);
                                }
                                else
                                {
                                    score.AddFlyingScore(500, PlayerFeet().X, PlayerFeet().Y, lastTime);
                                }
                                p.points_to_give -= 1;
                                audio.PNT();
                            }
                        }

                        else if (p.isMonster && player.V.Y != 0)
                        {
                            v.X = -25.5f;
                            lives.lives_number -= 1;
                            if (lives.lives_number < 1)
                            {
                                lives.lives_number = 0;
                                game_over.gameOver = true;
                            }
                            audio.JMP();
                        }

                        //if hit monster's right side... you lose/ game over
                        else if (p.isMonster && player.V.X <= 0)
                        {
                            lives.lives_number -= 3;
                            if (lives.lives_number < 1)
                            {
                                lives.lives_number = 0;
                                game_over.gameOver = true;
                            }
                        }
                        player.V = v;
                        player.Advance(0);
                    }
                }

                delta -= step;
            }

            score.Advance(time);

            if (!game_over.gameOver)
            {
                audio.BGD();
            }
            else
            {
                audio.BGD(true);  audio.OVR();
            }
        }
Example #4
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long  time  = stopwatch.ElapsedMilliseconds;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;

            if (player.P.X < 10)
            {
                snd.SoundSong();
                score.stop();
                end = true;
            }
            else
            {
                if (!beenThanked)
                {
                    beenThanked = true;
                    snd.SoundThanks();
                }
            }
            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }



                player.Advance(step);
                if (!(player.P.X - (float)Width / (float)Height * playingH / 2 < 0))
                {
                    sky.Advance(player.P.X - (float)Width / (float)Height * playingH / 2);
                }
                else
                {
                    sky.Advance(0);
                }

                foreach (Polygon p in world)
                {
                    p.Advance(step);
                }

                foreach (Polygon p in world)
                {
                    if (collision.Test(player, p))
                    {
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (collision.N.X != 0)
                        {
                            snd.SoundCollision();
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                        }
                        if (collision.N.Y < -0.1)
                        {
                            snd.SoundCollision();
                        }
                        player.V = v;
                        player.Advance(0);
                        if (collision.N.Y > 0)
                        {
                            player.STAND = true;
                        }
                    }
                    collision.ClearNormal();
                    if (player.V.Y < -3.0 && player.STAND == false)
                    {
                        snd.SoundDeath();
                    }
                }
                delta -= step;
            }
        }
Example #5
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long  time  = stopwatch.ElapsedMilliseconds;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;


            List <Polygon> dangers = new List <Polygon>();


            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }

                player.Advance(step);


                foreach (Polygon p in world)
                {
                    p.Advance(step);
                }
                //Some refactoring



                foreach (Polygon p in world)
                {
                    // p.Advance(step);
                    if (collision.Test(player, p))
                    {
                        /////////////////////////////////////////////////////
                        if (p.IsBad)
                        {
                            dangers.Add(p);
                        }


                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                        }

                        player.V = v;


                        if (prev_player_loc_y != player.P.Y && !(p is Platform))
                        {
                            sounds.Can();
                        }

                        if (prev_player_loc_y != player.P.Y && (p is Platform))
                        {
                            sounds.Woosh();
                        }

                        if (prev_player_loc_x != player.P.X)
                        {
                            sounds.Crunch();
                        }

                        player.Advance(0);
                    }
                }

                delta -= step;



                /////////////////////////////////////////////////////////////////
                //foreach (Polygon b in dangers)
                //    world.Remove(b);



                List <Ngon> newfireballs = new List <Ngon>();
                foreach (Ngon f in coins)
                {
                    if (Math.Abs(f.P.X - player.P.X) < ((float)(0.2f + 0.2f) / 2 + f.Rad) && Math.Abs(f.P.Y - player.P.Y) < ((float)(1) / 2 + f.Rad))
                    {
                        score += 10;
                        world.Remove(f);
                        // Score a collision with p
                        // and we won't need this fireball anymore.
                    }
                    else
                    {
                        // We still need this fireball, save it to the new list
                        newfireballs.Add(f);
                    }
                }//end foreach

                coins = newfireballs;
            }

            prev_player_loc_y = player.P.Y;
            prev_player_loc_x = player.P.X;

            foreach (Polygon b in dangers)
            {
                world.Remove(b);
            }


            if (player.P.Y < -2)
            {
                world.Clear();

                System.Windows.Forms.MessageBox.Show("You Fall into the River. Game Over!");


                device = null;

                player = null;
                this.Close(); // Esc was pressed
            }
        }
Example #6
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long  time  = stopwatch.ElapsedMilliseconds;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;

            Vector2 q = player.V;
            Vector2 r = player.P;

            //These added borders, is there a better way to do this?
            if (player.P.X < 0.1f)
            {
                q.X = 0;
                r.X = 0.1f;
            }
            else if (player.P.X > playingW - 0.25f)
            {
                q.X = 0;
                r.X = playingW - 0.25f;
            }
            if (player.P.Y < 0.1f)
            {
                q.Y = 0;
                r.Y = 0.1f;
            }
            else if (player.P.Y > playingH - 0.1f)
            {
                q.Y = 0;
                r.Y = playingH - 0.1f;
            }

            player.P = r;
            player.V = q;
            player.Advance(0);

            while (delta > 0)
            {
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }

                player.Advance(step);

                foreach (Polygon p in lasers)
                {
                    p.Advance(step);
                }

                foreach (Polygon p in enemies)
                {
                    p.Advance(step);
                }

                foreach (Polygon p in enemies)
                {
                    if (collision.Test(player, p))
                    {
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;
                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                        }
                        player.V = v;
                        player.Advance(0);
                    }
                }

                List <Polygon> newlasers   = new List <Polygon>();
                List <Polygon> tempenemies = enemies;
                bool           hit         = false;

                foreach (Polygon f in lasers)
                {
                    List <Polygon> newenemies = new List <Polygon>();
                    hit = false;
                    if (tempenemies.Count() > 0)
                    {
                        foreach (Polygon p in tempenemies)
                        {
                            if (collision.Test(f, p))
                            {
                                // Score a collision with p
                                // and we won't need this laser anymore.
                                score += 100;
                                hit    = true;
                                sounds.Explosion();
                            }
                            else
                            {
                                // Otherwise, we still need the enemy
                                newenemies.Add(p);
                            }
                        }
                    }
                    if (!hit)
                    {
                        newlasers.Add(f);
                    }
                    tempenemies = newenemies;
                }

                lasers  = newlasers;
                enemies = tempenemies;


                delta -= step;
            }
        }
Example #7
0
        /// <summary>
        /// Advance the game in time
        /// </summary>
        public void Advance()
        {
            // How much time change has there been?
            long  time  = stopwatch.ElapsedMilliseconds;
            float delta = (time - lastTime) * 0.001f;       // Delta time in milliseconds

            lastTime = time;

            while (delta > 0)
            {
                // fix tunnelling
                float step = delta;
                if (step > 0.05f)
                {
                    step = 0.05f;
                }

                float maxspeed = Math.Max(Math.Abs(player.V.X), Math.Abs(player.V.Y));
                if (maxspeed > 0)
                {
                    step = (float)Math.Min(step, 0.05 / maxspeed);
                }

                ////

                player.Advance(step);


                foreach (Polygon p in world)
                {
                    p.Advance(step);
                }


                foreach (Polygon p in world)
                {
                    if (collision.Test(player, p))
                    {
                        float depth = collision.P1inP2 ?
                                      collision.Depth : -collision.Depth;
                        player.P = player.P + collision.N * depth;
                        Vector2 v = player.V;

                        if (collision.N.X != 0)
                        {
                            v.X = 0;
                        }
                        if (collision.N.Y != 0)
                        {
                            v.Y = 0;
                        }
                        player.V = v;
                        player.Advance(0);
                    }
                }

                delta -= step;

                List <Ngon> newfireballs = new List <Ngon>();
                foreach (Ngon f in coins)
                {
                    if (collision.Test(player, f))
                    {
                        score += 10;
                        // Score a collision with p
                        // and we won't need this fireball anymore.
                    }
                    else
                    {
                        // We still need this fireball, save it to the new list
                        newfireballs.Add(f);
                    }
                } //end foreach

                coins = newfireballs;
            }
        }