pozicija loptice
Revision 0:7aa751de1e82, committed 2021-02-22
- Comitter:
- atopcic
- Date:
- Mon Feb 22 08:25:01 2021 +0000
- Commit message:
- pozicija loptice;
Changed in this revision
pozicijaLoptice.cpp | Show annotated file Show diff for this revision Revisions of this file |
pozicijaLoptice.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pozicijaLoptice.cpp Mon Feb 22 08:25:01 2021 +0000 @@ -0,0 +1,60 @@ +// funkcija pozicioniranja loptice: + +#include "pozicijaLoptice.h" +extern int polje[8][8]; +int loptaUljevo=1,loptaGore=1,loptaX=5,loptaY=4,Igrac1rez=0,Igrac2rez=0; +Timer timer3; + + void PozicijaLoptice (void){ + + if(loptaUljevo==1) + loptaX--; + else + loptaX++; + if(loptaX == 0) + loptaUljevo = 0; + else if (loptaX == 7) + loptaUljevo = 1; + + if(loptaGore==1) + loptaY++; + else + loptaY--; + + +if(loptaY == 6 && polje[7][loptaX] == 1) + { + loptaGore = 0; + } + +else if(loptaY == 1 && polje[0][loptaX] == 1) + + { + loptaGore = 1; + } + +else if( loptaY==7 || loptaY==0) +{ + if(loptaY==0){ Igrac2rez++; Igrac2rez%=8;} + else if(loptaY==7){Igrac1rez++; Igrac1rez%=8;} + //resetpolja: + for(int i=0;i<8;i++) + { + for(int j=0;j<8;j++) + { + polje[i][j]=0; + } + } + //prikaz rezultata: + for( int i=0;i<8;i++) + { + if (i<Igrac2rez) polje[7][i]=1; + if(i<Igrac1rez) polje[0][i]=1; + } + while(timer3.read_ms() < 1000) ispis(); + loptaUljevo=!loptaUljevo; + loptaGore=!loptaGore; + loptaX=4,loptaY=4; + } +polje[loptaY][loptaX] = 1; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pozicijaLoptice.h Mon Feb 22 08:25:01 2021 +0000 @@ -0,0 +1,12 @@ +#ifndef POZICIJALOPTICE_H +#define POZICIJALOPTICE_H +#include "mbed.h" +#include "Ispis.h" + + + +extern int loptaUljevo,loptaGore,loptaX,loptaY,Igrac1rez,Igrac2rez; +extern Timer timer3; + + void PozicijaLoptice (void); + #endif \ No newline at end of file