public Tile(Vector2 i_posOnTileSheet, Vector2 i_posOnPlatform, Platform i_plateform) { positionOnPlatform = i_posOnPlatform; positionOnTileset = i_posOnTileSheet; platform = i_plateform; int line = (int)positionOnPlatform.Y / Height; int column = (int)positionOnPlatform.X / Width; int numero_on_tilesheet = (int)(positionOnTileset.X / Platform.Width) + (int)(positionOnTileset.Y / Platform.Height) * 4; int collision_type = Platform.platforms[numero_on_tilesheet][line][column]; if (collision_type == 1) { collision = TileCollision.Impassable; } else if (collision_type == 2) { collision = TileCollision.Escalier; } pos_origin_x = 0; pos_origin_y = 0; pos_destination_x = (int)(LevelManager.Instance.offset_x + platform.position.X * Platform.Width + positionOnPlatform.X); pos_destination_y = (int)(LevelManager.Instance.offset_y + platform.position.Y * Platform.Height + positionOnPlatform.Y); }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(Texture2D texture, TileCollision collision, SpriteEffects effects, bool visible) { Texture = texture; Collision = collision; Effects = effects; Visible = visible; }
public void AddCollisionTile(TileCollision tileCollision) { if (!_tileCollisions.Any(t => t.XPos == tileCollision.XPos && t.YPos == tileCollision.YPos)) { _tileCollisions.Add(tileCollision); } }
/// <summary> /// Creates a new Moveable tile. /// </summary> /// <param name="sprite">Sprite representing texture, size, and position of the tile. </param> /// <param name="collision">Type of collision for the tile.</param> /// <param name="velocity">Tile velocity: .X is the movement angle in radians and .Y is the speed in pixels per second.</param> public MoveableTile(Sprite sprite, TileCollision collision, Vector2 velocity) : base(sprite, collision) { this.velocity = velocity; Leader = this; // By default, tiles lead themselves }
private Tile LoadVarietyTile(string name, int variation, TileCollision collision) { int index = random.Next(variation); // get index on tile to rect dictionary return(LoadTile(name + index, collision)); }
//public static readonly Vector2 Size = new Vector2(Width, Height); /// <summary> /// Constructs a new tile. /// </summary> public TileTODO(Texture2D texture, TileCollision collision) { Width = texture.Width; Height = texture.Height; Texture = texture; Collision = collision; }
public MovableTile(Level level, Vector2 position, TileCollision collision) { this.level = level; this.position = position; this.collision = collision; LoadContent(); }
public CollisionSurface() { AssetName = "collision_surface"; CollisionType = TileCollision.Impassable; Colour = Color.White; Visible = true; }
public void HandleCollisions() { int xOrigin = (int)(Position.X) / Tile.Width; int yOrigin = (int)(Position.Y) / Tile.Height; int xStart = xOrigin - 15; int yStart = yOrigin - 15; int xEnd = xOrigin + 15; int yEnd = yOrigin + 15; enemyToChar = new LiangBarsky(Position, new Vector2(level.Player.Position.X, level.Player.Position.Y - 32.0f)); wallInWay = false; for (int y = yStart; y < yEnd; ++y) { for (int x = xStart; x < xEnd; ++x) { TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable) { Rectangle tileBounds = level.GetBounds(x, y); if (enemyToChar.Intersect(tileBounds) == true) { wallInWay = true; } } } } }
public Tile(string tileName, Texture texture, TileCollision tileCollision, Vector position) { TileName = tileName; TileCollision = tileCollision; Sprite.Texture = texture; Sprite.SetPosition(position); }
public Vector3 CastMousePos(Vector3 mouse, Vector3 dir) { Vector3 result = mouse; while (mouse.Z < Depth * Tile.DEPTH) { TileCollision coll = GetCollision(mouse); if (coll == TileCollision.Solid || coll == TileCollision.Landing) { result = mouse + dir; } else if (coll == TileCollision.Slope) { int x = Tile.GetArrayXY(mouse.X); int y = Tile.GetArrayXY(mouse.Y); int z = Tile.GetArrayZ(mouse.Z); float height = ((TileSlope)Tiles[x, y, z]).GetHeight(mouse) % Tile.DEPTH; Vector3 multipled = new Vector3(dir.X, dir.Y, 0.0f); multipled *= (height / Tile.DEPTH); multipled.Z = height; result = mouse + multipled; } mouse += dir; } return(result); }
private LevelTile LoadMovableTile2(int x, int y, TileCollision collision) { Point position = GetBounds(x, y).Center; movableTiles.Add(new MovableTile(level, new Vector2(position.X, position.Y), collision, false, "Tiles/BlockB1")); return(new LevelTile(null, TileCollision.Passable)); }
public Tile(Texture2D texture, TileCollision collision, Rectangle bounds, Vector2 position) { this.texture = texture; this.tileType = collision; this.bounds = bounds; this.position = position; this.pathfindingParm = new AstarParam(); }
public MovableTile(Level level, Vector2 position, TileCollision collision , Boolean SmashBlock) { this.level = level; this.position = position; this.collision = collision; this.isSmashBlock = SmashBlock; LoadContent(); }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(TileCollision collision, int x, int y, int width, int height) { Collision = collision; this.X = x; this.Y = y; Width = width; Height = height; }
private Tile LoadMovableTile(int x, int y, TileCollision collision) { Point position = GetBounds(x, y).Center; movableTiles.Add(new MovableTile(this, new Vector2(position.X, position.Y), collision)); return(new Tile(null, TileCollision.Passable)); }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(Sprite sprite, TileCollision collision) { if (sprite != null) Sprite = sprite; else Sprite = new Sprite(); Collision = collision; }
public MovableTile(Level level, Vector2 position, TileCollision collision, Boolean SmashBlock) { this.level = level; this.position = position; this.collision = collision; this.isSmashBlock = SmashBlock; LoadContent(); }
private Tile LoadBridgeTile(int x, int y, TileCollision collision) { Vector2 position = RectangleExtensions.GetBottomCenter(GetBounds(x, y)); Tile bridgeTile = new Tile(Content.Load <Texture2D>("Tiles/bridge"), collision); bridgeTiles[x, y] = bridgeTile; return(bridgeTiles[x, y]); }
public void Update() { //Only update them if they're alive if (IsAlive) { //Move our bullet based on its velocity Position += Velocity; //Rectangle the size of the screen so bullets that //fly off screen are deleted. Rectangle screenRect = new Rectangle(0, 0, (int)gun.WeaponWielder.Level.Camera.Position.X + gun.WeaponWielder.Level.Camera.ViewPort.Width, (int)gun.WeaponWielder.Level.Camera.Position.Y + gun.WeaponWielder.Level.Camera.ViewPort.Height * 2); if (!screenRect.Contains(new Point( (int)Position.X, (int)Position.Y))) { IsAlive = false; return; } checkBulletCollision(); //Everything below here can be deleted if you want //your bullets to shoot through all tiles. //Look for adjacent tiles to the bullet Rectangle bounds = new Rectangle( rectangle.Center.X - 6, rectangle.Center.Y - 6, rectangle.Width / 4, rectangle.Height / 4); int leftTile = (int)Math.Floor((float)rectangle.Left / gun.WeaponWielder.Level.TileWidth); int rightTile = (int)Math.Ceiling(((float)bounds.Right / gun.WeaponWielder.Level.TileWidth)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / gun.WeaponWielder.Level.TileHeight); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / gun.WeaponWielder.Level.TileHeight)) - 1; // For each potentially colliding tile for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { TileCollision collision = gun.WeaponWielder.Level.GetCollision(x, y); //If we collide with an Impassable or Platform tile //then delete our bullet. if (collision == TileCollision.Impassable || collision == TileCollision.Platform) { if (rectangle.Intersects(bounds)) { IsAlive = false; } } } } } }
/// <summary> /// detect and deal with all collisions between the player and the tiles /// TODO: optimize /// BUG - player "sticks" to bottom of tiles while jumping /// fix by setting jumpTime to 0 if player hits bottom of an impassable tile /// </summary> private void handleCollisions() { Rectangle bounds = BoundingRectangle; OnGround = false; //inefficient way to check for collisions as it cycles through every existing tile for (int h = 0; h < level.Height; h++) { for (int w = 0; w < level.Width; w++) { // If this tile is collidable, TileCollision collision = level.GetCollision(h, w); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = level.GetBounds(h, w); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) { OnGround = true; } // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || OnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = BoundingRectangle; } } } } } previousBottom = bounds.Bottom; }
/// <summary> /// Constructor defaulting to inactive ladder /// </summary> /// <param name="sprite"></param> /// <param name="collision"></param> public LadderTile(Sprite sprite, TileCollision collision) : base(sprite, collision) { activated = sprite.Texture; deactivated = null; isActive = false; this.Sprite = sprite; }
public Tile(string tileName, Texture texture, TileCollision tileCollision, double x, double y) { X = x; Y = y; TileName = tileName; TileCollision = tileCollision; Sprite.SetPosition(x, y); Sprite.Texture = texture; }
public Tile(PyramidPanic game,string tileName ,Vector2 position,TileCollision tileCollision,char charItem) { this.game = game; this.tileCollision = tileCollision; this.texture = game.Content.Load<Texture2D>(@"PlaySceneAssets\tiles\"+tileName); this.position = position; this.rectangle = new Rectangle((int)this.position.X, (int)this.position.Y, texture.Width, texture.Height); this.charItem = charItem; }
//Constructor public MovingBlock(PyramidPanic game, string blockName, Vector2 location, TileCollision blockCollision, char charItem ) { this.game = game; this.texture = this.game.Content.Load<Texture2D>(@"PlaySceneAssets\pushable\" + blockName); //this.colText = this.game.Content.Load<Texture2D>(@"PlaySceneAssets\Explorer\CollisionText"); this.startLocation = location; this.Location = location; this.state = new MovingBlockIdle(this); }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(Texture2D texture, TileCollision collision) { Texture = texture; Collision = collision; Vector3 minBounding = new Vector3(0.0f, 0.0f, 0.0f); Vector3 maxBounding = new Vector3(Width, Height, 0.0f); collisionBox = new BoundingBox(minBounding, maxBounding); collisionRect = new Rectangle(0, 0, Width, Height); }
private void HandleCollision() { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = new Rectangle((int)Position.X - (int)origin.X, (int)Position.Y - (int)origin.Y, texture.Width, texture.Height); int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable) { Rectangle tileBounds = level.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = boundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. Position = new Vector2(Position.X + depth.X, Position.Y); // Perform further collisions with the new bounds. bounds = boundingRectangle; } } } } } }
public Tile(Vector3 pos, TileCollision coll, TileStyle style, Color fill) { Position = pos; MapX = GetArrayXY(pos.X); MapY = GetArrayXY(pos.Y); MapZ = GetArrayXY(pos.Z); Collision = coll; Style = style; Sprites = new Subtile[DIVS, DIVS, DIVS]; Fill = fill; }
private void HandleBullets() { for (int i = 0; i < bullets.Count; i++) { bullets[i].Position += new Vector2(bullets[i].Angle, 0) * bulletSpeed; if (bullets[i].Collision.Intersects(level.Player.BoundingRectangle) && level.Player.StopPlayerCollision == false) { level.Rumble.RumbleSetup(500.0f, 0.5f); level.Player.Strikes -= 1; level.Player.IsHit = true; level.Player.StopPlayerCollision = true; bullets.RemoveAt(i); } } foreach (var bulletIn in bullets.ToList()) { Rectangle bounds = new Rectangle((int)bulletIn.Position.X, (int)bulletIn.Position.Y, bullet.Width, bullet.Height); int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; if (level.Player.AttackBounds.Intersects(bounds) || level.Player.ShieldBounds.Intersects(bounds)) { bullets.Remove(bulletIn); break; } for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable && collision != TileCollision.Patrol) { bullets.Remove(bulletIn); } } } } }
public void Update(double gameTime) { _mouseState = Mouse.GetState(); if (_mouseState.LeftButton == ButtonState.Pressed && _managerCamera.MouseInsideWindow()) { var x = (int)(_managerCamera.Position.X + _mouseState.X) / 16; var y = (int)(_managerCamera.Position.Y + _mouseState.Y) / 16; //Just for test if (_mainForm.CurrentLayer == CurrentLayer.LayerOne) { foreach (var tilePoint in _mainForm.TilePoints) { var realX = x + (_mainForm.TilePoints[0].X - tilePoint.X) * -1; var realY = y + (_mainForm.TilePoints[0].Y - tilePoint.Y) * -1; var tile = new TileGraphic { ManagerCamera = _managerCamera, XPos = (int)realX, YPos = (int)realY, AnimationSpeed = 0, TextureName = "overworld_tiles", TileFrames = new List <TileFrame> { new TileFrame { TextureXPos = (int)tilePoint.X, TextureYPos = (int)tilePoint.Y } }, ZPos = 0 }; tile.LoadContent(); _tiles.AddTile(tile); } } else { var tileCollision = new TileCollision(true) { ManagerCamera = _managerCamera, XPos = x, YPos = y }; _tiles.AddCollisionTile(tileCollision); } } }
public override void HandleCollisions(GameTime gameTime) { int xOrigin = (int)(Position.X) / Tile.Width; int yOrigin = (int)(Position.Y) / Tile.Height; int xStart = xOrigin - 15; int yStart = yOrigin - 15; int xEnd = xOrigin + 15; int yEnd = yOrigin + 15; enemyToChar = new LiangBarsky(Position, new Vector2(level.Player.Position.X, level.Player.Position.Y - 32.0f)); wallInWay = false; for (int y = yStart; y < yEnd; ++y) { for (int x = xStart; x < xEnd; ++x) { TileCollision collision = level.GetCollision(x, y); if (collision != TileCollision.Passable && collision != TileCollision.Patrol) { Rectangle tileBounds = level.GetBounds(x, y); if (enemyToChar.Intersect(tileBounds) == true) { wallInWay = true; } } } } Rectangle bounds = BoundingRectangle; Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, level.Player.BoundingRectangle); if (depth.X < -2.0f || depth.X > 2.0f) { velocity = Vector2.Zero; if (level.Player.StopPlayerCollision == false) { level.Rumble.RumbleSetup(500.0f, 0.5f); level.Player.Strikes -= 1; level.Player.IsHit = true; } } }
public Platform(Rectangle platformBounds,TileCollision collision, Boolean isShadowCaster, KryptonEngine krypton) { this.krypton = krypton; Collision = collision; IsShadowCaster = isShadowCaster; Bounds = platformBounds; if (isShadowCaster) { ShadowHull shadowHull = ShadowHull.CreateRectangle(new Vector2(platformBounds.Width, platformBounds.Height)); shadowHull.Position.X = platformBounds.X + platformBounds.Width/2; shadowHull.Position.Y = platformBounds.Y + platformBounds.Height/2; krypton.Hulls.Add(shadowHull); } }
public Platform(Rectangle platformBounds, TileCollision collision, Boolean isShadowCaster, KryptonEngine krypton) { this.krypton = krypton; Collision = collision; IsShadowCaster = isShadowCaster; Bounds = platformBounds; if (isShadowCaster) { ShadowHull shadowHull = ShadowHull.CreateRectangle(new Vector2(platformBounds.Width, platformBounds.Height)); shadowHull.Position.X = platformBounds.X + platformBounds.Width / 2; shadowHull.Position.Y = platformBounds.Y + platformBounds.Height / 2; krypton.Hulls.Add(shadowHull); } }
public virtual void HandleRoomCollisions() { UpdateHitbox(); int worldLeft = (int)Math.Floor((float)Hitbox.Left / Tile.TILE_WIDTH); int worldRight = (int)Math.Ceiling((float)Hitbox.Right / Tile.TILE_WIDTH) - 1; int worldTop = (int)Math.Floor((float)Hitbox.Top / Tile.TILE_HEIGHT); int worldBottom = (int)Math.Ceiling((float)Hitbox.Bottom / Tile.TILE_HEIGHT); InWater = false; OnGround = previousBottom == Hitbox.Bottom && Velocity.Y == 0; somethingBelow = false; hitSomething = false; for (int x = worldLeft; x <= worldRight; x++) { for (int y = worldTop; y <= worldBottom; y++) { TileCollision colType = World.CurrentRoom.GetTileCollision(x, y); if (colType == TileCollision.Solid) { Rectangle tileBounds = World.CurrentRoom.GetTileBounds(x, y); hitSomething = PushOutOfTile(tileBounds) || hitSomething; if (y == worldBottom || y == worldBottom - 1) { somethingBelow = true; } } else if (colType == TileCollision.Water) { InWater = InWater || Hitbox.Intersects(World.CurrentRoom.GetTileBounds(x, y)); } } } if (!somethingBelow) { OnGround = false; } previousBottom = Hitbox.Bottom; if (hitSomething) { OnWallHit(); } }
public bool EmitOnTileCollision(Simulation.Simulation simulation, TileCollision tc) { bool defaultAction = true; foreach (EntityComponent simulationComponent in EntityComponents) { if (!simulationComponent.OnTileCollision(simulation, this, tc)) { defaultAction = false; } } return(defaultAction); }
private void HandleCollisions() { Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling((float)bounds.Right / Tile.Width) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling((float)bounds.Bottom / Tile.Height) - 1; isOnGround = false; for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { TileCollision collision = Level.GetCollision(x, y); if (collision != TileCollision.Passable) { Rectangle tileBounds = Level.GetBounds(x, y); Vector2 depth = bounds.GetIntersectionDepth(tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); if (absDepthY < absDepthX || collision == TileCollision.Platform) { if (previousBottom <= tileBounds.Top) { isOnGround = true; } if (collision == TileCollision.Impassable || IsOnGround) { Position = new Vector2(Position.X, Position.Y + depth.Y); bounds = BoundingRectangle; } } else if (collision == TileCollision.Impassable) { Position = new Vector2(Position.X + depth.X, Position.Y); bounds = BoundingRectangle; } } } } } previousBottom = bounds.Bottom; }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(int texture) { Texture = texture; if (texture < 6) { Collision = TileCollision.Passable; } else if (texture < 99) { Collision = TileCollision.Platform; } else { Collision = TileCollision.LevelExit; } }
/// <summary> /// Constructs a new tile. /// </summary> public Tile(int x, int y, Texture2D texture, TileCollision collision) { this.x = x; this.y = y; //var position = (new Rectangle(x * Tile.Width, y * Tile.Height, Tile.Width, Tile.Height)).GetBottomCenter(); //this._boundingBox = new Rectangle((int)position.X, (int)position.Y, Tile.Width, Tile.Height); this._boundingBox = new Rectangle(x * Tile.Width, y * Tile.Height, Tile.Width, Tile.Height); this.Texture = texture; this.Collision = collision; if (collision != TileCollision.Passable) { CollisionManager.Collection.Add(this); } }
/// <summary> /// Paces back and forth along a platform, waiting at either end. /// </summary> public void Update(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; // Calculate tile position based on the side we are walking towards. float posX = Position.X + localBounds.Width / 2 * (int)direction; int tileX = (int)Math.Floor(posX / Tile.Width) - (int)direction; int tileY = (int)Math.Floor(Position.Y / Tile.Height); if (waitTime > 0) { // Wait for some amount of time. waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds); if (waitTime <= 0.0f) { // Then turn around. direction = (FaceDirection)(-(int)direction); } } else { // If we are about to run into a wall or off a cliff, start waiting. TileCollision coll1 = Level.GetCollision(tileX + (int)direction, tileY - 1); TileCollision coll2 = Level.GetCollision(tileX + (int)direction, tileY); bool test1 = coll1 == TileCollision.Impassable; bool test2 = coll2 == TileCollision.Passable; bool collision = test1 || test2; //bool collision = coll1 == TileCollision.Impassable || coll2 == TileCollision.Passable; //if (Level.GetCollision(tileX + (int) direction, tileY - 1) == TileCollision.Impassable || // Level.GetCollision(tileX + (int) direction, tileY) == TileCollision.Passable) if (collision) { waitTime = MaxWaitTime; } else { // Move in the current direction. //Vector2 velocity = new Vector2((int) direction*MoveSpeed*elapsed, 0.0f); Vector2 velocity = Vector2.Zero; ; position = position + velocity; } } }
/// <summary> /// Gets the collision mode of the tile at a particular location. /// This method handles tiles outside of the levels boundries by making it /// impossible to escape past the left or right edges, but allowing things /// to jump beyond the top of the level and fall off the bottom. /// </summary> public TileCollision GetCollision(int x, int y) { // Prevent escaping past the level ends. if (x < 0 || x >= Width) { return(TileCollision.Impassable); } // Allow jumping past the level top and falling through the bottom. if (y < 0 || y >= Height) { return(TileCollision.Passable); } TileCollision collision = tiles[x, y].Collision; return(collision); //return tiles[x, y].Collision; }
private void HandleCollisions() { // Get the player's bounding rectangle and find neighboring tiles. Rectangle bounds = BoundingRectangle; int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width); int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1; int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height); int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1; // Reset flag to search for ground collision. IsOnGround = false; // For each potentially colliding tile, for (int y = topTile; y <= bottomTile; ++y) { for (int x = leftTile; x <= rightTile; ++x) { // If this tile is collidable, TileCollision collision = game.CurrentLevel.GetCollision(x, y); if (collision != TileCollision.Passable) { // Determine collision depth (with direction) and magnitude. Rectangle tileBounds = game.CurrentLevel.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform || collision == TileCollision.Impassable || IsOnGround) { this.Explode(); break; } } } } } // Save the new bounds bottom. previousBottom = bounds.Bottom; }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime, MouseState mouseState) { // TODO: Add your update code here if (mouseState.LeftButton == ButtonState.Pressed) { int mouseXCor = mouseState.X; int mouseYCor = mouseState.Y; TileCollision collision = tiles[mouseXCor / Tile.width, mouseYCor / Tile.height].collision; if (collision == TileCollision.SoftWall) { tiles[mouseXCor / Tile.width, mouseYCor / Tile.height].collision = TileCollision.Path; } } base.Update(gameTime); }
public Tile(TileType typeIn, int xIn, int yIn, int totalWidthIn, int totalHeightIn, Random rand, TileCollision collision, int decoration = -1) { tileType = typeIn; size.X = size.Y = 16; position = new Vector2(xIn * size.X, yIn * size.Y); render = true; decorationValue = decoration; tileOrientation = TileOrientation.Regular; totalHeight = totalHeightIn; totalWidth = totalWidthIn; tileCollision = collision; if (tileType == TileType.Dirt) { hitsRequired = 1; if (rand.Next(1, 25) == 5) { //damage = rand.Next(1, 3); // health = damage * 30; } } else if (tileType == TileType.Metal) hitsRequired = 5; }
private Tile LoadEnviornmentTile(string tileNameInput, int variationCount, TileCollision collisionInput) { int index = random.Next(variationCount); return LoadTile(tileNameInput + index, collisionInput); }
public void AddCollisionTile(TileCollision tileCollision) { if(!_tileCollisions.Any(t => t.XPos == tileCollision.XPos && t.YPos == tileCollision.YPos)) _tileCollisions.Add(tileCollision); }
/// <summary> /// Creates the movable tile /// </summary> /// <param name="x">x position</param> /// <param name="y">y position</param> /// <param name="collision">What kind of collision it can take</param> /// <returns>Loaded tile</returns> private Tile LoadMovableTile(int x, int y, TileCollision collision) { Point position = GetBounds(x, y).Center; movableTiles.Add(new MovableTile(this, new Vector2(position.X, position.Y), collision)); return new Tile(null, TileCollision.Passable); }
public void load_tile(int indicator,Tile tileAbove) { #region "PerChar" /* switch (indicator) { case 'S': //type = TileType.Wall; passable = TileColission.Passable; tile_type = TileType.Start; break; case 'X': //type = "Exit"; passable = TileColission.Passable; tile_type = TileType.Exit; break; case 'W': //type = "Wall"; passable = TileColission.Impassable; tile_type = TileType.Wall; break; default : //type = "Empty"; passable = TileColission.Passable; tile_type = TileType.Empty; break; } */ #endregion //tile_type = TileType.Empty; tile_type = TileType.Empty; passable = TileCollision.Passable; //indicator = indicator.Trim(); foreach (TileType type in Enum.GetValues(typeof(TileType))) { if (((int)type) == indicator) { tile_type = type; } } switch (tile_type) { case (TileType.Wall): passable = TileCollision.Impassable; break; case (TileType.Platform): passable = TileCollision.Platform; break; case TileType.Spike: passable = TileCollision.Event; break; } switch (tile_type) { case TileType.Platform: case TileType.Wall: standable = true; break; default: standable = false; break; } if (tileAbove != null) { switch (tileAbove.TileType) { case TileType.Wall: standable = false; break; default: break; } } }
public void Clear() { passable = TileCollision.Passable; tile_type = TileType.Empty; pos = Vector2.Zero; rect = Rectangle.Empty; }
/// <summary> /// This function creates an individual tile. /// </summary> /// <param name="texture">texture of tile</param> /// <param name="collision">collision type of tile</param> /// <returns>tile object</returns> private Tile LoadTile(Texture2D texture, TileCollision collision) { return new Tile(texture, collision); }
/// <summary> /// Constructs a new tile. /// </summary> public LevelTile(Texture2D texture, TileCollision collision) { Texture = texture; Collision = collision; }
/// <summary> /// For a teleport collision type /// </summary> /// <param name="collision">The collision type</param> /// <param name="name">The name of this tile sprite</param> /// <param name="texture">The texture used</param> /// <param name="destination">The destination tile where the player will be teleported on collision</param> public Tile(TileCollision collision, String name, Texture2D texture, Tile destination) : base(name, texture) { _destination = destination.Position; Collision = collision; }
/// <summary> /// Loads a tile with a random appearance. /// </summary> /// <param name="baseName"> /// The content name prefix for this group of tile variations. Tile groups are /// name LikeThis0.png and LikeThis1.png and LikeThis2.png. /// </param> /// <param name="variationCount"> /// The number of variations in this group. /// </param> private Tile LoadVarietyTile(string baseName, int variationCount, TileCollision collision) { int index = random.Next(variationCount); return LoadTile(baseName + index, collision); }
/// <summary> /// Constructs a new tile. /// </summary> protected Tile(string texture, Vector2 position, TileCollision collision, Engine engine) : base(engine) { Name = texture; Position = position; Collision = collision; }
public GroundTile(string name, Vector2 position, TileCollision collision, Engine engine) : base(name, position, collision, engine) { }
public DestructableTile(int life, string name, Vector2 position, TileCollision collision, Engine engine) : base(name, position, collision, engine) { _life = life; }
/// <summary> /// Creates a new tile. The other tile loading methods typically chain to this /// method after performing their special logic. /// </summary> /// <param name="name"> /// Path to a tile texture relative to the Content/Tiles directory. /// </param> /// <param name="collision"> /// The tile collision type for the new tile. /// </param> /// <returns>The new tile.</returns> private Tile LoadTile(string name, TileCollision collision) { return new Tile(Content.Load<Texture2D>("Tiles/" + name), collision); }
private Tile LoadBlock(string name, TileCollision collision) { return LoadTile(name, collision); }
/// <summary> /// Used for the movable platforms to push player /// </summary> /// <param name="bounds"></param> /// <param name="collision"></param> /// <param name="tileBounds"></param> /// <returns></returns> private Rectangle HandleCollision(Rectangle bounds, TileCollision collision, Rectangle tileBounds, Character character) { Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); // Resolve the collision along the shallow axis. if (absDepthY < absDepthX || collision == TileCollision.Platform) { // If we crossed the top of a tile, we are on the ground. if (character.previousBottom <= tileBounds.Top) character.IsOnGround = true; // Ignore platforms, unless we are on the ground. if (collision == TileCollision.Impassable || character.IsOnGround) { // Resolve the collision along the Y axis. character.Position = new Vector2(character.Position.X, character.Position.Y + depth.Y); // Perform further collisions with the new bounds. bounds = character.BoundingRectangle; } } else if (collision == TileCollision.Impassable) // Ignore platforms. { // Resolve the collision along the X axis. character.Position = new Vector2(character.Position.X + depth.X, character.Position.Y); // Perform further collisions with the new bounds. bounds = character.BoundingRectangle; } } return bounds; }
/// <summary> /// For any tile without special behaviours required as parameters /// </summary> /// <param name="collision">The collision type</param> /// <param name="name">The name of this tile sprite</param> /// <param name="texture">The texture used</param> public Tile(TileCollision collision, String name, Texture2D texture) : base(name, texture) { Collision = collision; }