public bool tryStop() { if (Math.Abs(_position.X - Math.Round(_position.X)) <= 0.05 && Math.Abs(_position.Y - Math.Round(_position.Y)) <= 0.05) { _position.X = (float)Math.Round(_position.X); _position.Y = (float)Math.Round(_position.Y); _velocity = new Vector2(0); if (movement == MovementType.Flying) { Parallel.BlockType currentBlock = Parallel.levelData[(int)_position.X][(int)_position.Y]; if (currentBlock == Parallel.BlockType.None || currentBlock == Parallel.BlockType.FloatBlock) { movement = MovementType.Still; move(nextDirection); } else { movement = MovementType.Still; finishFlyingPath(); } } else { movement = MovementType.Still; finishFlyingPath(); } return(true); } return(false); }
// public virtual bool checkBlockCollision(GameTime t, Vector2 vel) { // Vector2 nextPos = position + (vel * (t.ElapsedGameTime.Milliseconds / 10f)); //Parallel.BlockType nextBlockX = Parallel.getBlock(nextPos.X, position.Y); //Parallel.BlockType nextBlockY = Parallel.getBlock(position.X, nextPos.Y); //Parallel.BlockType nextBlockBoth = Parallel.getBlock(nextPos.X, nextPos.Y); //if (nextBlockBoth == Parallel.BlockType.Block || nextBlockBoth == Parallel.BlockType.FloatBlock) { // return true; //} // return false; // } public virtual bool checkPathCollision() { Parallel.BlockType b = Parallel.getBlock(position.X, position.Y); if (b == Parallel.BlockType.FloatBlock) { Parallel.setBlock(position.X, position.Y, Parallel.BlockType.RedFloatBlock); return(false); } return(false); }
public Parallel.BlockType getNextBlock(Direction d) { Parallel.BlockType nextBlock = Parallel.BlockType.Void; switch (d) { case Direction.Up: _velocity = new Vector2(0, -0.1f); if (Math.Round(_position.Y) > 0) { nextBlock = Parallel.levelData[(int)_position.X][(int)_position.Y - 1]; } else { nextBlock = Parallel.BlockType.Void; } break; case Direction.Right: _velocity = new Vector2(0.1f, 0); if (Math.Round(_position.X) < Parallel.levelSize.X - 1) { nextBlock = Parallel.levelData[(int)_position.X + 1][(int)_position.Y]; } else { nextBlock = Parallel.BlockType.Void; } break; case Direction.Down: _velocity = new Vector2(0, 0.1f); if (Math.Round(_position.Y) < Parallel.levelSize.Y - 1) { nextBlock = Parallel.levelData[(int)_position.X][(int)_position.Y + 1]; } else { nextBlock = Parallel.BlockType.Void; } break; case Direction.Left: _velocity = new Vector2(-0.1f, 0); if (Math.Round(_position.X) > 0) { nextBlock = Parallel.levelData[(int)_position.X - 1][(int)_position.Y]; } else { nextBlock = Parallel.BlockType.Void; } break; } return(nextBlock); }
public void update(GameTime t) { if (movement != MovementType.Still) { _position += _velocity * t.ElapsedGameTime.Milliseconds / 10f; } Parallel.BlockType current = getCurrentBlock(); if (current == Parallel.BlockType.None) { Parallel.setBlock(_position.X, _position.Y, Parallel.BlockType.FloatBlock); } }
public virtual bool checkBlockCollision() { Vector2 nextPos = position + velocity; Parallel.BlockType xBlock = Parallel.getBlock(nextPos.X, position.Y); Parallel.BlockType yBlock = Parallel.getBlock(position.X, nextPos.Y); Parallel.BlockType bothBlock = Parallel.getBlock(nextPos.X, nextPos.Y); if (xBlock == Parallel.BlockType.Block || xBlock == Parallel.BlockType.Void) { velocity.X *= -1; } if (yBlock == Parallel.BlockType.Block || yBlock == Parallel.BlockType.Void) { velocity.Y *= -1; } return(false); }
public void move(Direction d) { if (movement == MovementType.Still) { // Sets velocity of builder in the chosen direction and sets the movement type Parallel.BlockType nextBlock = getNextBlock(d); if (nextBlock == Parallel.BlockType.None) { movement = MovementType.Flying; } else if (nextBlock == Parallel.BlockType.Block) { movement = MovementType.Walking; } else { movement = MovementType.Still; } _direction = d; nextDirection = d; } }