public void EmptyMap()
 {
     for (int y=0; y < Constants.Constants.MAP_HEIGHT; y++) {
         List<Tile > row = new List<Tile> ();
         for (int x=0; x < Constants.Constants.MAP_WIDTH; x++) {
             Vector v = GetTilePos (x, y);
             Tile t = new Tile ((int)v.X, (int)v.Y, TileType.Air, lookup [TileType.Air]);
             row.Add (t);
         }
         map.Add (row);
     }
 }
示例#2
0
 private void FillScreen(GraphicsDevice device)
 {
     for (int i = 0; i < Dimensions.X; i += 70)
     {
         Tile t = new Tile(new Vector2(i, Dimensions.Y), TileSetImage, TileClips[12], 12, 1);
         t.CheckForCollision = false;
         Tiles.Add(t);
     }
 }
示例#3
0
        private void LoadMapLayer(int layerNumer, XElement xml)
        {
            CreateTileBasedOnLayer CreateTile;
            switch (layerNumer)
            {
                case 1:
                    CreateTile = (xPos, yPos, id) =>
                        {
                            return new Tile(new Vector2(xPos * 70, yPos * 70), TileSetImage, TileClips[id], id, layerNumer);
                        };
                    break;

                case 2:
                    CreateTile = (xPos, yPos, id) =>
                        {
                            var tile = new Tile(new Vector2(xPos * 70, yPos * 70), TileSetImage, TileClips[id], id, layerNumer);
                            tile.CheckForCollision = false;
                            return tile;
                        };
                    break;

                case 3:
                    CreateTile = (xPos, yPos, id) =>
                        {
                            var tile = new Spike(new Vector2(xPos * 70, yPos * 70), TileSetImage, TileClips[id], id, layerNumer);
                            return tile;
                        };
                    break;

                case 4:
                    CreateTile = (xPos, yPos, id) =>
                        {
                            var tile = new Coin(new Vector2(xPos * 70, yPos * 70), TileSetImage, TileClips[id], id, layerNumer);
                            return tile;
                        };
                    break;

                default:
                    CreateTile = (xpos, yPos, id) => null;
                    MessageBox.Show("Layer Delegate Doesn't exist");
                    Environment.Exit(1);
                    break;
            }

            int x = 0, y = 0;
            foreach (var position in xml.Element("data").Elements("tile"))
            {
                int id = int.Parse(position.Attribute("gid").Value);
                if (id != 0)
                {
                    var tile = CreateTile(x, y, id);
                    Tiles.Add(tile);
                }

                if (++x == (int)Dimensions.X / 70)
                {
                    x = 0;
                    ++y;
                }
            }
        }
 private void CollisionBullets(Tile c, ref GunSprite gS)
 {
     if (gS.gun.bullets != null) {
         foreach (Bullet b in gS.gun.bullets) {
             if (c.rect.IntersectsWith (b.rect)) {
                 gS.gun.bullets [gS.gun.bullets.IndexOf (b)].dead = true;
             }
         }
     }
 }
        private void Collision(ref GunSprite gS, Tile tile, float elapsed)
        {
            //			Tile mBLeft, mBRight;
            //			mBLeft = map [(int)((gS.y + overallCamera.y) / Tile.HEIGHT) + 1] [(int)((gS.x + overallCamera.x) /
            //				Tile.WIDTH)];
            //			mBRight = map [(int)((gS.y + overallCamera.y) / Tile.HEIGHT) + 1] [(int)((gS.width + gS.x +
            //				overallCamera.x) / Tile.WIDTH)];
            //
            //			if (mBLeft.tileType != TileType.Air || mBRight.tileType != TileType.Air) {
            //				gS.falling = false;
            //			} else if (gS.falling == false && !gS.jumping) {
            //				gS.falling = true;
            //			}

            Rectangle rectLeft, rectRight, rectTop, rectBot;
            if (gS != null) {
                float xSpeed = gS.xDir * elapsed * gS.MOVE_SPEED;
                float ySpeed = gS.yDir * elapsed * gS.FALL_SPEED;
                rectLeft = new Rectangle (new Point ((int)(gS.x + xSpeed), (int)(gS.y + ySpeed)),
                    new Size (1, gS.height));
                rectRight = new Rectangle (new Point ((int)(gS.x + xSpeed + gS.width), (int)(gS.y +
                    ySpeed)), new Size (1, gS.height));
                rectTop = new Rectangle (new Point ((int)(gS.x + xSpeed), ((int)(gS.y + ySpeed))),
                    new Size (Player.WIDTH, 1));
                rectBot = new Rectangle (new Point ((int)(gS.x + xSpeed), (int)(gS.y + gS.height +
                    ySpeed + 1)), new Size (gS.width, 1));
                gS.rectBot = rectBot;
                if (gS.gun.left) {
                    rectLeft.X -= gS.gun.width;
                } else {
                    rectRight.X += gS.gun.width;
                }
            }

            if (tile.outOfSight || gS == null) {
                return;
            }
            TileDirectionRelSprite t = new TileDirectionRelSprite ();
            t.tile = tile;
            t.below = tile.rect.IntersectsWith (rectBot);
            t.above = tile.rect.IntersectsWith (rectTop);
            t.left = tile.rect.IntersectsWith (rectLeft);
            t.right = tile.rect.IntersectsWith (rectRight);
            if (t.below || t.above || t.left || t.right) {
                if (t.tile.tileType == TileType.Fire) {
                    gS.dead = true;
                }
                gS.tileDirRelSprites.Add (t);
            }
        }