Beispiel #1
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 #2
0
        private void Animate(Controls controls, Level level, GameTime gameTime)
        {
            // Determine type of movement
            if (!frozen)
            {
                // Jumping
                if (!grounded)
                {
                    // Initialize sprite
                    if (image != images["jump"])
                    {
                        image = images["jump"];
                        frameIndexX = 0;
                    }
                    // Animate
                    else if (frameIndexX < 2 * 32 && level.count % 6 == 0)
                        frameIndexX += 32;
                }
                // Grounded, not Moving
                else if (Math.Abs(xVel) < 1)
                {
                    // Initialize sprite. No animation.
                    if (image != images["stand"])
                    {
                        image = images["stand"];
                        frameIndexX = 0;
                    }
                }
                // Grounded, yes moving
                else
                {
                    // Initialize sprite
                    if (image != images["walk"])
                        image = images["walk"];
                    // Animate
                    //frameIndex = (level.count / 8 % 4) * 32;
                    frameIndexX = ((int)(gameTime.TotalGameTime.TotalMilliseconds)/128 % 4)*32;
                }
            }

            // Puddle, if puddling
            if (puddled)
            {
                // Initialize sprite
                if (image != images["puddle"])
                {
                    image = images["puddle"];
                    frameIndexX = 0;
                }
                // Animate downward if puddling
                else if (controls.isPressed(Keys.Down, Buttons.DPadDown))
                {
                    if (frameIndexX < 5 * 32)
                        frameIndexX += 32;
                }
                // Animate upward if unpuddling
                else
                {
                    frameIndexX -= 32;
                    if (frameIndexX <= 0)
                    {
                        puddled = false;
                        piped = false;
                    }
                }
            }
        }
Beispiel #3
0
        private void Puddle(Controls controls)
        {
            if (controls.isPressed(Keys.Down, Buttons.DPadDown) &&
                !frozen && grounded && powerup["puddle"])
            {
                puddled = true;
            }

            if (puddled)
            {
                if (hydration >= puddleCost)
                    hydration -= puddleCost;
                else
                {
                    puddled = false;
                    piped = false;
                }
            }
        }
Beispiel #4
0
        private void Jump(Controls controls, Level level, GameTime gameTime)
        {
            SoundEffectInstance instance = soundList["Sounds/Jump.wav"].CreateInstance();
            instance.Volume = 0.1f;
            // Jump on button press
            if (controls.isPressed(Keys.S, Buttons.A) && !frozen && grounded)
            {
                if(instance.State != SoundState.Playing)
                    instance.Play();
                y_vel = -11;
                jumpPoint = (int)(gameTime.TotalGameTime.TotalMilliseconds);
                grounded = false;
            }

            // Cut jump short on button release
            else if (controls.onRelease(Keys.S, Buttons.A) && y_vel < 0)
            {
                y_vel /= 2;
            }
        }
Beispiel #5
0
        private void Animate(Controls controls, Physics physics, 
            ContentManager content)
        {
            // Check for standing still
            if (!frozen())
            {
                // Jumping
                if (!grounded)
                {
                    if (this.imageFile != "PC/jump.png")
                    {
                        frameIndex = 0;
                        this.imageFile = "PC/jump.png";
                        LoadContent(content);
                    }
                }
                // Not Moving
                else if (Math.Abs(x_vel) < .5)
                {
                    if (this.imageFile != "PC/stand.png")
                    {
                        frameIndex = 0;
                        this.imageFile = "PC/stand.png";
                        LoadContent(content);
                    }
                }

                // Yes moving
                else if (this.imageFile != "PC/sheet.png")
                {
                    frameIndex = 0;
                    this.imageFile = "PC/sheet.png";
                    LoadContent(content);
                }
            }

            // Puddle sprite logic
            if (this.imageFile == "PC/collapse.png")
            {
                if (controls.isPressed(Keys.Down, Buttons.DPadDown))
                {
                    if (frameIndex < 5 * 32)
                        frameIndex += 32;
                }
                else
                {
                    frameIndex -= 32;
                    if (frameIndex <= 0)
                        puddled = false;
                }
            }

            // Walking sprite frames
            else if (this.imageFile == "PC/sheet.png")
            {
                frameIndex = (physics.count / 8 % 4) * 32;
            }

            // Jumping sprite frames
            else if (this.imageFile == "PC/jump.png")
            {
                if (frameIndex < 2 * 32)
                    frameIndex += 32;
            }

            // Standing sprite frames
            else
            {
                frameIndex = 0;
            }
        }
Beispiel #6
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 #7
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 #8
0
        private void Animate(Controls controls, Physics physics,
                             ContentManager content)
        {
            // Check for standing still
            if (!frozen())
            {
                // Jumping
                if (!grounded)
                {
                    if (this.imageFile != "PC/jump.png")
                    {
                        frameIndex     = 0;
                        this.imageFile = "PC/jump.png";
                        LoadContent(content);
                    }
                }
                // Not Moving
                else if (Math.Abs(x_vel) < .5)
                {
                    if (this.imageFile != "PC/stand.png")
                    {
                        frameIndex     = 0;
                        this.imageFile = "PC/stand.png";
                        LoadContent(content);
                    }
                }

                // Yes moving
                else if (this.imageFile != "PC/sheet.png")
                {
                    frameIndex     = 0;
                    this.imageFile = "PC/sheet.png";
                    LoadContent(content);
                }
            }


            // Puddle sprite logic
            if (this.imageFile == "PC/collapse.png")
            {
                if (controls.isPressed(Keys.Down, Buttons.DPadDown))
                {
                    if (frameIndex < 5 * 32)
                    {
                        frameIndex += 32;
                    }
                }
                else
                {
                    frameIndex -= 32;
                    if (frameIndex <= 0)
                    {
                        puddled = false;
                    }
                }
            }

            // Walking sprite frames
            else if (this.imageFile == "PC/sheet.png")
            {
                frameIndex = (physics.count / 8 % 4) * 32;
            }

            // Jumping sprite frames
            else if (this.imageFile == "PC/jump.png")
            {
                if (frameIndex < 2 * 32)
                {
                    frameIndex += 32;
                }
            }

            // Standing sprite frames
            else
            {
                frameIndex = 0;
            }
        }