예제 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            player = new Player(100,100,60,60); // TODO: give player actual rectangle values

            g = GameState.Menu;

            world = new World(GameVariables.menuWorld, s); // Menu "world"
            pause = false;

            // x y width height are temporary filler values
            //gameHUD = new Hud(50, 20, 700, 180, spriteBatch, player, world.Levels[0].HudInfo , (GameVariables.menuWorld + " - " + (world.currentLevel + 1).ToString()));

            player.ObjPos.X = world.Levels[0].playerSpawn.X;
            player.ObjPos.Y = world.Levels[0].playerSpawn.Y;

            moveCamera = new Camera(player, GraphicsDevice);

            width = GraphicsDevice.Viewport.Width;
            height = GraphicsDevice.Viewport.Height;

            base.Initialize();
        }
예제 #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player.LoadContent(Content);
            GameVariables.LoadContentFiles(Content);

            // TODO: use this.Content to load your game content here

            pauseBack = Content.Load<Texture2D>(GameVariables.imgWall);
            gameFont = Content.Load<SpriteFont>(GameVariables.gFont);
            gameFont2 = Content.Load<SpriteFont>(GameVariables.gFont2);
            deathScreen = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/death");
            victoryScreen = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/Victory");
            menu = new AnimatedTexture(Content, @"ContentFiles/Images/Sprites/fronta", 5, .05f);

            world = new World(GameVariables.menuWorld, s, player, Content); // Menu "world"
            world.LoadWorld();

            player.ObjPos.X = world.levels["main.txt"].playerSpawn.X;
            player.ObjPos.Y = world.levels["main.txt"].playerSpawn.Y;
            world.currentLevel = "main.txt";

            moveCamera = new Camera(player, GraphicsDevice);
            gameHUD = new Hud((int)moveCamera.camX + 20, (int)moveCamera.camY + 20, 300, 45, spriteBatch, player, moveCamera, world.levels[world.currentLevel]);

            falling = new SoundLoop(GameVariables.fallingLoopInstance1, 700, GameVariables.fallingLoopInstance2, 700, GameVariables.fallingAccelerationInstance, 850);
            robotMovement = new SoundLoop(GameVariables.robotSoundInstance1, 690, GameVariables.robotSoundInstance2, 690);

            gameHUD.backt = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/back");
            gameHUD.undert = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/grey");
            gameHUD.energyt = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/energy");
        }
예제 #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();

            // TODO: Add your update logic here

            foreach (MusicController temp in GameVariables.layerList)
            {
                temp.Layer.Play();
            }

            previousKbState = kbState;
            kbState = Keyboard.GetState();

            if (g == GameState.Menu)
            {

                GameVariables.menuMusicInstance.Play();

                moveCamera.viewMatrix = moveCamera.GetTransform(player, width, height);
                if (SingleKeyPress(Keys.Enter, kbState, previousKbState))
                {
                    GameVariables.interfaceStartInstance.Play();
                    GameVariables.menuMusicInstance.Stop();
                    g = GameState.Level;
                    world.levels[world.currentLevel].levelTimer.Start();
                }
                MuteSoundEffects();
                MuteMusic();
                if (SingleKeyPress(Keys.F, kbState, previousKbState))
                {
                    graphics.ToggleFullScreen();
                }
            }

            if (g == GameState.Pause)
            {
                FadeLayers();
                if (SingleKeyPress(Keys.R, kbState, previousKbState))
                {
                    ResetLevel();
                    GameVariables.interfacePauseInstance.Play();
                    g = prevState;
                    paused = false;
                }
                if (SingleKeyPress(Keys.F, kbState, previousKbState))
                {
                    graphics.ToggleFullScreen();
                }

                MuteSoundEffects();
                MuteMusic();
                if (SingleKeyPress(Keys.Q, kbState, previousKbState))
                {
                    Exit();
                }
            }

            if (g == GameState.Dead)
            {
                foreach (MusicController temp in GameVariables.layerList)
                {
                    temp.Layer.Stop();
                }
                if (GameVariables.deathMusicInstance.State == SoundState.Stopped)
                {
                    GameVariables.deathMusicInstance.Play();
                }
                if (SingleKeyPress(Keys.R, kbState, previousKbState))
                {
                    ResetLevel();
                    g = GameState.Level;
                    GameVariables.interfaceStartInstance.Play();
                    GameVariables.deathMusicInstance.Stop();
                }
            }

            if (g == GameState.Victory)
            {
                world.levels[world.currentLevel].levelTimer.Stop();
                if (SingleKeyPress(Keys.Enter, kbState, previousKbState))
                {
                    g = GameState.Level;
                    player.victory = false;
                    GameVariables.interfaceStartInstance.Play();
                    world.levels[world.currentLevel].levelTimer.Start();
                }
                if (SingleKeyPress(Keys.F, kbState, previousKbState))
                {
                    graphics.ToggleFullScreen();
                }
                MuteSoundEffects();
                MuteMusic();
            }

            if (g == GameState.Level)
            {
                FadeLayers();
                player.Movement(kbState, previousKbState, gameTime, falling);
                player.Collisions(kbState, previousKbState, world, s, Content, robotMovement);
                foreach (Enemy enemy in world.levels[world.currentLevel].enemies)
                {
                    if (enemy.alive)
                    {
                        enemy.Movement(gameTime);
                        enemy.Collisions(world.levels[world.currentLevel].objects, kbState, previousKbState, world);
                    }
                }
                if (player.IsDead())
                {
                    foreach (SoundEffectInstance temp in GameVariables.GameSounds)
                    {
                        if (temp != GameVariables.deathMusicInstance && temp != GameVariables.deathSoundInstance)
                        {
                            temp.Stop();
                        }
                    }
                    g = GameState.Dead;
                }

                if (player.world != null && player.world != world)
                {
                    if (player.victory)
                    {
                        tempTime = world.levels[world.currentLevel].levelTimer.Elapsed.Seconds;
                        tempDeaths = world.levels[world.currentLevel].deathCount;
                        player.energy = 280;
                    }
                    world = player.world;
                    world.LoadWorld();
                    world.levels[world.currentLevel].levelTimer.Start();
                }

                if (player.victory)
                {
                    g = GameState.Victory;
                }

                moveCamera.viewMatrix = moveCamera.GetTransform(player, width, height);
                gameHUD.Check();
                player.Update(gameTime);
            }

            if (SingleKeyPress(Keys.P, kbState, previousKbState) && g != GameState.Menu && g != GameState.Victory && g != GameState.Dead)
            {
                foreach (SoundEffectInstance temp in GameVariables.GameSounds)
                {
                    if (temp != GameVariables.layer1Instance && temp != GameVariables.layer2Instance && temp != GameVariables.layer3Instance && temp != GameVariables.layer4Instance && temp != GameVariables.layer5Instance && temp != GameVariables.layer6Instance)
                    {
                        temp.Stop();
                    }
                }
                GameVariables.interfacePauseInstance.Play();
                if (!paused)
                {
                    prevState = g;
                    world.levels[world.currentLevel].levelTimer.Stop();
                    g = GameState.Pause;
                    paused = true;
                }
                else
                {
                    g = prevState;
                    GameVariables.interfacePauseInstance.Play();
                    world.levels[world.currentLevel].levelTimer.Start();
                    paused = false;
                }
            }

            //if(g == GameState.Level && world.levels[world.currentLevel].HudInfo != null)
            //{
            //    gameHUD.checkPlayerY();
            //}

            base.Update(gameTime);
        }
예제 #4
0
        public override void Collisions(List<GameObject> objs, KeyboardState k, KeyboardState p, World w)
        {
            inAir = true;
            foreach (GameObject obj in objs)
            {
                if (obj is Enemy | obj is Door | obj is Panel)
                {

                }
                // Left middle.
                else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Left)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.right;
                    }
                    ObjPos.X = obj.ObjRect.Right;
                    if (xVelocity < 0) { xVelocity = 0; }
                }
                // Right middle.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Right)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.left;
                    }
                    ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                    if (xVelocity > 0) { xVelocity = 0; }
                }
                // Top middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Top))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.down;
                    }
                    ObjPos.Y = obj.ObjRect.Bottom;
                    if (yVelocity < 0) { yVelocity = 0; }
                }
                // Bottom middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.up;
                    }
                    ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                    if (yVelocity > 0) { yVelocity = 0; }
                }
                // Top left corner.
                else if (obj.ObjRect.Contains(ObjRect.X, ObjRect.Y))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Top right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Y))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Bottom left corner.
                else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }
                // Bottom right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }

                //Vision Colisions
                if (vision.Intersects(player.ObjRect))
                {
                    switch (grav)
                    {
                        case gravDirection.Up:
                            if (Attacking == false)
                            {
                                Attacking = true;
                                yVelocity -= (float)GameVariables.jump * 1.5f;
                            }
                            break;
                        case gravDirection.Down:
                            if (Attacking == false)
                            {
                                Attacking = true;
                                yVelocity += (float)GameVariables.jump * 1.5f;
                            }
                            break;
                        case gravDirection.Left:
                            if (Attacking == false)
                            {
                                Attacking = true;
                                xVelocity -= (float)GameVariables.jump * 1.5f;
                            }
                            break;
                        case gravDirection.Right:
                            if (Attacking == false)
                            {
                                Attacking = true;
                                xVelocity += (float)GameVariables.jump * 1.5f;
                            }
                            break;
                    }

                }

                ObjRectX = (int)ObjPos.X;
                ObjRectY = (int)ObjPos.Y;
            }
        }
예제 #5
0
        /// <summary>
        /// Checks for collisions with each game object.
        /// </summary>
        public void Collisions(KeyboardState k, KeyboardState p, World w, StreamReader s, ContentManager content, SoundLoop robotLoop)
        {
            inAir = true;
            List<GameObject> objs = w.levels[w.currentLevel].objects;
            List<Enemy> enms = w.levels[w.currentLevel].enemies;
            foreach (Enemy en in enms)
            {
                if (en.alive)
                {
                    if (isColliding(en))
                    {
                        alive = false;
                        GameVariables.deathSoundInstance.Play();
                        w.levels[w.currentLevel].deathCount++;
                    }
                    if (en is EnemyF)
                    {
                        GameVariables.robotSoundInstance1.Apply3D(listener, en.enemyEmitter);
                        GameVariables.robotSoundInstance2.Apply3D(listener, en.enemyEmitter);
                        robotLoop.Loop();
                    }
                }
            }
            foreach (GameObject obj in objs)
            {
                if (obj is Hazard)
                {
                    Hazard temp = (Hazard)obj;
                    if (temp.wireEmitter != null)
                    {
                        temp.wireSound.Apply3D(listener, temp.wireEmitter);
                        temp.wireSound.Play();
                    }
                }
                if ((obj is Door))
                {
                    Door temp = (Door)obj;
                    temp.Open(this);
                }
                if (isColliding(obj) && obj.isDangerous)
                {
                    alive = false;
                    w.levels[w.currentLevel].deathCount++;
                    GameVariables.deathSoundInstance.Play();

                }
                else if (isColliding(obj))
                {
                    if (obj is Door)
                    {
                        Door temp = (Door)obj;
                        if (Game1.SingleKeyPress(Keys.E, k, p) && temp.destWorld == null)
                        {
                            w.currentLevel = temp.destination;

                            ObjPos.X = w.levels[w.currentLevel].playerSpawn.X;
                            ObjPos.Y = w.levels[w.currentLevel].playerSpawn.Y;
                            xVelocity = 0.0f;
                            yVelocity = 0.0f;
                            ObjRectWidth = 30;
                            ObjRectHeight = 54;
                            grav = gravDirection.Down;
                            PlayAnimation("Down_Idle_Right");
                        }
                        else if (Game1.SingleKeyPress(Keys.E, k, p))
                        {
                            world = new World(temp.destWorld, s, this, content);
                            world.changeWorldBool = true;
                            world.currentLevel = temp.destination + ".txt";
                            ObjPos.X = world.levels[world.currentLevel].playerSpawn.X;
                            ObjPos.Y = world.levels[world.currentLevel].playerSpawn.Y;
                            xVelocity = 0.0f;
                            yVelocity = 0.0f;
                            ObjRectWidth = 30;
                            ObjRectHeight = 54;
                            grav = gravDirection.Down;
                            if (temp.victory)
                            {
                                this.victory = true;
                            }
                            PlayAnimation("Down_Idle_Right");
                        }
                    }
                    // Background Case
                    else if (obj is Panel) { }

                    // Left middle.
                    else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Center.Y))
                    {
                        if (grav == gravDirection.Left)
                        {
                            inAir = false;
                            if (xVelocity < -1)
                            {
                                GameVariables.landingInstance.Play();
                            }
                            xVelocity = 0;
                        }
                        else
                        {
                            xVelocity = +1;
                        }
                        ObjPos.X = obj.ObjRect.Right;
                    }
                    // Right middle.
                    else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Center.Y))
                    {
                        if (grav == gravDirection.Right)
                        {
                            inAir = false;
                            if (xVelocity > 1)
                            {
                                GameVariables.landingInstance.Play();
                            }
                            xVelocity = 0;
                        }
                        else
                        {
                            xVelocity = -1;
                        }
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width + 1;
                    }
                    // Top middle.
                    else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Top))
                    {
                        if (grav == gravDirection.Up)
                        {
                            inAir = false;
                            if (yVelocity < -1)
                            {
                                GameVariables.landingInstance.Play();
                            }
                            yVelocity = 0;
                        }
                        else
                        {
                            yVelocity = +1;
                        }
                        ObjPos.Y = obj.ObjRect.Bottom;
                    }

                    // Bottom middle.
                    else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Bottom))
                    {
                        if (grav == gravDirection.Down)
                        {
                            if (inAir == true)
                            {
                                inAir = false;
                                if (yVelocity > 1)
                                {
                                    GameVariables.landingInstance.Play();
                                }
                            }
                            yVelocity = 0;
                        }
                        else
                        {
                            yVelocity = -1;
                        }

                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height + 1;

                    }
                    // Top left corner.
                    else if (obj.ObjRect.Contains(ObjRect.X + 12, ObjRect.Y + 12))
                    {
                        if (grav == gravDirection.Up)
                        {
                            inAir = false;
                            ObjPos.Y = obj.ObjRect.Bottom;
                            yVelocity = 0;
                        }
                        else if (grav == gravDirection.Left)
                        {
                            inAir = false;
                            ObjPos.X = obj.ObjRect.Right;
                            xVelocity = 0;
                        }
                        else
                        {
                            if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                            else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                        }
                    }
                    // Top right corner.
                    else if (obj.ObjRect.Contains(ObjRect.Right - 12, ObjRect.Y + 12))
                    {
                        if (grav == gravDirection.Up)
                        {
                            inAir = false;
                            ObjPos.Y = obj.ObjRect.Bottom;
                            yVelocity = 0;
                        }
                        else if (grav == gravDirection.Right)
                        {
                            inAir = false;
                            ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                            xVelocity = 0;
                        }
                        else
                        {
                            if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                            else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                        }
                    }
                    // Bottom left corner.
                    else if (obj.ObjRect.Contains(ObjRect.Left + 12, ObjRect.Bottom - 12))
                    {
                        if (grav == gravDirection.Down)
                        {
                            inAir = false;
                            ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                            yVelocity = 0;
                        }
                        else if (grav == gravDirection.Left)
                        {
                            inAir = false;
                            ObjPos.X = obj.ObjRect.Right;
                            xVelocity = 0;
                        }
                        else
                        {
                            if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                            else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                        }
                    }
                    // Bottom right corner.
                    else if (obj.ObjRect.Contains(ObjRect.Right - 12, ObjRect.Bottom - 12))
                    {
                        if (grav == gravDirection.Down)
                        {
                            inAir = false;
                            ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                            yVelocity = 0;
                        }
                        else if (grav == gravDirection.Right)
                        {
                            inAir = false;
                            ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                            xVelocity = 0;
                        }
                        else
                        {
                            if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                            else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                        }
                    }
                    ObjRectX = (int)ObjPos.X;
                    ObjRectY = (int)ObjPos.Y;
                }
            }
        }
예제 #6
0
        public override void Collisions(List<GameObject> objs, KeyboardState k, KeyboardState p, World w)
        {
            inAir = true;
            foreach (GameObject obj in objs)
            {

                if (isColliding(obj) && obj.isDangerous)
                {
                    alive = false;
                }

                else if (obj is Enemy | obj is Door | obj is Panel)
                {
                }
                // Left middle.
                else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Left)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.right;
                    }
                    ObjPos.X = obj.ObjRect.Right;
                    if (xVelocity < 0) { xVelocity = 0; }
                }
                // Right middle.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Right)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.left;
                    }
                    ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                    if (xVelocity > 0) { xVelocity = 0; }
                }
                // Top middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Top))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.down;
                    }
                    ObjPos.Y = obj.ObjRect.Bottom;
                    if (yVelocity < 0) { yVelocity = 0; }
                }
                // Bottom middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.up;
                    }
                    ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                    if (yVelocity > 0) { yVelocity = 0; }
                }
                // Top left corner.
                else if (obj.ObjRect.Contains(ObjRect.X + 18, ObjRect.Y + 18))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Top right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right - 18, ObjRect.Y + 18))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Bottom left corner.
                else if (obj.ObjRect.Contains(ObjRect.Left + 18, ObjRect.Bottom - 18))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }
                // Bottom right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right - 18, ObjRect.Bottom - 18))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }
                if (vision.Intersects(obj.ObjRect))
                {
                    if (obj is Hazard)
                    {
                        switch (grav)
                        {
                            case gravDirection.Down:
                                if (inAir == false)
                                {
                                    ObjPos.Y -= 20;
                                    yVelocity = -jump;
                                    inAir = true;
                                }
                                break;
                            case gravDirection.Up:
                                if (inAir == false)
                                {
                                    ObjPos.Y += 20;
                                    yVelocity = jump;
                                    inAir = true;
                                }
                                break;
                            case gravDirection.Left:
                                if (inAir == false)
                                {
                                    ObjPos.X += 20;
                                    xVelocity = jump;
                                    inAir = true;
                                }
                                break;
                            case gravDirection.Right:
                                if (inAir == false)
                                {
                                    ObjPos.X -= 20;
                                    xVelocity = -jump;
                                    inAir = true;
                                }
                                break;
                        }
                    }
                }
                ObjRectX = (int)ObjPos.X;
                ObjRectY = (int)ObjPos.Y;
            }
        }
예제 #7
0
 public void Collisions(List<GameObject> objs, KeyboardState k, KeyboardState p, World w)
 {
     inAir = true;
     foreach (GameObject obj in objs)
     {
         if (isColliding(obj) && obj.isDangerous)
         {
             alive = false;
             isDead(w.Levels[w.currentLevel].playerSpawn);
         }
         else if (isColliding(obj))
         {
             if (obj is Door)
             {
                 Door temp = (Door)obj;
                 if (Game1.SingleKeyPress(Keys.E, k, p))
                 {
                     w.currentLevel = temp.destination;
                     ObjPos.X = w.Levels[w.currentLevel].playerSpawn.X;
                     ObjPos.Y = w.Levels[w.currentLevel].playerSpawn.Y;
                     xVelocity = 0.0f;
                     yVelocity = 0.0f;
                 }
             }
             // Left middle.
             else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Center.Y))
             {
                 if (grav == gravDirection.Left)
                 {
                     inAir = false;
                 }
                 ObjPos.X = obj.ObjRect.Right;
                 xVelocity = 0;
             }
             // Right middle.
             else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Center.Y))
             {
                 if (grav == gravDirection.Right)
                 {
                     inAir = false;
                 }
                 ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                 xVelocity = 0;
             }
             // Top middle.
             else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Top))
             {
                 if (grav == gravDirection.Up)
                 {
                     inAir = false;
                 }
                 ObjPos.Y = obj.ObjRect.Bottom;
                 yVelocity = 0;
             }
             // Bottom middle.
             else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Bottom))
             {
                 if (grav == gravDirection.Down)
                 {
                     inAir = false;
                 }
                 ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                 yVelocity = 0;
             }
             // Top left corner.
             else if (obj.ObjRect.Contains(ObjRect.X, ObjRect.Y))
             {
                 if (grav == gravDirection.Up)
                 {
                     inAir = false;
                     ObjPos.Y = obj.ObjRect.Bottom;
                     yVelocity = 0;
                 }
                 else if (grav == gravDirection.Left)
                 {
                     inAir = false;
                     ObjPos.X = obj.ObjRect.Right;
                     xVelocity = 0;
                 }
                 else
                 {
                     if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                     else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                 }
             }
             // Top right corner.
             else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Y))
             {
                 if (grav == gravDirection.Up)
                 {
                     inAir = false;
                     ObjPos.Y = obj.ObjRect.Bottom;
                     yVelocity = 0;
                 }
                 else if (grav == gravDirection.Right)
                 {
                     inAir = false;
                     ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                     xVelocity = 0;
                 }
                 else
                 {
                     if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                     else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                 }
             }
             // Bottom left corner.
             else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Bottom))
             {
                 if (grav == gravDirection.Down)
                 {
                     inAir = false;
                     ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                     yVelocity = 0;
                 }
                 else if (grav == gravDirection.Left)
                 {
                     inAir = false;
                     ObjPos.X = obj.ObjRect.Right;
                     xVelocity = 0;
                 }
                 else
                 {
                     if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                     else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                 }
             }
             // Bottom right corner.
             else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Bottom))
             {
                 if (grav == gravDirection.Down)
                 {
                     inAir = false;
                     ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                     yVelocity = 0;
                 }
                 else if (grav == gravDirection.Right)
                 {
                     inAir = false;
                     ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                     xVelocity = 0;
                 }
                 else
                 {
                     if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                     else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                 }
             }
             //}
             //else
             //{
             //    if (topHit.isColliding(obj))
             //    {
             //        if (obj is Player)
             //        { }
             //        {
             //            if (grav == gravDirection.Up)
             //            {
             //                ObjPos.Y = obj.ObjRectY + obj.ObjRect.Height;
             //                yVelocity = 0;
             //                inAir = false;
             //            }
             //        }
             //    }
             //    else if (bottHit.isColliding(obj))
             //    {
             //        if (obj is Player)
             //        { }
             //        else
             //        {
             //            ObjPos.Y = obj.ObjRectY - ObjRect.Height;
             //            yVelocity = 0;
             //            if (grav == gravDirection.Down) { inAir = false; }
             //        }
             //    }
             //    else if (rightHit.isColliding(obj))
             //    {
             //        if (obj is Player)
             //        { }
             //        else
             //        {
             //            ObjPos.X = obj.ObjRectX - ObjRect.Width;
             //            xVelocity = 0;
             //            if (grav == gravDirection.Right) { inAir = false; }
             //        }
             //    }
             //    else if (leftHit.isColliding(obj))
             //    {
             //        if (obj is Player)
             //        { }
             //        else
             //        {
             //            ObjPos.X = obj.ObjRectX + obj.ObjRect.Width;
             //            xVelocity = 0;
             //            if (grav == gravDirection.Left) { inAir = false; }
             //        }
             //    }
             //    else
             //    {
             //        inAir = true;
             //    }
             ObjRectX = (int)ObjPos.X;
             ObjRectY = (int)ObjPos.Y;
         }
     }
 }
예제 #8
0
        public virtual void Collisions(List<GameObject> objs, KeyboardState k, KeyboardState p, World w)
        {
            inAir = true;
            foreach (GameObject obj in objs)
            {
                if (isColliding(obj) && obj.isDangerous)
                {
                    alive = false;
                }

                else if (obj is Enemy | obj is Door | obj is Panel)
                {
                }
                // Left middle.
                else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Left)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.right;
                    }
                    ObjPos.X = obj.ObjRect.Right;
                    if (xVelocity < 0) { xVelocity = 0; }
                }
                // Right middle.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Center.Y))
                {
                    if (grav == gravDirection.Right)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Down | grav == gravDirection.Up)
                    {
                        currentDir = myDirection.left;
                    }
                    ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                    if (xVelocity > 0) { xVelocity = 0; }
                }
                // Top middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Top))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.down;
                    }
                    ObjPos.Y = obj.ObjRect.Bottom;
                    if (yVelocity < 0) { yVelocity = 0; }
                }
                // Bottom middle.
                else if (obj.ObjRect.Contains(ObjRect.Center.X, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                    }
                    if (grav == gravDirection.Left | grav == gravDirection.Right)
                    {
                        currentDir = myDirection.up;
                    }
                    ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                    if (yVelocity > 0) { yVelocity = 0; }
                }
                // Top left corner.
                else if (obj.ObjRect.Contains(ObjRect.X, ObjRect.Y))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Top right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Y))
                {
                    if (grav == gravDirection.Up)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Bottom;
                        if (yVelocity < 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity < 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Bottom; }
                    }
                }
                // Bottom left corner.
                else if (obj.ObjRect.Contains(ObjRect.Left, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Left)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Right;
                        if (xVelocity < 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity < 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Right; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }
                // Bottom right corner.
                else if (obj.ObjRect.Contains(ObjRect.Right, ObjRect.Bottom))
                {
                    if (grav == gravDirection.Down)
                    {
                        inAir = false;
                        ObjPos.Y = obj.ObjRect.Top - ObjRect.Height;
                        if (yVelocity > 0) { yVelocity = 0; }
                    }
                    else if (grav == gravDirection.Right)
                    {
                        inAir = false;
                        ObjPos.X = obj.ObjRect.Left - ObjRect.Width;
                        if (xVelocity > 0) { xVelocity = 0; }
                    }
                    else
                    {
                        if (xVelocity > 0) { xVelocity = 0; ObjPos.X = obj.ObjRect.Left - ObjRect.Width; }
                        else if (yVelocity > 0) { yVelocity = 0; ObjPos.Y = obj.ObjRect.Top - ObjRect.Height; }
                    }
                }
                ObjRectX = (int)ObjPos.X;
                ObjRectY = (int)ObjPos.Y;
            }
        }