Пример #1
0
        public bool checkMoveValid(Level a, int x, int y)
        {
            Rectangle GBox = new Rectangle(x, y,  BlockTexture.Width, BlockTexture.Height);

            int temp = 0;
            for (int z = 0; z <= a.LevelBlocks.Count - 1; z++)
            {
                Rectangle rectangleA = a.LevelBlocks[z].BBox;
                if (GBox.Intersects(rectangleA))
                {

                    temp = z;
                    break;

                }

            }

            Rectangle rectangleB = a.LevelBlocks[temp].BBox;

            if (GBox.Intersects(rectangleB))
            {

                return false;
            }
            else
            {
                return true;
            }
        }
Пример #2
0
 public ProjHandler(SpriteBatch mainSpriteBatch, Camera2D mainCamera, Player mainPlayer, Level currentLevel)
 {
     spriteBatch = mainSpriteBatch;
     cam = mainCamera;
     player = mainPlayer;
     level = currentLevel;
 }
Пример #3
0
        public bool checkMoveValid(Level a, int x, int y)
        {
            if (activeProjectiles.Count == 0)
            {
                return false;
            }

            Rectangle GBox = new Rectangle();
            Rectangle rectangleB = new Rectangle();
            int temp;

              foreach(projectile currentProj in activeProjectiles){
            GBox = new Rectangle(x, y, currentProj.BlockTexture.Width, currentProj.BlockTexture.Height);

             temp = 0;
            for (int z = 0; z <= a.LevelBlocks.Count - 1; z++){
                Rectangle rectangleA = a.LevelBlocks[z].BBox;
                if (GBox.Intersects(rectangleA))
                {

                    temp = z;
                    break;

                }

            }

             rectangleB = a.LevelBlocks[temp].BBox;

            }
              if (GBox.Intersects(rectangleB))
              {
              return false;

              }
              else
              {
              return true;
              }
        }
Пример #4
0
        public void updatePhysicsMovement(Level lev)
        {
            if (!jumping)
            {

                if (checkMoveValid(lev, posX, posY + 1 * physcounter))
                {
                    posY += 1 * physcounter;
                    physcounter += 1;
                    Falling = true;
                    grounded = false;

                }
                else
                {
                    Falling = false;

                }
            }else{
                if(checkMoveValid(lev, posX, posY - 1 * jumpCounter)){
                    posY -= 1 * jumpCounter;
                    jumpCounter--;

                }else{
                    jumping = false;
                }

                if (!jumping && !Falling)
                {
                    jumpCounter = 20;
                    grounded = true;
                }

            }
        }
Пример #5
0
        public void updateKeyMovement(KeyboardState a, Level lev, GameTime g)
        {
            //NON MOVEMENT(I know. Misleading method name...Sorry)
            if(a.IsKeyDown(Keys.R)){
                if(readyToFire){
                    playerWeapons.Reload();
                }
            }

            if(a.IsKeyDown(Keys.Space)){
                if (readyToFire)
                {
                    playerWeapons.fire(lookingAngle);
                    readyToFire = false;
                }
            }

            if (a.IsKeyUp(Keys.Space))
            {
                readyToFire = true;
                //playerWeapons.killActive();
            }

            //END NON MOVMENT

            //Actual Movement

            //Legacy Movement

            /*
            if (a.IsKeyDown(Keys.Right))
            {
                lookingAngle = new Vector2(10, 0);

                if (checkMoveValid(lev, posX + movespeed, 0))
                {
                    if (checkMoveValid(lev, posX + movespeed, posY))
                        posX += movespeed;

                    moving = true;
                }
            }

            if (a.IsKeyDown(Keys.Left))
            {
                lookingAngle = new Vector2(-10, 0);
                if (checkMoveValid(lev, posX - movespeed, posY))
                    posX -= movespeed;
                moving = true;
            }

            if (a.IsKeyUp(Keys.Right) && a.IsKeyUp(Keys.Left))
            {
                moving = false;
            }
            if (a.IsKeyDown(Keys.Up))
            {

                jump(lev);
            }
            else
            {
                endJump();
            }

              /*  if (a.IsKeyDown(Keys.Down))
            {

                if (checkMoveValid(lev, posX, posY + movespeed))
                    posY += movespeed;
            }
              * */

            //New Movment

            MovementTimer += (float)g.ElapsedGameTime.TotalMilliseconds;
            if (a.IsKeyDown(Keys.Right))
            {
                if (MovementTimer >= MovementInterval)
                { MovementTimer = 0; currentMovmentModifier.X += 1; }
            }
            else if(grounded)
            {
                if (MovementTimer >= MovementInterval && currentMovmentModifier.X >= 5)
                { MovementTimer = 0; currentMovmentModifier.X -= 5; }

            }
            if (a.IsKeyDown(Keys.Left))
            {
                moving = true;
                if (MovementTimer >= MovementInterval)
                { MovementTimer = 0; currentMovmentModifier.X -= 1; }
            }
            else if(grounded)
            {
                if (MovementTimer >= MovementInterval && currentMovmentModifier.X <= -5)
                { MovementTimer = 0; currentMovmentModifier.X += 5; }

            }

            if (a.IsKeyUp(Keys.Left) && a.IsKeyUp(Keys.Right) && grounded )
            {
                moving = true;
                if (currentMovmentModifier.X < 3.5 && currentMovmentModifier.X > -3.5)
                {
                    currentMovmentModifier.X = 0;
                }
            }
            else if (a.IsKeyUp(Keys.Left) && a.IsKeyUp(Keys.Right) && !grounded)
            {

            }

            currentMovmentModifier.X = MathHelper.Clamp(currentMovmentModifier.X, -20, 20);
            posX += (int)currentMovmentModifier.X;

            if (a.IsKeyDown(Keys.Up))
            {

                jump(lev);
            }
        }
Пример #6
0
 public void update(GameTime g, KeyboardState a, Level lev)
 {
     BBox = new Rectangle(posX, posY, PlayerTexture.Width/9, PlayerTexture.Height);
     updateKeyMovement(a, lev,g);
     updatePhysicsMovement(lev);
     playerWeapons.update();
     updateAnimations(g);
 }
Пример #7
0
 // you Must Ready the ProjHandler; mostly because the ProjHandler will use a spritebatch and has its own check for intersections
 public void ReadyWeapons(SpriteBatch a,Camera2D b, Level c)
 {
     readyToFire = true;
     playerWeapons = new ProjHandler(a, b, this, c);
     def = new projectile((float).1, Color.Green, pos, PlayerTexture, 0, 0);
     playerWeapons.addProjectile(def);
 }
Пример #8
0
 public void performJump(Level lev)
 {
 }
Пример #9
0
        // JUMPING
        public void jump(Level lev)
        {
            if(!Falling)
            jumping = true;
               grounded = false;

            /*
            int jumpAmount = 3 * jumpCounter;

            if (!Falling && jumpCounter >= 0 )
            {
                jumping = true;
                if (checkMoveValid(lev, posX, posY - jumpAmount))
                {
                    posY -= jumpAmount;
                    jumpCounter--;
                }

            }  else if(jumpCounter >= 0)
                {
                    jumping = false;
                    Falling = true;
                    jumpCounter = 0;
                }
            else{
                        jumping = false;
                        Falling = true;
            }
            */
        }
Пример #10
0
 public bool checkIfInGameBounds(Level a)
 {
     if (BBox.Intersects(a.GameSpace))
     {
         return true;
     }
     else
     {
         return false;
     }
 }