[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Texture for raycasting engine



On Thu, 6 Mar 2008 18:42:25 +0100, Julia <midnightjulia@xxxxxxxxx> wrote:
> My problem is I'm not really sure where to start if I'm going to do this
> with images in pygame. So far I've only needed to used pygame.draw.line()
> so
> right now I'm rather lost.

This probably isn't the fastest way, but you could blit the desired portion
of the source image just by passing an extra parameter to the blit
function. Where "h" is the texture's height, texture_x the desired vertical
strip of it to draw, and (x,y) the desired screen position:

screen.blit(texture,(x,y),(texture_x,0,1,h))

That would blit a one-pixel-wide stripe of "texture." To calculate which
stripe to use, apparently you should find how far along the wall the ray
hits, the easiest way being to divide the world into a grid like Wolf3D,
and if it's 25% away from the left edge, set "texture_x" to the texture's
width * .25.