Ejemplo n.º 1
0
 //returns the tile a checkpoint is in
 public static Tile inTile(Level l, Checkpoint c)
 {
     foreach (Tile t in l.theLevel){
             if (t.rect.Contains(c.getPoint())){
              return t;
             }
     }
     return new Tile();
 }
Ejemplo n.º 2
0
 //returns true if the checkpoint's in a solid tile
 public static bool isColliding(Level l, Checkpoint c)
 {
     foreach (Tile t in l.theLevel)
     {
         if (t.rect.Contains(c.getPoint()) && t.isSolid)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
        //handles ground collisions, airtime, and landingfix
        public void airTimeManagement(Level l, GameTime gameTime)
        {
            if (onGround)
            {
                airTime = 0;
            }
            else if (Interaction.isColliding(l, W.points[4]) || Interaction.isColliding(l, W.points[3]))
            {
                    W.area.Y = Interaction.inTile(l, W.points[3]).rect.Y - W.area.Height;
            }

            onGround = Interaction.isColliding(l, W.points[3]) || Interaction.isColliding(l, W.points[4]);

            airTime++;
        }
Ejemplo n.º 4
0
        /*Handles movement involving listeners*/
        public void Movement(Level l)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Left) && !(Interaction.isColliding(l,W.points[0]) || Interaction.isColliding(l, W.points[5])))
            {
                if (W.area.X < Game1.gameWidth/4 && l.theLevel[0, 0].rect.X < 0)
                {
                    foreach (Tile t in l.theLevel)
                    {
                        t.rect.X += 5;
                    }
                }
                else
                {
                    W.area.X -= 5;
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right) && !(Interaction.isColliding(l, W.points[1]) || Interaction.isColliding(l, W.points[2])))
            {

                if (W.area.X > Game1.gameWidth/2 && l.theLevel[l.theLevel.GetLength(0)-1, l.theLevel.GetLength(1)-1].rect.X > Game1.gameWidth-Level.tileSide)
                {
                    foreach (Tile t in l.theLevel)
                    {
                        t.rect.X -= 5;
                    }
                }
                else
                {
                    W.area.X += 5;
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (!(Interaction.isColliding(l,W.points[0])||Interaction.isColliding(l,W.points[1])))
                {
                    W.area.Y -= 12;
                }
            }
        }
Ejemplo n.º 5
0
        //update loop
        public void Update(Level l, GameTime gameTime)
        {
            //Gravity: makes gravity happen
            if (!(onGround))
            {
                W.area.Y += (int)(.3* Math.Abs(airTime));
            }

            Movement(l); //runs listeners and handles x/y positioning.
            W.pointsUpdate();
            airTimeManagement(l, gameTime);
        }
Ejemplo n.º 6
0
 //used to load a level
 public void LoadLevel(string tileAsset, string levelPath, string charAssetSheet)
 {
     samplelevel = new Level(Content.Load<Texture2D>(tileAsset), CSVRead.getLevel(levelPath));
     dude = new Dude(new Rectangle(200, 500, dudeWidth, dudeHeight), Content.Load<Texture2D>(charAssetSheet));
 }