Link to home
Start Free TrialLog in
Avatar of tppramod
tppramodFlag for India

asked on

PC-MAN DOS Graphics Programming

I want to move the sprite (14x14 pixels) by decrementing the value of `Y' keeing the value of `X' = 0 (i.e. to move towards Up) and when the whole of the sprite is moved up first only then should appear from the bottom rowwise and rest is the same.  But the problem starts the moment value of `Y' turns   (-1)  and so  on.  The top of the sprite is appeared immediately at the bottom and the sprite can be seen split into two parts, some on top and some left at bottom of the screen. Why this happen? and how to overcome this problem?.  i would be great if i can get a sample code for it.  I am programming this game in Turbo C Version 3 DOS version and is near to completion.


T. P. Pramod Kumar
New Delhi
INDIA

ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tppramod

ASKER

Hi sunnycoder,

the part where i need clarification is when the sprite is displayed at a location where the value of `Y' is a negative and since that location is not a displayable area then why the system display that part at the bottom.   Is this always happen with all other programming languages?

In the game `paratrooper' by Dr. Greg Kuperberg, the helicopters moves from left to right of the screen and vice versa. This game was  designed for CGA (300x200x4) where all the animations were done in the same screen i.e. sprite were erased as it moved because there was no much memory left for offscreen usage.  Does the technique showed by you is the only way to have the similar effect or is there any other better way?.

T. P. Pramod Kumar
New Delhi
INDIA
>Y' is a negative and since that location is not a displayable area then why the
>system display that part at the bottom.   Is this always happen with all other
>programming languages?

this is most likely due to the maths you might have used ... AFAIK this is not a programming language "feature" ... can you post the code

> Does the technique showed by you is the only way to have the similar effect
>or is there any other better way?.

you say that you would like the sprite ti reappear after it has completely vanshed from the screen ... then you have either of two approaches ...
1. let is slide away and keep checking when it is off the screen (what you seem to be trying for)
2. a small variation of it which I have posted
Avatar of bredbored
bredbored

Assuming that you are still using putimage, the sprite appears at the bottom of the screen because the blitter doesn't clip the image to the display size.  A negative number causes the blitter to write to the end of the video memory segment, which may be visible at the bottom of the screen in video modes with a single display page.  This is not dependent on the language, but is dependent on the graphics library.

There is no simple solution for this problem using Borland's getimage and putimage, because these functions expect the first two words of the bitmap to indicate its width and height.  You could write your own renderer with clipping and raster operations.  Otherwise I would suggest you simply move the sprite to the other side of the screen as soon as his coordinate becomes negative.

This should do that, I think, although I haven't tested it:

putimage( sprite->x, sprite->y, sprite->image, XOR_PUT );

sprite->y += sprite->dy;

if( sprite->y < 0 )
      sprite->y += display->height - sprite->height;

if( sprite->y + sprite->height > display->height )
      sprite->y -= display->height;

sprite->x += sprite->dx;

if( sprite->x < 0 )
      sprite->x += display->width - sprite->width;

if( sprite->x + sprite->width > display->width )
      sprite->x -= display->width;

putimage( sprite->x, sprite->y, sprite->image, XOR_PUT );