private void MoveSprite(ref GunSprite gS, TileDirectionRelSprite tile, Rectangle rectangle) { if (tile.below && !gS.jumping && rectangle.IntersectsWith(new Rectangle(new Point((int)tile.tile.x, (int)tile.tile.y), new Size(Tile.WIDTH, 7)))) { gS.y = tile.tile.y - gS.height - 1; gS.falling = false; gS.yDir = 0; } else if (tile.left) { gS.x = tile.tile.x + Tile.WIDTH; if (gS.gun.left) { gS.x += gS.gun.width + 1; } } else if (tile.right) { gS.x = tile.tile.x - gS.width - 1; if (!gS.gun.left) { gS.x -= gS.gun.width; } } }
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); } }
private void MoveSprite(ref GunSprite gS, TileDirectionRelSprite tile, Rectangle rectangle) { if (tile.below && !gS.jumping && rectangle.IntersectsWith (new Rectangle (new Point ((int)tile.tile.x, (int)tile.tile.y), new Size (Tile.WIDTH, 7)))) { gS.y = tile.tile.y - gS.height - 1; gS.falling = false; gS.yDir = 0; } else if (tile.left) { gS.x = tile.tile.x + Tile.WIDTH; if (gS.gun.left) { gS.x += gS.gun.width + 1; } } else if (tile.right) { gS.x = tile.tile.x - gS.width - 1; if (!gS.gun.left) { gS.x -= gS.gun.width; } } }
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); } }