The simplest way to raycast would just be to iterate over each pixel looking for collisions each time. Here is a more correct way to do it. As I see it that’s the best way to do collision - because it’s not discrete (therefore you can’t be moving so fast you pass over things).
But it may be beyond your skill level, sure. For now I’d just do pixel-by-pixel movement, i.e.
public void move()
{
float magnitude = Math.sqrt(velocity.x*velocity.x + velocity.y*velocity.y);
float normalizedVelocity = new Vector2(velocity.x / magnitude, velocity.y / magnitude);
Vector2 newPosition = new Vector2(position.x, position.y);
for (int i = 0; i < magnitude; i++)
{
if (!collidesWithStuff(position.x + normalizedVelocity.x * i, position.y + normalizedVelocity.y * i))
{
newPosition = new Vector2(position.x + normalizedVelocity.x * i, position.y + normalizedVelocity.y * i);
}
else
{
break;
}
}
position = newPosition;
}