Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everybody. i have some problems with graphics.h functions in c++. 1) how can i add constant background image to my code? i tried initwindow and readimagefile fuctions but when i put that in for loop each time it opens new window and when i put it out of for loop it disappears when loop starts. i have same problem with sound. when i play sound using playsound function program waits for sound to finish and then reads rest of the code. i would be thankful to help me.

What I have tried:

#include <stdio.h>
#include <graphics.h>
#include <windows.h>
#include <conio.h>
#include <mmsystem.h>

int main() {

    int p=0 ;

    int w=0,d=0,s=0,a=0 ;

int gd=DETECT,gm ;

initgraph(&gd,&gm,"") ;

      PlaySound(TEXT("gow.wav"), NULL, SND_SYNC) ;

char c='y';

while (c!=27) {

rectangle(20+a,20+w,80+d,80+s) ;

c=getch() ;

if (c=='t') {

    p++ ;
}

if (c=='f') {

        for (int i=20+w;i>=0;i--) {

    rectangle(20+a,20+w,80+d,80+s) ;

    if (p%2==0) {

    circle((100+a+d)/2,i,4) ;
    }
    else {

        line((100+a+d)/2,i,(100+a+d)/2,i-5) ;
    }

    Sleep(1) ;

    cleardevice() ;

        }
}

if (c=='a') {

    cleardevice() ;

    a-=10 ;

    d-=10 ;
}
else if (c=='w') {

    cleardevice() ;

    w-=10 ;

    s-=10 ;
}
else if (c=='d') {

    cleardevice();

    d+=10 ;

    a+=10 ;
}
else if (c=='s') {

    cleardevice() ;

    s+=10 ;

    w+=10 ;
}

}

closegraph() ;

return 0;
}
Posted
Updated 15-Nov-19 9:43am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900