1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <graphics.h>
int main() {
int x1=20,x2=40,y1=20,y2=40,x3=400,x4=420,y3=300,y4=320;
int ek=30;
char button;
initwindow(600,400);
int x,y;
setcolor(RED);
rectangle(x1,y1,x2,y2); //first rectengular shape
setcolor(WHITE);
rectangle(x3,y3,x4,y4); //second rectengular shape
for(;;){
button=getch();
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
setcolor(BLACK);
rectangle(x3,y3,x4,y4);
if(button==77) { x1=x1+ek; x2=x2+ek; } // arrowkey left
if(button==97) { x3=x3-ek; x4=x4-ek; } // button s
if(button==75) { x1-=ek; x2-=ek; } //arrowkey right
if(button==100) {x3=x3+ek; x4=x4+ek; }// button a
if(button==72){ y1-=ek; y2-=ek; } //arrowkey down
if(button==115) {y3=y3+ek; y4=y4+ek;} // button d
if(button==80) { y1+=ek; y2+=ek; } //arrowkey up
if(button==119) {y3=y3-ek; y4=y4-ek; } // button 119
setcolor(RED);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(x3,y3,x4,y4);
}
closegraph();
return 0;
}
|