Archived

This topic is now archived and is closed to further replies.

someboddy

Can anyone help me solve this problem?

Recommended Posts

someboddy    100
Well, I started to make an astroids game in c, but my starship is blinking. Can someone tell me if it's blinking on his PC too?
#include
#include
#include
#include
#include
#define maxspd 10
void main(void)
 {
  int grphdrv=DETECT,gmode;
  initgraph(&grphdrv,&gmode,"");
  setcolor(RED);
  setbkcolor(BLACK);
  int x=250,y=250,spd=0,spdchg;
  float ang=3.14*2-0.5,angchg;
  char k=0;
  int maxx=getmaxx(),maxy=getmaxy();
  while(k!=27)
   {
    spdchg=0;
    angchg=0;
    while(kbhit())
     {
      k=getch();
      switch(k)
       {
	case 'w':spdchg=1;
		 break;
	case 's':spdchg=-1;
		 break;
	case 'a':angchg=-0.05;
		 break;
	case 'd':angchg=0.05;
		 break;
       }
     }
    ang+=angchg*10;
    spd+=spdchg;
    if(spd>maxspd)
      spd=maxspd;
    if(spd<-maxspd/2)
      spd=-maxspd/2;
    x+=spd*cos(ang);
    y+=spd*sin(ang);
    if(x<0)
      x=maxx;
    if(x>maxx)
      x=0;
    if(y<0)
      y=maxy;
    if(y>maxy)
      y=0;
    clearviewport();
    line(x,y,x+30*cos(ang+3.14+0.2),y+30*sin(ang+3.14+0.2));
    line(x,y,x+30*cos(ang-3.14-0.2),y+30*sin(ang-3.14-0.2));
    delay(10);
   }
 }
  
Everyboddy need someboddy! [edited by - someboddy on January 4, 2004 5:47:12 AM]

Share this post


Link to post
Share on other sites
Dark Star    100
I have not had the chance to test the code but I have a feeling by looking at it, it will blink too.Im not too sure which graphics system you are using but I guess that your blinking is caused by the fact u dont seem to be using double buffering. Correct me if I am wrong. You see the problem with not using double buffering is that you are drawing directly onto the screen and so the user can see the drawing in construction. also you are clearing the viewport which may clear the screen immediately which may cause your screen to blink because the user can see the screen being drawn and then cleared all at once. So are drawing ur ship then immediately blacking out the screen and then pausing. This will give a blinking effect.

The solution is to use double buffering. with this method you prepare a buffer which is the same size as ur screen in resolution and do all ur drawing onto it. This is done in memory and the user cannot see the drawing and clearing in process. When the drawing is done in this ''offscreen'' buffer, you would then draw that buffer at once to the screen. This will remove flicker animation.

Here''s the process:

Create offscreen buffer same size as screen
Clear offscreen buffer

BEGIN game loop
{
do_game_logic();
get_inputs();

draw_to_offscreen_buffer();
copy_offscreen_to_screen();
}

I can see that maybe ur doing some DOS programming and that means there are a couple of ways to create the offscreen buffer and are not easy to go into here. But the system ur using may have some more advanced graphics commands to do it for you. I dont know.

Whichever compiler ur using, try to search site for resources on how to do advanced graphics in DOS.

Hope that helped.

DarkStar
UK

Share this post


Link to post
Share on other sites
Dark Star    100
It depends on what compiler u are using although not always. I suggest u do search on gamedev resources or the net about advanced graphics in DOS and using ur compiler. I dont believe it will be easy because its DOS. I remember when I wrote my DOS gfx functions to change screen mode, double buffer, palette functions and waiting for vertical syncing of screen, it was complicated and alot of code I got from the net for my compiler: DJGPP.

Sorry but its a difficult thing to go into right here.

DarkStar
UK

Share this post


Link to post
Share on other sites
someboddy    100
O.K., I need your help... again.
I found two functions that I pretty sure do that buffer thing:
1 "setactivepage()": set the number of the page that the graphics function write to.
2 "setvisualpage()": set the number of the page to be viewed on screen.

So I tried to switch between pages 0&1 on each frame, each time writing to the invisible page, but it turned out that...

E A C H - P A G E - W R I T E S - I N - A N O T H E R - C O R D I N A T E S ! ! !

Can anyone help a noob to solve his problem?


Everyboddy need someboddy!

[edited by - someboddy on January 6, 2004 2:50:44 AM]

Share this post


Link to post
Share on other sites
krez    443
figure out what the coordinates are for both pages, and use those for each one (you''ll have to keep track of which page you are currently drawing to, but that isn''t too hard).

Share this post


Link to post
Share on other sites
someboddy    100
What I mean, is that each page have different resulution. I tried to change the resulution, but when I change to the other page, the resulution change back. Changing it on every frame won''t work, since it will make the game very slow.

-----------------------------------------
Everyboddy need someboddy!

Share this post


Link to post
Share on other sites
oliii    2196
yikes. That surely is a BGI problem. It should not change resolution. Don't set the mode to DETECT, but rather, use a specific mode with support for multiple pages

and here is a link to an extended BGI driver for SVGA compatible graphics cards...

http://www.mirror.ac.uk/collections/hensa-micros/local/msdos/drivers/svgabgi3.txt

http://www.mirror.ac.uk/collections/hensa-micros/local/msdos/drivers/svgabgi3.zip

but by default, try
int grphdrv=VGA,gmode=VGAMED;
initgraph(&grphdrv,&gmode,"");

or

int grphdrv=IBM8514,gmode=IBM8514HI;
initgraph(&grphdrv,&gmode,"");


[edited by - oliii on January 7, 2004 4:19:30 AM]

Share this post


Link to post
Share on other sites