Beispiel #1
0
        public void Update(Controls controls, Physics physics, 
            ContentManager content)
        {
            //  Acceleration
            if (controls.onPress(Keys.Right, Buttons.DPadRight))
                x_accel += speed;
            else if (controls.onRelease(Keys.Right, Buttons.DPadRight))
                x_accel -= speed;
            if (controls.onPress(Keys.Left, Buttons.DPadLeft))
                x_accel -= speed;
            else if (controls.onRelease(Keys.Left, Buttons.DPadLeft))
                x_accel += speed;

            // Movement
            x_vel = x_vel * (1 - friction)
                + (frozen() ? 0 : x_accel * .10);
            spriteX += Convert.ToInt32(x_vel);

            // Direction
            if (x_vel > 0.1)
                left = false;
            else if (x_vel < -0.1)
                left = true;

            // Puddle
            if (!frozen() && grounded && powerup["puddle"] &&
                controls.isPressed(Keys.Down, Buttons.DPadDown))
            {
                puddled = true;
                imageFile = "PC/collapse.png";
                LoadContent(content);
                if (controls.onPress(Keys.Down, Buttons.DPadDown))
                    puddle_point = physics.count;
            }

            // New shots
            if (controls.onPress(Keys.D, Buttons.RightShoulder))
            {
                shooting = true;
                shot_point = physics.count;
            }
            else if (controls.onRelease(Keys.D, Buttons.RightShoulder))
            {
                shooting = false;
            }

            if (controls.onPress(Keys.S, Buttons.A) && grounded)
            {
                jump_point = physics.count;
            }
            else if (controls.onRelease(Keys.S, Buttons.A))
            {
                // Cut jump short
                if (y_vel < 0)
                    y_vel /= 2;
            }

            // Fall (with grace!)
            if (spriteY < physics.ground)
            {
                spriteY += y_vel;
                y_vel += physics.gravity;
            }
            else
            {
                spriteY = physics.ground;
                y_vel = 0;
                grounded = true;
            }

            // Deal with shot creation and delay
            if (!frozen())
            {
                // Generate regular shots
                if ((physics.count - shot_point) % shot_delay == 0 && shooting)
                {
                    string dir = controls.isPressed(Keys.Up, Buttons.DPadUp) ? "up" : "none";
                    Shot s = new Shot(this, dir);
                    s.LoadContent(content);
                    physics.shots.Add(s);
                }

                // Generate downward shots
                if ((physics.count - jump_point) % jump_delay == 0 && powerup["jetpack"] &&
                    !grounded && controls.isPressed(Keys.S, Buttons.A))
                {
                    // New shot
                    Shot s = new Shot(this, "down");
                    s.LoadContent(content);
                    physics.shots.Add(s);

                    // Upwards
                    spriteY -= 1;
                    y_vel = -8;
                }
            }

            // Jump logic
            if (controls.isPressed(Keys.S, Buttons.A) && !frozen() && grounded)
            {
                spriteY -= 1;
                y_vel = -15;
                grounded = false;
            }

            Animate(controls, physics, content);

            CheckCollisions(physics);
        }
Beispiel #2
0
        private void Shoot(Controls controls, Level level, GameTime gameTime)
        {
            index = rand.Next(4);
            // New shots
            if (controls.onPress(Keys.D, Buttons.RightShoulder) && !powerShotCharging)
            {
                shooting = true;
                shotPoint = (int)(gameTime.TotalGameTime.TotalMilliseconds);
            }
            else if (controls.onRelease(Keys.D, Buttons.RightShoulder))
            {
                shooting = false;
            }

            if (powerup["charged"])
            {
                if (controls.onPress(Keys.X, Buttons.RightTrigger))
                {
                    if (hydration >= powerShotCost)
                        powerShotCharging = true;
                    powerShotPoint = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                    powerShotRelease = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                    tryShotHydration = 0;
                }
                else if (controls.isPressed(Keys.X, Buttons.RightTrigger) && powerShotCharging)
                {
                    if (tryShotHydration < powerShotCost)
                    {
                        tryShotHydration += 1;
                        hydration -= 1;
                    }
                }
                else if (controls.onRelease(Keys.X, Buttons.RightTrigger) && powerShotCharging)
                {
                    powerShotRelease = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                    if (((powerShotRelease - powerShotPoint) >= powerShotDelay) && tryShotHydration == powerShotCost)
                    {
                        powerShotCharging = false;
                        tryShotHydration = 0;
                        string dir = controls.isPressed(Keys.Up, Buttons.DPadUp) ? "up" : "none";
                        PowerShot s = new PowerShot(this, dir);
                        if (index == 0)
                        {
                            soundList["Sounds/Shot1.wav"].Play();
                        }
                        else if (index == 1)
                        {
                            soundList["Sounds/Shot2.wav"].Play();
                        }
                        else if (index == 2)
                        {
                            soundList["Sounds/Shot3.wav"].Play();
                        }
                        else
                        {
                            soundList["Sounds/Shot4.wav"].Play();
                        }
                        level.projectiles.Add(s);
                    }
                    else
                    {
                        powerShotCharging = false;
                        hydration += tryShotHydration;
                        tryShotHydration = 0;
                    }
                }
            }

            // Deal with shot creation and delay
            if (!frozen)
            {
                // Generate regular shots
                int currentTime1 = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                if (((currentTime1 - shotPoint) >= shotDelay || (currentTime1 - shotPoint) == 0)
                    && shooting && hydration >= shotCost)
                {
                    shotPoint = currentTime1;
                    string dir = controls.isPressed(Keys.Up, Buttons.DPadUp) ? "up" : "none";
                    Shot s = new Shot(this, dir);
                    if (index == 0)
                    {
                        soundList["Sounds/Shot1.wav"].Play();
                    }
                    else if (index == 1)
                    {
                        soundList["Sounds/Shot2.wav"].Play();
                    }
                    else if (index == 2)
                    {
                        soundList["Sounds/Shot3.wav"].Play();
                    }
                    else
                    {
                        soundList["Sounds/Shot4.wav"].Play();
                    }
                    level.projectiles.Add(s);
                    hydration -= shotCost;
                }

                // Jetpack (Midair jump and downward shots)
                int currentTime2 = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                if ((currentTime2 - jumpPoint) >= jumpDelay && yVel > 3 && powerup["jetpack"] &&
                    hydration >= jetpackCost && !grounded && controls.isPressed(Keys.S, Buttons.A))
                {
                    // New shot
                    jumpPoint = currentTime2;
                    Shot s = new Shot(this, "down");
                    if (index == 0)
                    {
                        soundList["Sounds/Shot1.wav"].Play();
                    }
                    else if (index == 1)
                    {
                        soundList["Sounds/Shot2.wav"].Play();
                    }
                    else if (index == 2)
                    {
                        soundList["Sounds/Shot3.wav"].Play();
                    }
                    else
                    {
                        soundList["Sounds/Shot4.wav"].Play();
                    }
                    level.projectiles.Add(s);
                    hydration -= jetpackCost;

                    // Slight upward boost
                    spriteY--;
                    movedY--;
                    yVel = -4.5;
                }
            }
        }
Beispiel #3
0
        public void Update(Controls controls, Physics physics,
                           ContentManager content)
        {
            //  Acceleration
            if (controls.onPress(Keys.Right, Buttons.DPadRight))
            {
                x_accel += speed;
            }
            else if (controls.onRelease(Keys.Right, Buttons.DPadRight))
            {
                x_accel -= speed;
            }
            if (controls.onPress(Keys.Left, Buttons.DPadLeft))
            {
                x_accel -= speed;
            }
            else if (controls.onRelease(Keys.Left, Buttons.DPadLeft))
            {
                x_accel += speed;
            }

            // Movement
            x_vel = x_vel * (1 - friction)
                    + (frozen() ? 0 : x_accel * .10);
            spriteX += Convert.ToInt32(x_vel);

            // Direction
            if (x_vel > 0.1)
            {
                left = false;
            }
            else if (x_vel < -0.1)
            {
                left = true;
            }

            // Puddle
            if (!frozen() && grounded && powerup["puddle"] &&
                controls.isPressed(Keys.Down, Buttons.DPadDown))
            {
                puddled   = true;
                imageFile = "PC/collapse.png";
                LoadContent(content);
                if (controls.onPress(Keys.Down, Buttons.DPadDown))
                {
                    puddle_point = physics.count;
                }
            }


            // New shots
            if (controls.onPress(Keys.D, Buttons.RightShoulder))
            {
                shooting   = true;
                shot_point = physics.count;
            }
            else if (controls.onRelease(Keys.D, Buttons.RightShoulder))
            {
                shooting = false;
            }

            if (controls.onPress(Keys.S, Buttons.A) && grounded)
            {
                jump_point = physics.count;
            }
            else if (controls.onRelease(Keys.S, Buttons.A))
            {
                // Cut jump short
                if (y_vel < 0)
                {
                    y_vel /= 2;
                }
            }

            // Fall (with grace!)
            if (spriteY < physics.ground)
            {
                spriteY += y_vel;
                y_vel   += physics.gravity;
            }
            else
            {
                spriteY  = physics.ground;
                y_vel    = 0;
                grounded = true;
            }

            // Deal with shot creation and delay
            if (!frozen())
            {
                // Generate regular shots
                if ((physics.count - shot_point) % shot_delay == 0 && shooting)
                {
                    string dir = controls.isPressed(Keys.Up, Buttons.DPadUp) ? "up" : "none";
                    Shot   s   = new Shot(this, dir);
                    s.LoadContent(content);
                    physics.shots.Add(s);
                }

                // Generate downward shots
                if ((physics.count - jump_point) % jump_delay == 0 && powerup["jetpack"] &&
                    !grounded && controls.isPressed(Keys.S, Buttons.A))
                {
                    // New shot
                    Shot s = new Shot(this, "down");
                    s.LoadContent(content);
                    physics.shots.Add(s);

                    // Upwards
                    spriteY -= 1;
                    y_vel    = -8;
                }
            }

            // Jump logic
            if (controls.isPressed(Keys.S, Buttons.A) && !frozen() && grounded)
            {
                spriteY -= 1;
                y_vel    = -15;
                grounded = false;
            }



            Animate(controls, physics, content);


            CheckCollisions(physics);
        }